Example usage for java.util Objects nonNull

List of usage examples for java.util Objects nonNull

Introduction

In this page you can find the example usage for java.util Objects nonNull.

Prototype

public static boolean nonNull(Object obj) 

Source Link

Document

Returns true if the provided reference is non- null otherwise returns false .

Usage

From source file:com.mac.holdempoker.app.hands.Boat.java

private Card[] findBoat() {
    Card[] trips = null;//from w ww .  j a  v a 2 s.co m
    Card[] pair = null;
    for (Map.Entry<Rank, Card[]> entry : cards.entrySet()) {
        if (hasThree(entry.getValue())) {
            if (Objects.isNull(trips)) {
                trips = ArrayUtils.subarray(entry.getValue(), 0, 3);
            }
        } else if (hasTwo(entry.getValue())) {
            if (Objects.isNull(pair)) {
                pair = ArrayUtils.subarray(entry.getValue(), 0, 2);
            }
        }
    }
    if (Objects.nonNull(trips) && Objects.nonNull(pair)) {
        return ArrayUtils.addAll(trips, pair);
    } else {
        return null;
    }
}

From source file:org.kitodo.sruimport.ResponseHandler.java

/**
 * Transform given HttpResponse into Document and return it.
 * @param response HttpResponse that is transformed into a Document
 * @return Document into which given HttpResponse has been transformed
 */// w  w w .j av a2s.c o  m
static Document transformResponseToDocument(HttpResponse response) {
    HttpEntity entity = response.getEntity();
    if (Objects.nonNull(entity)) {
        try {
            return parseXML(entity.getContent());
        } catch (IOException e) {
            throw new ConfigException(e.getMessage());
        }
    }
    throw new ConfigException("SRU response is null");
}

From source file:com.mac.holdempoker.app.hands.Quad.java

private Card[] findQuad() {
    Card highest = null;/*from w  w w  .  j a  va  2 s.  c om*/
    Card[] quad = null;
    for (Entry<Rank, Card[]> entry : cards.entrySet()) {
        if (hasFour(entry.getValue())) {
            if (Objects.isNull(quad)) {
                quad = entry.getValue();
            }
        } else if (Objects.isNull(highest)) {
            highest = getSingleCard(entry.getValue());
        }
    }
    if (Objects.nonNull(quad) && Objects.nonNull(highest)) {
        return ArrayUtils.add(quad, highest);
    } else {
        return null;
    }
}

From source file:it.greenvulcano.util.metadata.properties.BeanPropertiesHandler.java

@Override
public String expand(String type, String str, Map<String, Object> inProperties, Object object, Object extra)
        throws PropertiesHandlerException {
    String propName = str;//from  w w  w . j av  a2  s. c om
    if ("this".equals(propName)) {
        if (object instanceof GVBuffer) {
            object = GVBuffer.class.cast(object).getObject();
        }
        return Objects.nonNull(object) ? object.toString() : "";
    }
    if (!PropertiesHandler.isExpanded(propName)) {
        propName = PropertiesHandler.expand(propName, inProperties, object, extra);
    }

    if (object == null) {
        return "#" + PROP_START + str + PROP_END;
    }

    String value = null;
    try {
        value = BeanUtils.getProperty(object, propName);
    } catch (Exception e) {
        value = "#" + PROP_START + str + PROP_END;
    }

    return value;
}

From source file:org.kitodo.production.forms.dataeditor.BooleanMetadataTableRow.java

/**
 * Creates a new meta-data panel row with an on/off switch.
 *
 * @param panel//from   w  w w  .  j a v  a2s . c o  m
 *            MetadataPanel instance
 * @param container
 *            containing meta-data group
 * @param settings
 *            configuration settings from the rule set
 * @param data
 *            data to display
 */
BooleanMetadataTableRow(MetadataPanel panel, FieldedMetadataTableRow container,
        SimpleMetadataViewInterface settings, MetadataEntry data) {

    super(panel, container, settings);
    this.active = Objects.nonNull(data);
    Iterator<Entry<String, String>> selectItems = settings.getSelectItems().entrySet().iterator();
    this.optionLabel = selectItems.hasNext() ? selectItems.next().getValue() : "";
}

From source file:com.fantasy.stataggregator.entities.dao.AbstractRepository.java

protected T findLast() {
    javax.persistence.criteria.CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
    cq.select(cq.from(entityClass));// ww w . j a v  a2s .co  m
    javax.persistence.Query q = em.createQuery(cq);

    List<T> option = Optional.ofNullable(q.setMaxResults(1).getResultList()).orElse(new ArrayList());

    T entity = null;
    if (Objects.nonNull(option.get(0))) {
        entity = option.get(0);
    }
    return entity;
}

From source file:pe.chalk.telegram.type.Update.java

public boolean hasInlineQuery() {
    return Objects.nonNull(this.getInlineQuery());
}

From source file:com.github.yongchristophertang.engine.java.handler.JsonTransformer.java

/**
 * Transform the json result to an instance of T.
 *
 * @param clazz the type class of transformed object
 *///from   w ww  . j a  v  a  2 s  . c o m
public <T> T object(String expression, Class<T> clazz) {
    Objects.nonNull(expression);
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
    try {
        return expression == null ? mapper.readValue(context, clazz)
                : mapper.readValue(JsonPath.compile(expression).read(context).toString(), clazz);
    } catch (Exception e) {
        return clazz.cast(JsonPath.compile(expression).read(context));
    }
}

From source file:com.mac.holdempoker.app.hands.HandEvaluator.java

public AbstractHand evaluateHand() throws IllegalArgumentException, IllegalAccessException, Exception {

    Field[] fields = getClass().getDeclaredFields();
    for (Field field : fields) {
        field.setAccessible(true);/*  w w  w .  j a  va2 s.  c  o m*/
        AbstractHand ah = (AbstractHand) field.get(this);
        Card[] hand = ah.getHand();
        if (Objects.nonNull(hand)) {
            return ah;
        }
        field.setAccessible(false);
    }
    throw new Exception("Invalid hand");
}

From source file:org.apache.streams.cassandra.CassandraClient.java

public void start() throws Exception {

    Objects.nonNull(config);

    LOGGER.info("CassandraClient.start {}", config);

    Cluster.Builder builder = Cluster.builder().withPort(config.getPort().intValue()).withoutJMXReporting()
            .withoutMetrics()//from   ww  w. java 2 s .  c  o m
            .withSocketOptions(new SocketOptions().setConnectTimeoutMillis(DEFAULT_CONNECT_TIMEOUT_MILLIS * 10)
                    .setReadTimeoutMillis(DEFAULT_READ_TIMEOUT_MILLIS * 10));

    if (config.getSsl() != null && config.getSsl().getEnabled() == true) {

        Ssl ssl = config.getSsl();

        KeyStore ks = KeyStore.getInstance("JKS");

        InputStream trustStore = new FileInputStream(ssl.getTrustStore());
        ks.load(trustStore, ssl.getTrustStorePassword().toCharArray());
        InputStream keyStore = new FileInputStream(ssl.getKeyStore());
        ks.load(keyStore, ssl.getKeyStorePassword().toCharArray());

        TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        tmf.init(ks);

        KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmf.init(ks, ssl.getKeyStorePassword().toCharArray());

        SSLContext sslContext = SSLContext.getInstance("SSLv3");
        sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

        SSLOptions sslOptions = JdkSSLOptions.builder().withSSLContext(sslContext).build();

        builder = builder.withSSL(sslOptions);
    }

    Collection<InetSocketAddress> addresses = new ArrayList<>();
    for (String h : config.getHosts()) {
        LOGGER.info("Adding Host: {}", h);
        InetSocketAddress socketAddress = new InetSocketAddress(h, config.getPort().intValue());
        addresses.add(socketAddress);
    }
    builder.addContactPointsWithPorts(addresses);

    if (StringUtils.isNotBlank(config.getUser()) && StringUtils.isNotBlank(config.getPassword())) {
        builder.withCredentials(config.getUser(), config.getPassword());
    }
    cluster = builder.build();

    Objects.nonNull(cluster);

    try {
        Metadata metadata = cluster.getMetadata();
        LOGGER.info("Connected to cluster: {}\n", metadata.getClusterName());
        for (Host host : metadata.getAllHosts()) {
            LOGGER.info("Datacenter: {}; Host: {}; Rack: {}\n", host.getDatacenter(), host.getAddress(),
                    host.getRack());
        }
    } catch (Exception e) {
        LOGGER.error("Exception: {}", e);
        throw e;
    }

    try {
        session = cluster.connect();
    } catch (Exception e) {
        LOGGER.error("Exception: {}", e);
        throw e;
    }

    Objects.nonNull(session);

}