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:it.reply.orchestrator.dto.deployment.CredentialsAwareSlaPlacementPolicy.java

/**
 * Set the password from an {@link AbstractPropertyValue}.
 * /*w ww.  ja  v  a2s .c  o  m*/
 * @param password
 *          the password
 */
public void setPassword(AbstractPropertyValue password) {
    Objects.requireNonNull(password, "password must not be null");
    Assert.isInstanceOf(ScalarPropertyValue.class, password, "password must be a scalar value");
    this.password = ((ScalarPropertyValue) password).getValue();
}

From source file:edu.usu.sdl.openstorefront.service.OrganizationServiceImpl.java

@Override
public void saveOrganization(Organization organization) {
    Objects.requireNonNull(organization, "Organization is required");
    Objects.requireNonNull(organization.getName(), "Organization name is required");

    Organization organizationExisting = persistenceService.findById(Organization.class,
            organization.getOrganizationId());
    if (organizationExisting == null) {
        organizationExisting = persistenceService.findById(Organization.class, organization.nameToKey());
    }//  ww  w.ja v  a 2s  .  c  om

    if (organizationExisting != null) {
        organizationExisting.updateFields(organization);
        persistenceService.persist(organizationExisting);
    } else {
        organization.setOrganizationId(organization.nameToKey());
        organization.populateBaseCreateFields();
        persistenceService.persist(organization);
    }
}

From source file:com.navercorp.pinpoint.collector.service.AgentEventService.java

void handleEvent(PinpointServer pinpointServer, long eventTimestamp, AgentEventType eventType,
        Object eventMessage) {/*from   w  w  w. j a v  a2s.c o m*/
    Objects.requireNonNull(pinpointServer, "pinpointServer must not be null");
    Objects.requireNonNull(eventType, "pinpointServer must not be null");

    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;
    }

    final String agentId = MapUtils.getString(channelProperties, HandshakePropertyType.AGENT_ID.getName());
    final long startTimestamp = MapUtils.getLong(channelProperties,
            HandshakePropertyType.START_TIMESTAMP.getName());

    AgentEventBo agentEventBo = newAgentEventBo(agentId, startTimestamp, eventTimestamp, eventType);
    insertEvent(agentEventBo, eventMessage);
}

From source file:io.github.retz.web.feign.Retz.java

static Retz connect(URI uri, Authenticator authenticator, SSLSocketFactory socketFactory,
        HostnameVerifier hostnameVerifier) {
    String url = Objects.requireNonNull(uri, "uri cannot be null").toString();
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new Jdk8Module());
    return Feign.builder().client(new Client.Default(socketFactory, hostnameVerifier)).logger(new Slf4jLogger())
            .encoder(new JacksonEncoder(mapper)).decoder(new JacksonDecoder(mapper))
            .errorDecoder(new ErrorResponseDecoder(mapper))
            .requestInterceptor(new AuthHeaderInterceptor(authenticator)).target(Retz.class, url);
}

From source file:com.cloudera.oryx.app.speed.als.ALSSpeedModelManager.java

@Override
public void consume(Iterator<KeyMessage<String, String>> updateIterator, Configuration hadoopConf)
        throws IOException {
    int countdownToLogModel = 10000;
    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
            }/*from   w w  w.j a v a2 s.c  o m*/
            // Note that here, the speed layer is actually listening for updates from
            // two sources. First is the batch layer. This is somewhat unusual, because
            // the batch layer usually only makes MODELs. The ALS model is too large
            // to send in one file, so is sent as a skeleton model plus a series of updates.
            // However it is also, neatly, listening for the same updates it produces below
            // in response to new data, and applying them to the in-memory representation.
            // ALS continues to be a somewhat special case here, in that it does benefit from
            // real-time updates to even the speed layer reference model.
            List<?> update = MAPPER.readValue(message, List.class);
            // Update
            String id = update.get(1).toString();
            float[] vector = MAPPER.convertValue(update.get(2), float[].class);
            switch (update.get(0).toString()) {
            case "X":
                model.setUserVector(id, vector);
                break;
            case "Y":
                model.setItemVector(id, vector);
                break;
            default:
                throw new IllegalArgumentException("Bad message: " + km);
            }
            if (--countdownToLogModel <= 0) {
                log.info("{}", model);
                countdownToLogModel = 10000;
            }
            break;

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

            int features = Integer.parseInt(AppPMMLUtils.getExtensionValue(pmml, "features"));
            boolean implicit = Boolean.parseBoolean(AppPMMLUtils.getExtensionValue(pmml, "implicit"));

            if (model == null || features != model.getFeatures()) {
                log.warn("No previous model, or # features has changed; creating new one");
                model = new ALSSpeedModel(features, implicit);
            }

            log.info("Updating model");
            // Remove users/items no longer in the model
            Collection<String> XIDs = new HashSet<>(AppPMMLUtils.getExtensionContent(pmml, "XIDs"));
            Collection<String> YIDs = new HashSet<>(AppPMMLUtils.getExtensionContent(pmml, "YIDs"));
            model.retainRecentAndUserIDs(XIDs);
            model.retainRecentAndItemIDs(YIDs);
            log.info("Model updated: {}", model);
            break;

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