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:org.keycloak.connections.httpclient.ProxyMappings.java

/**
 * @param hostname//from  w  w w  .  j  av  a2  s . co  m
 * @return the {@link HttpHost} proxy associated with the first matching hostname {@link Pattern}
 * or {@literal null} if none matches.
 */
public HttpHost getProxyFor(String hostname) {

    Objects.requireNonNull(hostname, "hostname");

    return entries.stream() //
            .filter(e -> e.matches(hostname)) //
            .findFirst() //
            .map(ProxyMapping::getProxy) //
            .orElse(null);
}

From source file:com.github.yongchristophertang.engine.web.request.HttpRequestBuilders.java

/**
 * Package private constructor. To get an instance, use static factory
 * methods in {@link TestRequestBuilders}.
 * <p/>/*  w w w  . j  a va2s  .  c om*/
 * <p>Although this class cannot be extended, additional ways to initialize
 * the {@code MockHttpServletRequest} can be plugged in via
 * {@link #with(RequestPostProcessor)}.
 *
 * @param urlTemplate  a URL template; the resulting URL will be encoded
 * @param urlVariables zero or more URL variables
 */
HttpRequestBuilders(HttpRequest httpRequest, String urlTemplate, String description, Object... urlVariables) {

    Objects.requireNonNull(urlTemplate, "uriTemplate is required");
    Objects.requireNonNull(httpRequest, "httpRequest is required");

    this.description = description;
    this.httpRequest = httpRequest;
    expandURLTemplate(urlTemplate, urlVariables);
    this.uriTemplate = urlTemplate;
}

From source file:com.conwet.silbops.api.impl.XJSPPubEndpoint.java

@Override
public void setContext(Context context) {

    this.context = Objects.requireNonNull(context, "Context is null");
}

From source file:com.netflix.nicobar.core.utils.ClassPathUtils.java

/**
 * Find the root path for the given class. If the class is found in a Jar file, then the
 * result will be an absolute path to the jar file. If the resource is found in a directory,
 * then the result will be the parent path of the given resource.
 *
 * @param clazz class to search for/*from  w  w  w  . ja v  a 2  s  .  c om*/
 * @return absolute path of the root of the resource.
 */
@Nullable
public static Path findRootPathForClass(Class<?> clazz) {
    Objects.requireNonNull(clazz, "resourceName");
    String resourceName = classToResourceName(clazz);
    return findRootPathForResource(resourceName, clazz.getClassLoader());
}

From source file:com.seyren.core.util.velocity.AbstractHelper.java

protected String getTemplateAsString(String fileName) {
    Objects.requireNonNull(fileName, "filename is null");

    try {/*from w ww . j av a2  s  .c o  m*/
        // Handle the template filename as either a class path resource or an absolute path to the filesystem.
        InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
        if (inputStream == null) {
            inputStream = new FileInputStream(fileName);
        }
        return IOUtils.toString(inputStream);
    } catch (IOException e) {
        throw new RuntimeException("Template file could not be found on classpath at " + fileName);
    }
}

From source file:ch.puzzle.itc.mobiliar.business.auditview.control.AuditService.java

@SuppressWarnings("unchecked")
public <T> Object getDeletedEntity(T entity, Integer id) {
    Objects.requireNonNull(entity, "Entity can not be null");
    Objects.requireNonNull(id, "Id can not be null");

    AuditReader reader = AuditReaderFactory.get(entityManager);

    if (reader.isEntityClassAudited(entity.getClass())) {
        AuditQuery query = reader.createQuery().forRevisionsOfEntity(entity.getClass(), false, true)
                .add(AuditEntity.id().eq(id)).add(AuditEntity.revisionType().eq(DEL));

        List<Object[]> resultList = query.getResultList();
        if (!resultList.isEmpty()) {
            return resultList.get(0)[0];
        }/*from ww w.j  a va 2s . co m*/
    }
    return null;
}

From source file:com.github.jinahya.sql.database.metadata.bind.MetadataContext.java

/**
 * Creates a new instance with given {@code DatabaseMetaData}.
 *
 * @param database the {@code DatabaseMetaData} instance to hold.
 *//*from  w w  w .  j av  a2 s  .c  o  m*/
public MetadataContext(final DatabaseMetaData database) {

    super();

    this.database = Objects.requireNonNull(database, "null database");
}

From source file:de.speexx.jira.jan.command.issuequery.CsvCreator.java

void checkParameter(final IssueData issueData, final List<FieldName> historyFieldNames,
        final List<FieldNamePath> currentFieldNames, final TemporalChangeOutput temporalOutput,
        final AtomicBoolean header) {
    Objects.requireNonNull(issueData, "issueData is null");
    Objects.requireNonNull(historyFieldNames, "historyFieldNames is null");
    Objects.requireNonNull(currentFieldNames, "currentFieldNames is null");
    Objects.requireNonNull(temporalOutput, "temporalOutput is null");
    Objects.requireNonNull(header, "header is null");
}

From source file:com.navercorp.pinpoint.web.service.map.FilteredMapBuilder.java

public FilteredMapBuilder(ApplicationFactory applicationFactory, ServiceTypeRegistryService registry,
        Range range, int version) {
    this.applicationFactory = Objects.requireNonNull(applicationFactory, "applicationFactory must not be null");
    this.registry = Objects.requireNonNull(registry, "registry must not be null");
    Objects.requireNonNull(range, "range must not be null");

    this.version = version;

    this.timeWindow = new TimeWindow(range, TimeWindowDownSampler.SAMPLER);
    this.linkDataDuplexMap = new LinkDataDuplexMap();
    this.responseHistogramsBuilder = new ResponseHistograms.Builder(range);
    this.dotExtractor = new DotExtractor();
}

From source file:no.digipost.api.useragreements.client.DigipostUserAgreementsClient.java

public IdentificationResult identifyUser(final SenderId senderId, final UserId userId,
        final String requestTrackingId) {
    Objects.requireNonNull(senderId, "senderId cannot be null");
    Objects.requireNonNull(userId, "userId cannot be null");
    return apiService.identifyUser(senderId, userId, requestTrackingId,
            singleJaxbEntityHandler(IdentificationResult.class));
}