Example usage for java.util Objects requireNonNull

List of usage examples for java.util Objects requireNonNull

Introduction

In this page you can find the example usage for java.util Objects requireNonNull.

Prototype

public static <T> T requireNonNull(T obj) 

Source Link

Document

Checks that the specified object reference is not null .

Usage

From source file:io.github.retz.scheduler.RetzScheduler.java

public RetzScheduler(Launcher.Configuration conf, Protos.FrameworkInfo frameworkInfo) {
    MAPPER.registerModule(new Jdk8Module());
    PLANNER = PlannerFactory.create(conf.getServerConfig().getPlannerName());
    this.conf = Objects.requireNonNull(conf);
    this.frameworkInfo = frameworkInfo;
    this.slaves = new ConcurrentHashMap<>();
    this.filters = Protos.Filters.newBuilder().setRefuseSeconds(conf.getServerConfig().getRefuseSeconds())
            .build();/*w w w  .j a v a2  s .co m*/
    MAX_JOB_SIZE = conf.getServerConfig().getMaxJobSize();
}

From source file:net.sf.jabref.logic.openoffice.StyleLoader.java

/**
 * Adds the given style to the list of styles
 * @param filename The filename of the style
 * @return True if the added style is valid, false otherwise
 *///from   w ww .j a v a 2s .  c o m
public boolean addStyleIfValid(String filename) {
    Objects.requireNonNull(filename);
    try {
        OOBibStyle newStyle = new OOBibStyle(new File(filename), jabrefPreferences, journalAbbreviationLoader,
                encoding);
        if (externalStyles.contains(newStyle)) {
            LOGGER.info("External style file " + filename + " already existing.");
        } else if (newStyle.isValid()) {
            externalStyles.add(newStyle);
            storeExternalStyles();
            return true;
        } else {
            LOGGER.error(String.format("Style with filename %s is invalid", filename));
        }
    } catch (FileNotFoundException e) {
        // The file couldn't be found... should we tell anyone?
        LOGGER.info("Cannot find external style file " + filename, e);
    } catch (IOException e) {
        LOGGER.info("Problem reading external style file " + filename, e);
    }
    return false;

}

From source file:io.github.moosbusch.lumpi.gui.impl.Expression.java

public void setSeparatorChar(char separatorChar) {
    this.separatorChar = Objects.requireNonNull(separatorChar);
}

From source file:co.rsk.mine.BlockToMineBuilder.java

@Autowired
public BlockToMineBuilder(MiningConfig miningConfig, Repository repository, BlockStore blockStore,
        TransactionPool transactionPool, DifficultyCalculator difficultyCalculator,
        GasLimitCalculator gasLimitCalculator,
        @Qualifier("minerServerBlockValidation") BlockValidationRule validationRules,
        RskSystemProperties config, ReceiptStore receiptStore, MinerClock clock) {
    this.miningConfig = Objects.requireNonNull(miningConfig);
    this.repository = Objects.requireNonNull(repository);
    this.blockStore = Objects.requireNonNull(blockStore);
    this.transactionPool = Objects.requireNonNull(transactionPool);
    this.difficultyCalculator = Objects.requireNonNull(difficultyCalculator);
    this.gasLimitCalculator = Objects.requireNonNull(gasLimitCalculator);
    this.validationRules = Objects.requireNonNull(validationRules);
    this.clock = Objects.requireNonNull(clock);
    this.minimumGasPriceCalculator = new MinimumGasPriceCalculator();
    this.minerUtils = new MinerUtils();
    final ProgramInvokeFactoryImpl programInvokeFactory = new ProgramInvokeFactoryImpl();
    this.executor = new BlockExecutor(repository,
            (tx1, txindex1, coinbase, track1, block1, totalGasUsed1) -> new TransactionExecutor(tx1, txindex1,
                    block1.getCoinbase(), track1, blockStore, receiptStore, programInvokeFactory, block1, null,
                    totalGasUsed1, config.getVmConfig(), config.getBlockchainConfig(), config.playVM(),
                    config.isRemascEnabled(), config.vmTrace(), new PrecompiledContracts(config),
                    config.databaseDir(), config.vmTraceDir(), config.vmTraceCompressed()));

    this.minerMinGasPriceTarget = Coin.valueOf(miningConfig.getMinGasPriceTarget());
}

From source file:at.gridtec.lambda4j.generator.util.LambdaUtils.java

/**
 * Searches for a {@link LambdaEntity} using given lambda type, lambda arity and throwable flag. If the lambda
 * exists, it will be returned as is, otherwise {@code null} is returned.
 *
 * @param type The lambdas type/*w w w  . j  a  v  a 2  s . c  o m*/
 * @param arity The lambdas arity
 * @param isThrowable The flag indicating if lambda is throwable
 * @param preferFromJdk A flag if we also search for {@code JDK} lambdas
 * @return The lambda from given lambda type, lambda arity and throwable flag, or {@code null} if no such lambda
 * exists.
 * @throws NullPointerException If given lambda type is {@code null}
 * @throws IllegalArgumentException If given lambda arity is < 0
 * @implNote This implementation search for the lambda, which match the given arguments. If the {@code
 * #preferFromJdk} flag is set to {@code true}, then {@code JDK} lambdas are preferred over those from this library.
 * In either case, if no appropriate match could be found, {@code null} is returned.
 */
public static LambdaEntity search(@Nonnull final LambdaTypeEnum type, @Nonnegative int arity,
        boolean isThrowable, boolean preferFromJdk) {
    // Check arguments
    Objects.requireNonNull(type);
    if (arity < 0) {
        throw new IllegalArgumentException("arity must be greater than 0");
    }

    // Default variable declaration
    Optional<LambdaEntity> optionalLambda = Optional.empty();

    // If jdk flag set, then find jdk lambda if such
    if (preferFromJdk) {
        optionalLambda = LambdaCache.getInstance().getJdkLambdas().stream()
                .filter(l -> l.getType().equals(type)).filter(l -> l.getArity() == arity)
                .filter(l -> l.isThrowable() == isThrowable).findFirst();
    }

    // If jdk lambda not present find other non-jdk one and return if found or return null; if present return jdk lambda
    if (!optionalLambda.isPresent()) {
        return LambdaCache.getInstance().getLambdas().stream().filter(l -> l.getType().equals(type))
                .filter(l -> l.getArity() == arity).filter(l -> l.isThrowable() == isThrowable).findFirst()
                .orElse(null);
    } else {
        return optionalLambda.get();
    }
}

From source file:at.yawk.buycraft.BuycraftApiImpl.java

@Override
public String url(String url) throws IOException {
    Objects.requireNonNull(url);
    return get("url", new URIBuilder().setParameter("url", url)).getAsJsonObject("payload").get("url")
            .getAsString();// w ww . ja v  a2  s.c o m
}

From source file:org.eclipse.hono.service.auth.impl.FileBasedAuthenticationService.java

/**
 * Sets the factory to use for creating tokens asserting a client's identity and authorities.
 * //from ww w .j  ava  2  s  . com
 * @param tokenFactory The factory.
 * @throws NullPointerException if factory is {@code null}.
 */
@Autowired
@Qualifier("signing")
public void setTokenFactory(final AuthTokenHelper tokenFactory) {
    this.tokenFactory = Objects.requireNonNull(tokenFactory);
}

From source file:org.eclipse.hono.service.tenant.TenantAmqpEndpoint.java

/**
 * Checks if the client is authorized to invoke an operation.
 * <p>//  www.  j  ava  2 s .c o m
 * If the request does not include a <em>tenant_id</em> application property
 * then the request is authorized by default. This behavior allows clients to
 * invoke operations that do not require a tenant ID as a parameter. In such
 * cases the {@link #filterResponse(HonoUser, EventBusMessage)} method is used
 * to verify that the response only contains data that the client is authorized
 * to retrieve.
 * <p>
 * If the request does contain a tenant ID parameter in its application properties
 * then this tenant ID is used for the authorization check together with the
 * endpoint and operation name.
 *
 * @param clientPrincipal The client.
 * @param resource The resource the operation belongs to.
 * @param request The message for which the authorization shall be checked.
 * @return The outcome of the check.
 * @throws NullPointerException if any of the parameters is {@code null}.
 */
@Override
protected Future<Boolean> isAuthorized(final HonoUser clientPrincipal, final ResourceIdentifier resource,
        final Message request) {

    Objects.requireNonNull(request);

    final String tenantId = MessageHelper.getTenantId(request);
    if (tenantId == null) {
        // delegate authorization check to filterResource operation
        return Future.succeededFuture(Boolean.TRUE);
    } else {
        final ResourceIdentifier specificTenantAddress = ResourceIdentifier
                .fromPath(new String[] { resource.getEndpoint(), tenantId });

        return getAuthorizationService().isAuthorized(clientPrincipal, specificTenantAddress,
                request.getSubject());
    }
}

From source file:com.diffplug.gradle.oomph.OomphIdeExtension.java

public OomphIdeExtension(Project project) throws IOException {
    this.project = Objects.requireNonNull(project);
    this.workspaceRegistry = WorkspaceRegistry.instance();
    this.name = project.getRootProject().getName();
    this.perspective = Perspectives.RESOURCES;
}

From source file:com.envision.envservice.service.UserService.java

/**
 * //from   w w w  .j a v  a  2  s.  c om
 * 
 * @Title: login 
 * @Description: Ldap?, SAP??
 * @param username
 * @param password
 * @return User
 * @throws Exception 
 * @Date 2015-10-22
 */
public UserBo login(String username, String password) throws Exception {
    Objects.requireNonNull(username);
    Objects.requireNonNull(password);
    if (password != null && password.length() > 0) {
        //         boolean authenricate = userAuthenticate.authenricate(username + MAIL_SUFFIX, password);
        boolean authenricate = true;
        if (authenricate) {
            UserBo user = queryUserByUsername(username);
            if (user != null) {
                httpSession.setAttribute(Constants.SESSION_USER, user);
                return user;
            }
            throw new ServiceException(Code.USER_NOT_FOUND, "?");
        } else {
            throw new ServiceException(Code.USER_AUTHENTICATION_FAIL,
                    "?   username:" + username);
        }
    } else {
        throw new ServiceException(Code.USER_AUTHENTICATION_FAIL, "?   username:" + username);
    }

}