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:fr.landel.utils.commons.builder.HashCodeBuilder2.java

/**
 * Append the {@code hashCode} returned by the {@code getter} function. The
 * {@code getter} method is only applied if the {@code object} is not
 * {@code null}.//from ww w.j  a v  a 2s  .c o m
 * 
 * @param getter
 *            the function to apply if both objects are not {@code null}
 *            (required, throws a {@link NullPointerException} if
 *            {@code null})
 * @param <X>
 *            the sub type
 * @return the current builder
 */
public <X> HashCodeBuilder2<T> append(final Function<T, X> getter) {
    Objects.requireNonNull(getter, "getter");
    if (this.object != null) {
        this.append(getter.apply(this.object));
    }
    return this;
}

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

/**
 * Find the root path for the given resource. If the resource 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.
 *
 * For example, if the resourceName is given as "scripts/myscript.groovy", and the path to the file is
 * "/root/sub1/script/myscript.groovy", then this method will return "/root/sub1"
 *
 * @param resourceName relative path of the resource to search for. E.G. "scripts/myscript.groovy"
 * @param classLoader the {@link ClassLoader} to search
 * @return absolute path of the root of the resource.
 *///from   w  w  w .  j  av  a  2 s .  co  m
@Nullable
public static Path findRootPathForResource(String resourceName, ClassLoader classLoader) {
    Objects.requireNonNull(resourceName, "resourceName");
    Objects.requireNonNull(classLoader, "classLoader");

    URL resource = classLoader.getResource(resourceName);
    if (resource != null) {
        String protocol = resource.getProtocol();
        if (protocol.equals("jar")) {
            return getJarPathFromUrl(resource);
        } else if (protocol.equals("file")) {
            return getRootPathFromDirectory(resourceName, resource);
        } else {
            throw new IllegalStateException("Unsupported URL protocol: " + protocol);
        }
    }
    return null;
}

From source file:com.conwet.silbops.msg.PublishMsg.java

public PublishMsg(Notification notification, Context context) {

    super(MessageType.PUBLISH);
    this.notification = Objects.requireNonNull(notification, "Notification is null");
    this.context = Objects.requireNonNull(context, "Context is null");
}

From source file:com.conwet.silbops.msg.ContextMsg.java

public ContextMsg(String id, Context context) {

    super(MessageType.CONTEXT);
    // TODO FIX how contextID is generated
    //      this.id = Objects.requireNonNull(id, "ID is null");
    this.id = id == null ? "" : id;
    this.context = Objects.requireNonNull(context, "Context is null");
}

From source file:net.javacrumbs.completionstage.CallbackRegistry.java

/**
 * Adds the given callbacks to this registry.
 *///from   w ww .java  2s  . c om
public void addCallbacks(Consumer<? super T> successCallback, Consumer<Throwable> failureCallback,
        Executor executor) {
    Objects.requireNonNull(successCallback, "'successCallback' must not be null");
    Objects.requireNonNull(failureCallback, "'failureCallback' must not be null");
    Objects.requireNonNull(executor, "'executor' must not be null");

    synchronized (mutex) {
        state = state.addCallbacks(successCallback, failureCallback, executor);
    }
}

From source file:fr.landel.utils.commons.builder.HashCodeBuilder.java

/**
 * Append the {@code hashCode} returned by the {@code getter} function. The
 * {@code getter} method is only applied if the {@code object} is not
 * {@code null}./*from   w  w  w  .j a va  2 s. co  m*/
 * 
 * @param object
 *            the first object
 * @param getter
 *            the function to apply if both objects are not {@code null}
 *            (required, throws a {@link NullPointerException} if
 *            {@code null})
 * @param <O>
 *            the check object type
 * @param <X>
 *            the sub type
 * @return the current builder
 */
public <O, X> HashCodeBuilder append(final O object, final Function<O, X> getter) {
    Objects.requireNonNull(getter, "getter");
    if (object != null) {
        this.append(getter.apply(object));
    }
    return this;
}

From source file:fr.gael.dhus.util.functional.collect.TransformedMap.java

public TransformedMap(Map<K, Vi> input, Transformer<Duo<K, Vi>, Vo> transformer) {
    Objects.requireNonNull(input, "input map must not be null");
    Objects.requireNonNull(transformer, "transformer must not be null");

    this.input = input;
    this.transformer = transformer;
}

From source file:net.andylizi.laserlib.LaserManagerImpl.java

@Override
public Laser createLaser(Location source, Entity target, boolean elder) throws RuntimeException {
    Objects.requireNonNull(source, "source cannot be null");
    Objects.requireNonNull(target, "target cannot be null");
    Validate.isTrue(source.getWorld().getUID().equals(target.getWorld().getUID()),
            "source and target must in the same world");
    Location guardianPos = source.clone().add(0, -GUARDIAN_EYE_HEIGHT, 0);
    try {//from www  .  j  a  v a  2  s. com
        DummyEntity guardian = NMSUtil.createDummyGuardian(guardianPos, elder, target.getEntityId());
        NMSUtil.dummyGuardians.add(new DummyGuardianRecord(target.getEntityId(), guardian, null));
        return new RealLaser(source, guardian, target);
    } catch (ReflectiveOperationException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.navercorp.pinpoint.web.calltree.span.SpanAlign.java

public SpanAlign(SpanBo spanBo, boolean meta) {
    this.spanBo = Objects.requireNonNull(spanBo, "spanBo must not be null");
    this.hasChild = hasChild0();
    this.meta = meta;
}

From source file:com.navercorp.pinpoint.collector.receiver.thrift.tcp.AgentEventHandler.java

@Async("agentEventWorker")
public void handleEvent(PinpointServer pinpointServer, long eventTimestamp, AgentEventType eventType) {
    Objects.requireNonNull(pinpointServer, "pinpointServer must not be null");
    Objects.requireNonNull(eventType, "pinpointServer must not be null");

    final Map<Object, Object> channelProperties = pinpointServer.getChannelProperties();
    if (MapUtils.isEmpty(channelProperties)) {
        // It can occurs CONNECTED -> RUN_WITHOUT_HANDSHAKE -> CLOSED(UNEXPECTED_CLOSE_BY_CLIENT, ERROR_UNKNOWN)
        logger.warn("maybe not yet received the handshake data - pinpointServer:{}", pinpointServer);
        return;/*  w  w w  .  j  a  v a2  s.co  m*/
    }

    final String agentId = MapUtils.getString(channelProperties, HandshakePropertyType.AGENT_ID.getName());
    final long startTimestamp = MapUtils.getLong(channelProperties,
            HandshakePropertyType.START_TIMESTAMP.getName());
    final AgentEventBo agentEventBo = newAgentEventBo(agentId, startTimestamp, eventTimestamp, eventType);
    this.agentEventService.insert(agentEventBo);
}