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, Supplier<String> messageSupplier) 

Source Link

Document

Checks that the specified object reference is not null and throws a customized NullPointerException if it is.

Usage

From source file:com.wavemaker.tools.apidocs.tools.parser.scanner.FilterableModelScanner.java

@Override
public boolean filter(final Class<?> type) {
    Objects.requireNonNull(type, "Type cannot be null");
    return !ClassUtils.isPrimitiveOrWrapper(type) && apply(type.getName() + CLASS_EXT);
}

From source file:edu.usu.sdl.openstorefront.util.ReflectionUtil.java

/**
 * Check for class to see if it's a collection class
 *
 * @param checkClass/*  w ww. j ava2s.  c o  m*/
 * @return
 */
public static boolean isCollectionClass(Class checkClass) {
    Objects.requireNonNull(checkClass, "Class is required");

    boolean collection = false;
    if (checkClass.getSimpleName().equalsIgnoreCase(List.class.getSimpleName())
            || checkClass.getSimpleName().equalsIgnoreCase(Map.class.getSimpleName())
            || checkClass.getSimpleName().equalsIgnoreCase(Collection.class.getSimpleName())
            || checkClass.getSimpleName().equalsIgnoreCase(Queue.class.getSimpleName())
            || checkClass.getSimpleName().equalsIgnoreCase(Set.class.getSimpleName())) {
        collection = true;
    }
    return collection;
}

From source file:org.elasticsearch.client.RestClientBuilder.java

/**
 * Creates a new builder instance and sets the hosts that the client will send requests to.
 *
 * @throws NullPointerException if {@code hosts} or any host is {@code null}.
 * @throws IllegalArgumentException if {@code hosts} is empty.
 *//*from w  w w. j a  va  2 s .c om*/
RestClientBuilder(HttpHost... hosts) {
    Objects.requireNonNull(hosts, "hosts must not be null");
    if (hosts.length == 0) {
        throw new IllegalArgumentException("no hosts provided");
    }
    for (HttpHost host : hosts) {
        Objects.requireNonNull(host, "host cannot be null");
    }
    this.hosts = hosts;
}

From source file:com.github.xbn.experimental.listify.backend.LFCharsInAString.java

public final char getChar(int index) {
    try {//from   ww w  .  jav  a  2 s  .com
        return getRawString().charAt(index);
    } catch (RuntimeException rx) {
        Objects.requireNonNull(getRawString(), "getRawString()");
        CrashIfIndex.badForLength(index, size(), "index", "size()");
        throw rx;
    }
}

From source file:com.github.yongchristophertang.engine.web.WebTemplateBuilder.java

/**
 * Set global default {@link ResultHandler} for built {@link WebTemplate}.
 *//*w  ww.  java2s. c o  m*/
public WebTemplateBuilder alwaysDo(ResultHandler resultHandler) {
    Objects.requireNonNull(resultHandler, "resultHandler must not be null");
    resultHandlers.add(resultHandler);
    return this;
}

From source file:ratpack.spring.config.RatpackProperties.java

static Path resourceToPath(URL resource) {

    Objects.requireNonNull(resource, "Resource URL cannot be null");
    URI uri;/*  ww  w.  j  a  v  a  2s .  c o m*/
    try {
        uri = resource.toURI();
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Could not extract URI", e);
    }

    String scheme = uri.getScheme();
    if (scheme.equals("file")) {
        String path = uri.toString().substring("file:".length());
        if (path.contains("//")) {
            path = StringUtils.cleanPath(path.replace("//", ""));
        }
        return Paths.get(new FileSystemResource(path).getFile().toURI());
    }

    if (!scheme.equals("jar")) {
        throw new IllegalArgumentException("Cannot convert to Path: " + uri);
    }

    String s = uri.toString();
    int separator = s.indexOf("!/");
    String entryName = s.substring(separator + 2);
    URI fileURI = URI.create(s.substring(0, separator));

    FileSystem fs;
    try {
        fs = FileSystems.newFileSystem(fileURI, Collections.<String, Object>emptyMap());
        return fs.getPath(entryName);
    } catch (IOException e) {
        throw new IllegalArgumentException("Could not create file system for resource: " + resource, e);
    }
}

From source file:alfio.config.Initializer.java

@Override
protected WebApplicationContext createRootApplicationContext() {
    ConfigurableWebApplicationContext ctx = ((ConfigurableWebApplicationContext) super.createRootApplicationContext());
    Objects.requireNonNull(ctx, "Something really bad is happening...");
    ConfigurableEnvironment environment = ctx.getEnvironment();
    if (environment.acceptsProfiles(PROFILE_DEV)) {
        environment.addActiveProfile(PROFILE_HTTP);
    }//  w  w w.j  a  va  2s. co  m
    this.environment = environment;
    return ctx;
}

From source file:com.github.horrorho.inflatabledonkey.requests.Headers.java

private Headers(String name) {
    this.name = Objects.requireNonNull(name, "name");
}

From source file:com.cloudera.oryx.app.serving.rdf.model.RDFServingModelManager.java

/**
 * Called by the framework to initiate a continuous process of reading models, and reading
 * from the input topic and updating model state in memory, and issuing updates to the
 * update topic. This will be executed asynchronously and may block.
 *
 * @param updateIterator iterator to read models from
 * @param hadoopConf Hadoop context, which may be required for reading from HDFS
 * @throws IOException if an error occurs while reading updates
 *///from w w w. ja va 2s. c  o m
@Override
public void consume(Iterator<KeyMessage<String, String>> updateIterator, Configuration hadoopConf)
        throws IOException {
    while (updateIterator.hasNext()) {
        KeyMessage<String, String> km = updateIterator.next();
        String key = km.getKey();
        String message = km.getMessage();
        Objects.requireNonNull(key, "Bad message: " + km);
        switch (key) {
        case "UP":
            if (model == null) {
                continue; // No model to interpret with yet, so skip it
            }

            DecisionForest forest = model.getForest();
            List<?> update = MAPPER.readValue(message, List.class);
            int treeID = Integer.parseInt(update.get(0).toString());
            String nodeID = update.get(1).toString();

            if (inputSchema.isClassification()) {
                TerminalNode nodeToUpdate = (TerminalNode) forest.getTrees()[treeID].findByID(nodeID);
                CategoricalPrediction predictionToUpdate = (CategoricalPrediction) nodeToUpdate.getPrediction();
                @SuppressWarnings("unchecked")
                Map<Integer, Integer> counts = (Map<Integer, Integer>) update.get(2);
                for (Map.Entry<?, ?> entry : counts.entrySet()) {
                    int encoding = Integer.parseInt(entry.getKey().toString());
                    int count = Integer.parseInt(entry.getValue().toString());
                    predictionToUpdate.update(encoding, count);
                }
            } else {
                TerminalNode nodeToUpdate = (TerminalNode) forest.getTrees()[treeID].findByID(nodeID);
                NumericPrediction predictionToUpdate = (NumericPrediction) nodeToUpdate.getPrediction();
                double mean = Double.parseDouble(update.get(2).toString());
                int count = Integer.parseInt(update.get(3).toString());
                predictionToUpdate.update(mean, count);
            }

            break;

        case "MODEL":
        case "MODEL-REF":
            log.info("Loading new model");
            PMML pmml = AppPMMLUtils.readPMMLFromUpdateKeyMessage(key, message, hadoopConf);

            RDFPMMLUtils.validatePMMLVsSchema(pmml, inputSchema);
            Pair<DecisionForest, CategoricalValueEncodings> forestAndEncodings = RDFPMMLUtils.read(pmml);
            model = new RDFServingModel(forestAndEncodings.getFirst(), forestAndEncodings.getSecond(),
                    inputSchema);
            log.info("New model: {}", model);
            break;

        default:
            throw new IllegalArgumentException("Bad message: " + km);
        }
    }
}

From source file:com.smokejumperit.gradle.report.DependencyLicenseReport.java

public void setReportedConfigurations(Iterable<?> reportedConfigurations) {
    if (reportedConfigurations == null) {
        this.reportedConfigurations = Collections.emptyList();
        return;/*w w  w.  j  a  v  a2s .c  o  m*/
    }
    this.reportedConfigurations = Iterables.transform(reportedConfigurations, new Function<Object, String>() {
        @Override
        public String apply(Object input) {
            Objects.requireNonNull(input, "reportedConfigurations element");
            if (input instanceof Configuration) {
                return ((Configuration) input).getName();
            } else {
                return input.toString();
            }
        }
    });
}