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.qpark.maven.plugin.mockoperation.OperationProviderMockGenerator.java

private boolean hasFailureList(final ComplexType ct) {
    boolean value = ct.getChildren().stream()
            .filter(ctc -> ctc.getChildName().equals("failure") && ctc.isList()).findFirst().isPresent();
    if (!value && Objects.nonNull(ct.getParent())) {
        value = this.hasFailureList(ct.getParent());
    }/* ww  w.j av  a2  s .co  m*/
    return value;
}

From source file:org.keycloak.models.jpa.JpaRealmProvider.java

@Override
public List<GroupModel> getTopLevelGroups(RealmModel realm, Integer first, Integer max) {
    List<String> groupIds = em.createNamedQuery("getTopLevelGroupIds", String.class)
            .setParameter("realm", realm.getId()).setFirstResult(first).setMaxResults(max).getResultList();
    List<GroupModel> list = new ArrayList<>();
    if (Objects.nonNull(groupIds) && !groupIds.isEmpty()) {
        for (String id : groupIds) {
            GroupModel group = getGroupById(id, realm);
            list.add(group);//from   www  . j a v a2  s .co m
        }
    }

    list.sort(Comparator.comparing(GroupModel::getName));

    return Collections.unmodifiableList(list);
}

From source file:com.mac.holdempoker.app.impl.util.HandMatrix.java

private Rank[] getRanksWithCount(int count, int amount) {
    List<Rank> foundRanks = new ArrayList(1);

    Set<Rank> keys = rankHistogram.keySet();
    Rank[] ranks = keys.toArray(new Rank[keys.size()]);
    Arrays.sort(ranks, rc);//  w  w  w  .  j  av a 2  s  .  c  om
    ArrayUtils.reverse(ranks);

    for (Rank r : ranks) {
        Integer val = rankHistogram.get(r);
        if (Objects.nonNull(val)) {
            if (val == count) {
                foundRanks.add(r);
                if (foundRanks.size() == amount) {
                    break;
                }
            }
        }
    }
    return foundRanks.toArray(new Rank[foundRanks.size()]);
}

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

void updatePhysicalNodeSelection(GalleryMediaContent galleryMediaContent) {
    if (this.separateMedia) {
        if (Objects.nonNull(previouslySelectedPhysicalNode)) {
            previouslySelectedPhysicalNode.setSelected(false);
        }/*from  ww  w  .  j  a  v a  2 s .co m*/
        if (Objects.nonNull(selectedPhysicalNode)) {
            selectedPhysicalNode.setSelected(false);
        }
        if (Objects.nonNull(physicalTree)) {
            TreeNode selectedTreeNode = updateNodeSelectionRecursive(galleryMediaContent, physicalTree);
            if (Objects.nonNull(selectedTreeNode)) {
                setSelectedPhysicalNode(selectedTreeNode);
            } else {
                Helper.setErrorMessage("Unable to update Node selection in physical structure!");
            }
        }
    }
}

From source file:org.kitodo.filemanagement.locking.LockManagement.java

/**
 * Removes a permission from memory. If the administration object becomes
 * empty, the administration object is also deleted.
 *
 * @param user//from  www  .j  a  v  a 2 s.c  o  m
 *            User who held the lock
 * @param lock
 *            lock (object)
 * @param uri
 *            locked URI
 */
private void removePermission(String user, AbstractLock lock, URI uri) {
    GrantedPermissions permissions = grantedPermissions.get(uri);
    if (Objects.nonNull(permissions)) {
        permissions.remove(user, lock);
        if (permissions.isEmpty()) {
            grantedPermissions.remove(uri);
        }
    }
}

From source file:it.greenvulcano.gvesb.virtual.gv_multipart.MultipartCallOperation.java

/**
 * //from   w  ww.j a  v a  2s. c  o  m
 * @param gvBuffer 
 *          for transport data in GreenVulcano
 * @return the GVBuffer
 * 
 * @see it.greenvulcano.gvesb.virtual.CallOperation#perform(it.greenvulcano.gvesb.buffer.GVBuffer)
 */
@Override
public GVBuffer perform(GVBuffer gvBuffer) throws ConnectionException, CallException, InvalidDataException {

    StringBuffer callDump = new StringBuffer();
    callDump.append("Performing RestCallOperation " + name).append("\n        ").append("URL: ").append(url);

    if (isByteArray == true && gvBuffer.getObject() != null) {
        byte[] requestData;
        if (gvBuffer.getObject() instanceof byte[]) {
            requestData = (byte[]) gvBuffer.getObject();
        } else {
            requestData = gvBuffer.getObject().toString().getBytes();
        }
        callDump.append("\n        ").append("Content-Length: " + requestData.length);
        ByteArrayBody byteArrayPart = new ByteArrayBody(requestData, contentType, fileName);
        multipartEntityBuilder.addPart(name, byteArrayPart);
    }

    else if (isFileProperty == true) {
        file = new File(gvBuffer.getProperty("DIR"));
        FileBody filePart = new FileBody(file, this.contentType, fileName);
        multipartEntityBuilder.addPart(filePartName, filePart);
    }

    try {
        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpPost httpPost = new HttpPost(url);
        httpEntity = multipartEntityBuilder.build();
        String responseString = EntityUtils.toString(httpEntity);
        httpPost.setEntity(multipartEntityBuilder.build());
        for (Map.Entry<String, String> header : headers.entrySet()) {
            String key = header.getKey();
            String value = header.getValue();
            httpPost.setHeader(key, value);
        }
        CloseableHttpResponse response = httpClient.execute(httpPost);
        HttpEntity responseEntity = response.getEntity();
        Header[] responseHeaders = response.getAllHeaders();

        Header contentType = responseEntity.getContentType();

        InputStream responseStream = null;

        response.getStatusLine();
        responseStream = responseEntity.getContent();

        for (Header header : response.getAllHeaders()) {
            if (Objects.nonNull(header)) {
                gvBuffer.setProperty(header.getName(), header.getValue());
            }
        }

        if (responseStream != null) {

            byte[] responseData = IOUtils.toByteArray(responseStream);
            String responseContentType = Optional
                    .ofNullable(gvBuffer.getProperty(RESPONSE_HEADER_PREFIX.concat("CONTENT-TYPE"))).orElse("");

            if (responseContentType.startsWith("application/json")
                    || responseContentType.startsWith("application/javascript")) {
                gvBuffer.setObject(new String(responseData, "UTF-8"));
            } else {
                gvBuffer.setObject(responseData);
            }

        } else {
            gvBuffer.setObject(null);
        }

        gvBuffer.setProperty(RESPONSE_STATUS, String.valueOf(response.getStatusLine()));
        gvBuffer.setProperty(RESPONSE_MESSAGE, String.valueOf(response));

        callDump.append("\n " + gvBuffer);

        response.close();

        logger.debug(callDump.toString());
    } catch (Exception exc) {
        throw new CallException("GV_CALL_SERVICE_ERROR",
                new String[][] { { "service", gvBuffer.getService() }, { "system", gvBuffer.getSystem() },
                        { "tid", gvBuffer.getId().toString() }, { "message", exc.getMessage() } },
                exc);
    }
    return gvBuffer;
}

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

/**
 * Creates a DataCopier with the given configuration, lets it process the
 * given data and wraps any errors to display in the front end.
 *
 * @param data//from w  w  w  .jav  a 2 s .c  om
 *            data to process
 */
private void applyCopyingRules(CopierData data) {
    String rules = ConfigCore.getParameter(ParameterCore.COPY_DATA_ON_CATALOGUE_QUERY);
    if (Objects.nonNull(rules)) {
        try {
            new DataCopier(rules).process(data);
        } catch (ConfigurationException e) {
            Helper.setErrorMessage("dataCopier.syntaxError", logger, e);
        }
    }
}

From source file:org.goobi.production.cli.helper.CopyProcess.java

private String calcProcessTitleCheck(String fieldName, String fieldValue) {
    String result = fieldValue;//www . j  av a  2s  .  com

    if (fieldName.equals("Bandnummer")) {
        try {
            int bandInt = Integer.parseInt(fieldValue);
            java.text.DecimalFormat df = new java.text.DecimalFormat("#0000");
            result = df.format(bandInt);
        } catch (NumberFormatException e) {
            Helper.setErrorMessage(INCOMPLETE_DATA, "Bandnummer ist keine gltige Zahl", logger, e);
        }
        if (Objects.nonNull(result) && result.length() < 4) {
            result = "0000".substring(result.length()) + result;
        }
    }
    return result;
}

From source file:org.kitodo.production.helper.tasks.EmptyTask.java

/**
 * The procedure setNameDetail() may be used to set the tasks name along
 * with a detail that doesnt require translation and is helpful when being
 * shown in the front end (such as the name of the entity the task is based
 * on). The name detail should be set once (in the constructor). You may
 * pass in null to reset the name and remove the detail.
 *
 * <p>//from   w  w  w.  ja v a2  s.  c  o m
 * I.e., if your task is about creation of OCR for a process, the detail
 * here could be the process title.
 * </p>
 *
 * @param detail
 *            a name detail, may be null
 */
protected void setNameDetail(String detail) {
    StringBuilder composer = new StringBuilder(119);
    composer.append(this.getDisplayName());
    if (Objects.nonNull(detail)) {
        composer.append(": ");
        composer.append(detail);
    }
    super.setName(composer.toString());
}

From source file:org.kitodo.export.ExportDms.java

private void exportWithTimeLimit(Process process) throws IOException {
    DmsImportThread asyncThread = new DmsImportThread(process, atsPpnBand);
    asyncThread.start();/*from ww w . j  a v a 2  s .  c o m*/
    String processTitle = process.getTitle();

    try {
        // wait 30 seconds for the thread, possibly kill
        asyncThread.join(process.getProject().getDmsImportTimeOut().longValue());
        if (asyncThread.isAlive()) {
            asyncThread.stopThread();
        }
    } catch (InterruptedException e) {
        if (Objects.nonNull(exportDmsTask)) {
            exportDmsTask.setException(e);
            logger.error(Helper.getTranslation(ERROR_EXPORT, Collections.singletonList(processTitle)));
        } else {
            Thread.currentThread().interrupt();
            Helper.setErrorMessage(ERROR_EXPORT, new Object[] { processTitle }, logger, e);
        }
    }

    String result = asyncThread.getResult();
    if (!result.isEmpty()) {
        if (Objects.nonNull(exportDmsTask)) {
            exportDmsTask.setException(new RuntimeException(processTitle + ": " + result));
        } else {
            Helper.setErrorMessage(processTitle + ": ", result);
        }
    } else {
        if (Objects.nonNull(exportDmsTask)) {
            exportDmsTask.setProgress(100);
        } else {
            Helper.setMessage(process.getTitle() + ": ", "exportFinished");
        }
        // delete success folder again
        if (process.getProject().isDmsImportCreateProcessFolder()) {
            URI successFolder = URI.create(process.getProject().getDmsImportSuccessPath() + "/"
                    + Helper.getNormalizedTitle(processTitle));
            fileService.delete(successFolder);
        }
    }
}