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:org.jnosql.diana.orientdb.document.DefaultOrientDBDocumentCollectionManager.java

@Override
public DocumentEntity insert(DocumentEntity entity) throws NullPointerException {
    requireNonNull(entity, "Entity is required");
    try (ODatabaseDocumentTx tx = pool.acquire()) {
        ODocument document = new ODocument(entity.getName());

        Map<String, Object> entityValues = toMap(entity);
        entityValues.keySet().stream().forEach(k -> document.field(k, entityValues.get(k)));
        ODocument save = null;/*from w  w  w  .  jav  a  2 s . c o m*/
        try {
            save = tx.save(document);
        } catch (ONeedRetryException e) {
            save = tx.reload(document);
        }
        if (Objects.nonNull(save)) {
            ORecordId ridField = save.field("@rid");
            if (Objects.nonNull(ridField)) {
                entity.add(Document.of(RID_FIELD, ridField.toString()));
            }
        }

        return entity;
    }
}

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

private boolean hasTwo(Card[] all) {
    int index = 0;
    for (Card c : all) {
        if (Objects.nonNull(c)) {
            index++;/* w  w  w  .j a v  a 2  s. c o m*/
            if (index == 2) {
                return true;
            }
        }
    }
    return false;
}

From source file:io.redlink.solrlib.standalone.SolrServerConnector.java

@Override
@SuppressWarnings("squid:S3776")
protected void init(ExecutorService executorService) throws IOException, SolrServerException {
    Preconditions.checkState(initialized.compareAndSet(false, true));
    Preconditions.checkArgument(Objects.nonNull(solrBaseUrl));

    if (configuration.isDeployCores() && Objects.nonNull(configuration.getSolrHome())) {
        final Path solrHome = configuration.getSolrHome();
        Files.createDirectories(solrHome);
        final Path libDir = solrHome.resolve("lib");
        Files.createDirectories(libDir);

        try (HttpSolrClient solrClient = new HttpSolrClient.Builder(solrBaseUrl).build()) {
            for (SolrCoreDescriptor coreDescriptor : coreDescriptors) {
                final String coreName = coreDescriptor.getCoreName();
                if (availableCores.containsKey(coreName)) {
                    log.warn("CoreName-Clash: {} already initialized. Skipping {}", coreName,
                            coreDescriptor.getClass());
                    continue;
                }/*  w  w  w. ja v a  2 s  .  c om*/
                final String remoteName = createRemoteName(coreName);

                final Path coreHome = solrHome.resolve(remoteName);
                coreDescriptor.initCoreDirectory(coreHome, libDir);

                final Path corePropertiesFile = coreHome.resolve("core.properties");
                // core.properties is created by the CreateCore-Command.
                Files.deleteIfExists(corePropertiesFile);

                if (coreDescriptor.getNumShards() > 1 || coreDescriptor.getReplicationFactor() > 1) {
                    log.warn("Deploying {} to SolrServerConnector, ignoring config of shards={},replication={}",
                            coreName, coreDescriptor.getNumShards(), coreDescriptor.getReplicationFactor());
                }

                // Create or reload the core
                if (CoreAdminRequest.getStatus(remoteName, solrClient).getStartTime(remoteName) == null) {
                    final CoreAdminResponse adminResponse = CoreAdminRequest.createCore(remoteName,
                            coreHome.toAbsolutePath().toString(), solrClient);
                } else {
                    final CoreAdminResponse adminResponse = CoreAdminRequest.reloadCore(remoteName, solrClient);
                }
                // schedule client-side core init
                final boolean isNewCore = findInNamedList(
                        CoreAdminRequest.getStatus(remoteName, solrClient).getCoreStatus(remoteName), "index",
                        "lastModified") == null;
                scheduleCoreInit(executorService, coreDescriptor, isNewCore);

                availableCores.put(coreName, coreDescriptor);
            }
        }
    } else {
        try (HttpSolrClient solrClient = new HttpSolrClient.Builder(solrBaseUrl).build()) {
            for (SolrCoreDescriptor coreDescriptor : coreDescriptors) {
                final String coreName = coreDescriptor.getCoreName();
                if (availableCores.containsKey(coreName)) {
                    log.warn("CoreName-Clash: {} already initialized. Skipping {}", coreName,
                            coreDescriptor.getClass());
                    continue;
                }
                final String remoteName = createRemoteName(coreName);
                if (CoreAdminRequest.getStatus(remoteName, solrClient).getStartTime(remoteName) == null) {
                    // Core does not exists
                    log.warn("Collection {} (remote: {}) not available in Solr '{}' "
                            + "but deployCores is set to false", coreName, remoteName, solrBaseUrl);
                } else {
                    log.debug("Collection {} exists in Solr '{}' as {}", coreName, solrBaseUrl, remoteName);
                    scheduleCoreInit(executorService, coreDescriptor, false);
                    availableCores.put(coreName, coreDescriptor);
                }
            }
        }
    }
}

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

public AbstractHand evaluateHand(Card... cards)
        throws IllegalArgumentException, IllegalAccessException, Exception {
    //        Card[] cards = ArrayUtils.addAll(p.getHoleCards(), b.getBoard());

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

From source file:pe.chalk.telegram.type.message.Message.java

public boolean hasFrom() {
    return Objects.nonNull(this.getFrom());
}

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

private static int extractNumberOfRecords(Document document) {
    NodeList numberOfRecordNodes = document.getElementsByTagNameNS(SRW_NAMESPACE, SRW_NUMBER_OF_RECORDS_TAG);
    assert numberOfRecordNodes.getLength() == 1;
    Element numberOfRecordsElement = (Element) numberOfRecordNodes.item(0);
    if (Objects.nonNull(numberOfRecordsElement)) {
        return Integer.parseInt(numberOfRecordsElement.getTextContent().trim());
    }//from w  w w. j a  v  a2s . c o  m
    return 0;
}

From source file:org.opentestsystem.ap.ivs.service.ValidationUtility.java

public Path mapItemToValidationStructure(final ItemContext itemContext, final Path validationRootChild) {
    return Objects.nonNull(itemContext)
            ? mapToValidationStructure(itemContext, validationRootChild.resolve(ITEMS_DIR),
                    mapItemFolderName(itemContext.getItemId()))
            : null;//from   ww  w . jav a  2  s . c o m
}

From source file:com.amanmehara.programming.android.activities.DetailActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    sharedPreferences = getSharedPreferences("Programming", MODE_PRIVATE);

    setContentView(R.layout.activity_detail);
    setActionBar(R.id.toolbar, true);/*ww w. j  a v a 2 s .c  o  m*/
    recyclerView = setRecyclerView(R.id.files_recycler_view);

    bundle = getIntent().getExtras();
    accessToken = bundle.getString("accessToken");
    languageName = bundle.getString("languageName");
    logoBlob = bundle.getByteArray("logoBlob");
    programJson = bundle.getString("program");
    programsJson = bundle.getString("programs");

    try {
        if (isConnected()) {
            JSONObject program = new JSONObject(programJson);
            setProgramName(R.id.program_name, program);
            String url = program.getString("url");
            String response = sharedPreferences.getString(url, null);
            if (Objects.nonNull(response)) {
                getProgramResponseCallback(url, true).accept(response);
            } else {
                new GithubAPIClient(this, getProgramResponseCallback(url, false)).execute(withAccessToken(url));

            }
        } else {
            setAdapter();
            Map<String, Serializable> extrasMap = new HashMap<>();
            extrasMap.put("enumeration.Activity", Activity.DETAIL);
            extrasMap.put("languageName", languageName);
            extrasMap.put("programs", programsJson);
            extrasMap.put("program", programJson);
            extrasMap.put("logoBlob", logoBlob);
            startActivity(ConnectionActivity.class, extrasMap);
        }
    } catch (JSONException e) {
        Log.e(TAG, e.getMessage());
    }

}

From source file:org.kitodo.production.forms.LanguageForm.java

/**
 * Set session locale field id.//from   w  w w  .  ja v a  2s  . c o  m
 *
 *
 */
private void setSessionLocaleFieldId() {
    String key = "";
    if (Objects.isNull(ServiceManager.getUserService().getAuthenticatedUser())) {
        key = ConfigCore.getParameterOrDefaultValue(ParameterCore.LANGUAGE_DEFAULT);
    } else {
        try {
            User user = ServiceManager.getUserService()
                    .getById(ServiceManager.getUserService().getAuthenticatedUser().getId());
            key = user.getLanguage();
        } catch (DAOException e) {
            Helper.setErrorMessage("Error in retrieving user ", logger, e);
        }
    }
    Locale locale = new Locale.Builder().setLanguageTag(key).build();
    if (LocaleUtils.isAvailableLocale(locale)) {
        FacesContext context = FacesContext.getCurrentInstance();
        if (Objects.nonNull(context.getViewRoot())) {
            context.getViewRoot().setLocale(locale);
            context.getExternalContext().getSessionMap().put(SESSION_LOCALE_FIELD_ID, locale);
        }
    }
}

From source file:com.mac.holdempoker.socket.SocketManager.java

private boolean isValidObject(Object obj) {
    return Objects.nonNull(obj);
}