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.trustedanalytics.uploader.rest.Transfer.java

public Transfer(Transfer transfer) {
    this.source = Objects.requireNonNull(transfer.getSource(), "source is required");
    this.orgUUID = Objects.requireNonNull(transfer.getOrgUUID(), "orgUUID is required");
    this.title = Objects.requireNonNull(transfer.getTitle(), "title is required");
    this.category = Objects.requireNonNull(transfer.getCategory(), "category is required");
    this.publicAccess = Objects.requireNonNull(transfer.isPublicAccess(), "publicAccess is required");
    this.objectStoreId = Objects.requireNonNull(transfer.getObjectStoreId(), "objectStoreId is required");
    this.savedObjectId = Objects.requireNonNull(transfer.getSavedObjectId(), "savedObjectId is required");
}

From source file:org.apache.river.springframework.config.ApplicationContextAdapter.java

@Override
public Object getEntry(String component, String name, Class type, Object defaultValue, Object data)
        throws ConfigurationException {
    Objects.requireNonNull(name, "The name parameter must not be null.");
    Objects.requireNonNull(name, "The type parameter must not be null.");

    Object value = null;/*ww  w  .j  a  v  a  2 s. c  o m*/

    try {
        if (component != null && !component.isEmpty()) {
            try {
                value = adaptee.getBean(component + "." + name);
            } catch (NoSuchBeanDefinitionException e) {
            }
        }
        if (value == null) {
            try {
                value = adaptee.getBean(name);
            } catch (NoSuchBeanDefinitionException e) {
            }
        }
    } catch (BeansException e) {
        throw new ConfigurationException("Unable to get configuration value.", e);
    }

    if (value == null) {
        if (defaultValue == Configuration.NO_DEFAULT) {
            throw new NoSuchEntryException("No configuration value found.");
        } else {
            value = defaultValue;
        }
    }

    if (value != null) {
        if ((type.isPrimitive() && (type == boolean.class && value instanceof Boolean)
                || (type == char.class && value instanceof Character)
                || (type == byte.class && value instanceof Byte)
                || (type == short.class && value instanceof Short)
                || (type == int.class && value instanceof Integer)
                || (type == long.class && value instanceof Long)
                || (type == float.class && value instanceof Float)
                || (type == double.class && value instanceof Double)) || type.isInstance(value)) {

        } else {
            throw new IllegalArgumentException("Configuration value cannot be converted to type.");
        }
    }

    return value;
}

From source file:org.zalando.problem.DefaultProblem.java

DefaultProblem(final URI type, final String title, final StatusType status, final Optional<String> detail,
        final Optional<URI> instance, @Nullable final ThrowableProblem cause) {
    super(cause);
    this.type = Objects.requireNonNull(type, "type must not be null");
    this.title = Objects.requireNonNull(title, "title must not be null");
    this.status = Objects.requireNonNull(status, "status must not be null");
    this.detail = Objects.requireNonNull(detail, "detail must not be null");
    this.instance = Objects.requireNonNull(instance, "instance must not be null");
}

From source file:it.unibo.alchemist.language.protelis.MethodCall.java

/**
 * @param m//ww w .  j a  va2 s  .c o  m
 *            the method to call
 * @param branch
 *            the Protelis sub-programs
 * @param isStatic
 *            if false, the first branch must contain the AnnotatedTree whose
 *            annotation will contain the object on which the method will be
 *            invoked
 */
public MethodCall(final Method m, final List<AnnotatedTree<?>> branch, final boolean isStatic) {
    super(branch);
    Objects.requireNonNull(m, "No compatible method found.");
    method = m;
    ztatic = isStatic;

    boolean found = false;
    for (Class<?> clazz : method.getParameterTypes()) {
        if (Field.class.isAssignableFrom(clazz)) {
            found = true;
            break;
        }
    }
    fieldComposable = !found;
}

From source file:com.github.xbn.list.ListUtil.java

/**
   <p>YYY</p>/*from  w w  w  . j a  v a2  s  . c  o  m*/
        
 * @exception  XbnIndexOutOfBoundsException  If any {@code list_ofUniqueAscIdxsToDelete} are invalid for {@code list}, or if its elements are not unique or ascending, causing subsequent indexes (that <i>were</i> valid) to not be valid.
 */
public static final void deleteElementsNotInAscUnqIndexList(List<?> list,
        List<Integer> list_ofUniqueAscIdxsToDelete) {
    int iOrigSz = -1;
    //      int iLXSz = -1;
    try {
        iOrigSz = list.size();
        //         iLXSz = list_ofUniqueAscIdxsToDelete.size();
    } catch (RuntimeException rx) {
        Objects.requireNonNull(list, "list");
        throw CrashIfObject.nullOrReturnCause(list_ofUniqueAscIdxsToDelete, "list_ofUniqueAscIdxsToDelete",
                null, rx);
    }

    //Going backwards, so indexes in list_ofUniqueAscIdxsToDelete don't have to be decremented.
    for (int i = (list_ofUniqueAscIdxsToDelete.size() - 1); i >= 0; i--) {
        int ix = list_ofUniqueAscIdxsToDelete.get(i);
        try {
            list.remove(ix);
        } catch (IndexOutOfBoundsException ibx) {
            String sInfo = "Attempting list.remove(list_ofUniqueAscIdxsToDelete.get(" + i
                    + "). list_ofUniqueAscIdxsToDelete.get(" + i + ")=[" + ix
                    + "]. It is assumed-but-not-verified that list_ofUniqueAscIdxsToDelete contains only unique elements and is ordered ascending: ["
                    + StringUtils.join(list_ofUniqueAscIdxsToDelete, ", ")
                    + "]. Also note that list is as it exists after some deletions -- Its original size was "
                    + iOrigSz + ".";
            throw new XbnIndexOutOfBoundsException_Cfg()
                    .badIndex(ix, "list_ofUniqueAscIdxsToDelete.get(" + i + ")").absCollectionSize(list, "list")
                    .buildWithCauseInfo(ibx, sInfo);
        }
    }
}

From source file:ch.netzwerg.paleo.schema.Field.java

public Field(String name, ColumnType<?> type, Option<String> format) {
    this.name = safeString(name);
    this.type = safeType(type);
    this.format = Objects.requireNonNull(format, "format must not be null");
    this.metaData = LinkedHashMap.empty();
}

From source file:com.ejisto.core.classloading.SpringLoadedJVMPlugin.java

public SpringLoadedJVMPlugin(Consumer<String> reloadEventHandler) {
    LOGGER.info("SpringLoadedJVMPlugin : called constructor");
    Objects.requireNonNull(reloadEventHandler, "reloadEventHandler cannot be null");
    this.reloadEventHandler = reloadEventHandler;
}

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

@Async("agentEventWorker")
public void handleLifeCycleEvent(PinpointServer pinpointServer, long eventTimestamp,
        AgentLifeCycleState agentLifeCycleState, int eventCounter) {
    Objects.requireNonNull(pinpointServer, "pinpointServer must not be null");
    Objects.requireNonNull(agentLifeCycleState, "agentLifeCycleState must not be null");
    if (eventCounter < 0) {
        throw new IllegalArgumentException("eventCounter may not be negative");
    }//from   w w  w.  j av  a2 s  .co m
    logger.info("Handle lifecycle event - pinpointServer:{}, state:{}", pinpointServer, agentLifeCycleState);

    // TODO
    Map<Object, Object> channelProperties = pinpointServer.getChannelProperties();
    final Integer socketId = MapUtils.getInteger(channelProperties, SOCKET_ID_KEY);
    if (socketId == null) {
        logger.debug("socketId not found, agent does not support life cycle management - pinpointServer:{}",
                pinpointServer);
        return;
    }

    final String agentId = MapUtils.getString(channelProperties, HandshakePropertyType.AGENT_ID.getName());
    final long startTimestamp = MapUtils.getLong(channelProperties,
            HandshakePropertyType.START_TIMESTAMP.getName());
    final long eventIdentifier = createEventIdentifier(socketId, eventCounter);
    final AgentLifeCycleBo agentLifeCycleBo = new AgentLifeCycleBo(agentId, startTimestamp, eventTimestamp,
            eventIdentifier, agentLifeCycleState);

    agentLifeCycleService.insert(agentLifeCycleBo);
}

From source file:fr.landel.utils.commons.tuple.MutableSingle.java

/**
 * {@inheritDoc}/*w  w w  . j a  v a  2s . c o m*/
 */
@Override
public T update(final Function<T, T> function) {
    Objects.requireNonNull(this.element, "Cannot update, current element is null");
    return this.set(function.apply(this.element));
}

From source file:it.reply.orchestrator.dto.deployment.SlaPlacementPolicy.java

/**
 * Set the SLA id from a {@link AbstractPropertyValue}.
 * /*w  w  w  .j  a v  a  2  s . co m*/
 * @param slaId
 *          the SLA id
 */
public void setSlaId(AbstractPropertyValue slaId) {
    Objects.requireNonNull(slaId, "slaId must not be null");
    Assert.isInstanceOf(ScalarPropertyValue.class, slaId, "slaId must be a scalar value");
    this.slaId = ((ScalarPropertyValue) slaId).getValue();
}