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:it.unibo.alchemist.model.implementations.timedistributions.SAPEREExponentialTime.java

/**
 * @param rateEquation/* w  w  w  . j a v  a  2s .  c  o  m*/
 *            the rate equation
 * @param start
 *            initial time
 * @param random
 *            the {@link RandomGenerator}
 */
public SAPEREExponentialTime(final String rateEquation, final Time start, final RandomGenerator random) {
    super(Double.NaN, start, Objects.requireNonNull(random));
    double temp = 0d;
    boolean numeric = true;
    try {
        temp = Double.parseDouble(Objects.requireNonNull(rateEquation));
    } catch (NumberFormatException e) {
        numeric = false;
    }
    numericRate = numeric;
    staticRate = temp;
    if (numericRate) {
        if (Double.isInfinite(staticRate)) {
            exp = new Expression("asap");
        } else {
            exp = new Expression(FORMAT.format(staticRate));
        }
    } else {
        exp = new Expression(rateEquation);
    }
}

From source file:azkaban.jobtype.connectors.gobblin.GobblinHadoopJob.java

/**
 * Factory method that provides IPropertiesValidator based on preset in runtime.
 * Using factory method pattern as it is expected to grow.
 * @param preset/*  w ww.j a  va  2 s .co  m*/
 * @return IPropertiesValidator
 */
private static IPropertiesValidator getValidator(GobblinPresets preset) {
    Objects.requireNonNull(preset);
    switch (preset) {
    case MYSQL_TO_HDFS:
        return new MySqlToHdfsValidator();
    case HDFS_TO_MYSQL:
        return new HdfsToMySqlValidator();
    default:
        throw new UnsupportedOperationException("Preset " + preset + " is not supported");
    }
}

From source file:org.eclipse.hono.service.auth.device.X509AuthProvider.java

/**
 * Creates a {@link SubjectDnCredentials} instance from information provided by a
 * device in its client (X.509) certificate.
 * <p>/*from www. j  a  va2 s . c o m*/
 * The JSON object passed in is required to contain a <em>subject-dn</em> property.
 * If the <em>singleTenant</em> service config property is {@code false}, then the
 * object is also required to contain a <em>tenant-id</em> property, otherwise
 * the default tenant is used.
 * 
 * @param authInfo The authentication information provided by the device.
 * @return The credentials or {@code null} if the authentication information
 *         does not contain a tenant ID and subject DN.
 * @throws NullPointerException if the authentication info is {@code null}.
 */
@Override
protected DeviceCredentials getCredentials(final JsonObject authInfo) {

    Objects.requireNonNull(authInfo);
    try {
        final String tenantId = Optional
                .ofNullable(authInfo.getString(CredentialsConstants.FIELD_PAYLOAD_TENANT_ID)).orElseGet(() -> {
                    if (config.isSingleTenant()) {
                        return Constants.DEFAULT_TENANT;
                    } else {
                        return null;
                    }
                });
        final String subjectDn = authInfo.getString(CredentialsConstants.FIELD_PAYLOAD_SUBJECT_DN);
        if (tenantId == null || subjectDn == null) {
            return null;
        } else {
            return SubjectDnCredentials.create(tenantId, subjectDn);
        }
    } catch (ClassCastException e) {
        return null;
    }
}

From source file:com.github.horrorho.liquiddonkey.cloud.client.AccountClient.java

AccountClient(ResponseHandler<ICloud.MBSAccount> mbsaAccountResponseHandler, Headers headers) {
    this.mbsAccountResponseHandler = Objects.requireNonNull(mbsaAccountResponseHandler);
    this.headers = Objects.requireNonNull(headers);
}

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

public StyleLoader(OpenOfficePreferences preferences, JabRefPreferences jabrefPreferences,
        JournalAbbreviationLoader journalAbbreviationLoader, Charset encoding) {
    this.journalAbbreviationLoader = Objects.requireNonNull(journalAbbreviationLoader);
    this.preferences = Objects.requireNonNull(preferences);
    this.jabrefPreferences = Objects.requireNonNull(jabrefPreferences);
    this.encoding = Objects.requireNonNull(encoding);
    loadInternalStyles();//from   w ww .  j a v a 2s  . co m
    loadExternalStyles();
}

From source file:net.sf.jabref.importer.fileformat.FreeCiteImporter.java

@Override
public boolean isRecognizedFormat(BufferedReader reader) throws IOException {
    Objects.requireNonNull(reader);
    // TODO: We don't know how to recognize text files, therefore we return "false"
    return false;
}

From source file:com.dgtlrepublic.anitomyj.Tokenizer.java

/**
 * Tokenize a filename into {@link Element}s.
 *
 * @param filename the filename/*from   w ww . j  av  a 2 s.c  o  m*/
 * @param elements the list of elements where preidentified tokens will be added
 * @param options  the parser options
 * @param tokens   the list of tokens where tokens will be added.
 */
public Tokenizer(String filename, List<Element> elements, Options options, List<Token> tokens) {
    this.filename = Objects.requireNonNull(filename);
    this.elements = Objects.requireNonNull(elements);
    this.options = Objects.requireNonNull(options);
    this.tokens = Objects.requireNonNull(tokens);
}

From source file:org.eclipse.hono.connection.ConnectionFactoryImpl.java

/**
 * Sets the configuration parameters for connecting to the AMQP server.
 * <p>/* w  w  w  .  j  a v  a2  s .  c o m*/
 * The <em>name</em> property of the configuration is used as the basis
 * for the local container name which is then appended with a UUID.
 *  
 * @param config The configuration parameters.
 * @throws NullPointerException if the parameters are {@code null}.
 */
@Autowired
public final void setClientConfig(final ClientConfigProperties config) {
    this.config = Objects.requireNonNull(config);
}

From source file:com.github.horrorho.inflatabledonkey.cache.StreamCryptor.java

public StreamCryptor(KDF kdf, int saltLength, int nonceLength, int tagLength) {
    this.kdf = Objects.requireNonNull(kdf);
    this.saltLength = saltLength;
    this.nonceLength = nonceLength;
    this.tagLength = tagLength;
}

From source file:net.sf.jabref.importer.fileformat.BibTeXMLImporter.java

@Override
public ParserResult importDatabase(BufferedReader reader) throws IOException {
    Objects.requireNonNull(reader);

    List<BibEntry> bibItems = new ArrayList<>();

    // Obtain a factory object for creating SAX parsers
    SAXParserFactory parserFactory = SAXParserFactory.newInstance();
    // Configure the factory object to specify attributes of the parsers it
    // creates/*from  www.java2 s.  c  o  m*/
    // parserFactory.setValidating(true);
    parserFactory.setNamespaceAware(true);
    // Now create a SAXParser object

    try {
        SAXParser parser = parserFactory.newSAXParser(); //May throw exceptions
        BibTeXMLHandler handler = new BibTeXMLHandler();
        // Start the parser. It reads the file and calls methods of the handler.
        parser.parse(new InputSource(reader), handler);
        // When you're done, report the results stored by your handler object
        bibItems.addAll(handler.getItems());

    } catch (javax.xml.parsers.ParserConfigurationException e) {
        LOGGER.error("Error with XML parser configuration", e);
        return ParserResult.fromErrorMessage(e.getLocalizedMessage());
    } catch (org.xml.sax.SAXException e) {
        LOGGER.error("Error during XML parsing", e);
        return ParserResult.fromErrorMessage(e.getLocalizedMessage());
    } catch (IOException e) {
        LOGGER.error("Error during file import", e);
        return ParserResult.fromErrorMessage(e.getLocalizedMessage());
    }
    return new ParserResult(bibItems);
}