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.kitodo.production.forms.IndexingForm.java

/**
 * Return the number of objects in the database for the given ObjectType.
 *
 * @param objectType//from   w  ww  . j ava2s .c  o m
 *            name of ObjectType for which the number of database objects is
 *            returned
 * @return number of database objects
 */
private int getNumberOfDatabaseObjects(ObjectType objectType) {
    try {
        SearchService searchService = searchServices.get(objectType);
        if (Objects.nonNull(searchService)) {
            return toIntExact(searchService.countDatabaseRows());
        }
    } catch (DAOException e) {
        Helper.setErrorMessage(e.getLocalizedMessage(), logger, e);
    }
    return 0;
}

From source file:org.kitodo.production.metadata.MetadataProcessor.java

private void cleanupMetadata() {
    // before save remove all unused docstructs
    this.metaHelper.deleteAllUnusedElements(this.digitalDocument.getLogicalDocStruct());

    if (currentRepresentativePage != null && currentRepresentativePage.length() > 0) {
        boolean match = false;
        LegacyDocStructHelperInterface physicalDocStruct = this.digitalDocument.getPhysicalDocStruct();
        if (Objects.nonNull(physicalDocStruct) && Objects.nonNull(physicalDocStruct.getAllMetadata())) {
            for (LegacyMetadataHelper md : this.digitalDocument.getPhysicalDocStruct().getAllMetadata()) {
                if (md.getMetadataType().getName().equals("_representative")) {
                    Integer value = Integer.valueOf(currentRepresentativePage);
                    md.setStringValue(String.valueOf(value + 1));
                    match = true;//from w ww  .j  a  v  a 2  s .  c om
                }
            }
        }
        if (!match) {
            LegacyMetadataTypeHelper mdt = myPrefs.getMetadataTypeByName("_representative");
            addMetadataToPhysicalDocStruct(mdt);
        }
    }
}

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

/**
 * Get document structure.//  w w w.j  a v a 2  s.co  m
 *
 * @return list of DocstructElement objects
 */
public List<? extends DocstructElement> getDocstructs() {
    java.lang.reflect.Method method;
    try {
        method = this.plugin.getClass().getMethod(GET_CURRENT_DOC_STRUCTS);
        Object o = method.invoke(this.plugin);
        @SuppressWarnings("unchecked")
        List<? extends DocstructElement> list = (List<? extends DocstructElement>) o;
        if (Objects.nonNull(list)) {
            return list;
        }
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | RuntimeException e) {
        Helper.setErrorMessage(e.getLocalizedMessage(), logger, e);
    }
    return new ArrayList<>();
}

From source file:org.openecomp.sdc.validation.impl.validators.EcompGuideLineValidator.java

@SuppressWarnings("unchecked")
private void checkNeutronPortFixedIpsName(String fileName, Map.Entry<String, Resource> resourceEntry,
        GlobalValidationContext globalContext) {
    String[] regexList = new String[] { "[^_]+_[^_]+_ips", "[^_]+_[^_]+_v6_ips", "[^_]+_[^_]+_ip_(\\d+)",
            "[^_]+_[^_]+_v6_ip_(\\d+)" };

    if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
        return;// w ww  . j  a  va  2 s.c  o  m
    }

    Map<String, Object> propertiesMap = resourceEntry.getValue().getProperties();
    Object fixedIps = propertiesMap.get("fixed_ips");
    if (Objects.nonNull(fixedIps) && fixedIps instanceof List) {
        List<Object> fixedIpsList = (List<Object>) fixedIps;
        for (Object fixedIpsObject : fixedIpsList) {
            Map.Entry<String, Object> fixedIpsEntry = ((Map<String, Object>) fixedIpsObject).entrySet()
                    .iterator().next();
            if (Objects.nonNull(fixedIpsEntry)) {
                if (fixedIpsEntry.getValue() instanceof Map) {
                    String fixedIpsName = getWantedNameFromPropertyValueGetParam(fixedIpsEntry.getValue());
                    if (Objects.nonNull(fixedIpsName)) {
                        if (!evalPattern(fixedIpsName, regexList)) {
                            globalContext.addMessage(fileName, ErrorLevel.WARNING,
                                    ErrorMessagesFormatBuilder.getErrorWithParameters(
                                            Messages.FIXED_IPS_NOT_ALIGNED_WITH_GUIDE_LINES.getErrorMessage(),
                                            resourceEntry.getKey()));
                        }
                    }
                } else {
                    globalContext.addMessage(fileName, ErrorLevel.WARNING,
                            ErrorMessagesFormatBuilder.getErrorWithParameters(
                                    Messages.MISSING_GET_PARAM.getErrorMessage(), "fixed_ips",
                                    resourceEntry.getKey()));
                }
            }
        }
    }
}

From source file:org.esa.s3tbx.olci.radiometry.rayleigh.RayleighAux.java

void setInterpolation() {
    BicubicSplineInterpolator gridInterpolator = new BicubicSplineInterpolator();
    Map<Integer, List<double[]>> interpolate = new HashMap<>();
    double[] sunZenithAngles = getSunZenithAngles();
    double[] viewZenithAngles = getViewZenithAngles();

    //todo mba ask Mp if to use this approach.
    assert sunZenithAngles != null;

    if (Objects.nonNull(sunZenithAngles) && Objects.nonNull(viewZenithAngles)) {
        for (int index = 0; index < sunZenithAngles.length; index++) {
            double yVal = viewZenithAngles[index];
            double xVal = sunZenithAngles[index];

            List<double[]> valueList = new ArrayList<>();
            for (int i = 0; i < rayCooefMatrixA.length; i++) {
                double thetaMin = thetas[0];
                double thetaMax = thetas[thetas.length - 1];

                if (yVal > thetaMin && yVal < thetaMax) {
                    double[] values = new double[4];
                    values[0] = gridInterpolator.interpolate(thetas, thetas, rayCooefMatrixA[i]).value(xVal,
                            yVal);//from  www .  j a  v a 2s  .  c  om
                    values[1] = gridInterpolator.interpolate(thetas, thetas, rayCooefMatrixB[i]).value(xVal,
                            yVal);
                    values[2] = gridInterpolator.interpolate(thetas, thetas, rayCooefMatrixC[i]).value(xVal,
                            yVal);
                    values[3] = gridInterpolator.interpolate(thetas, thetas, rayCooefMatrixD[i]).value(xVal,
                            yVal);
                    valueList.add(values);
                } else {
                    valueList.add(new double[] { 0, 0, 0, 0 });
                }
            }
            interpolate.put(index, valueList);
        }
        interpolateMap = interpolate;
    }
}

From source file:org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupManager.java

private DrawableGroup popuplateIfAnalyzed(GroupKey<?> groupKey, ReGroupTask<?> task) {

    if (Objects.nonNull(task) && (task.isCancelled())) {
        /*/*from   ww  w  . j  av a 2  s  .  c o  m*/
         * if this method call is part of a ReGroupTask and that task is
         * cancelled, no-op
         *
         * this allows us to stop if a regroup task has been cancelled (e.g.
         * the user picked a different group by attribute, while the current
         * task was still running)
         */

    } else { // no task or un-cancelled task
        if ((groupKey.getAttribute() != DrawableAttribute.PATH) || db.isGroupAnalyzed(groupKey)) {
            /*
             * for attributes other than path we can't be sure a group is
             * fully analyzed because we don't know all the files that will
             * be a part of that group,. just show them no matter what.
             */

            try {
                Set<Long> fileIDs = getFileIDsInGroup(groupKey);
                if (Objects.nonNull(fileIDs)) {
                    DrawableGroup group;
                    final boolean groupSeen = db.isGroupSeen(groupKey);
                    synchronized (groupMap) {
                        if (groupMap.containsKey(groupKey)) {
                            group = groupMap.get(groupKey);

                            group.setFiles(ObjectUtils.defaultIfNull(fileIDs, Collections.emptySet()));
                        } else {
                            group = new DrawableGroup(groupKey, fileIDs, groupSeen);
                            controller.getCategoryManager().registerListener(group);
                            group.seenProperty().addListener((o, oldSeen, newSeen) -> {
                                Platform.runLater(() -> markGroupSeen(group, newSeen));
                            });
                            groupMap.put(groupKey, group);
                        }
                    }
                    Platform.runLater(() -> {
                        if (analyzedGroups.contains(group) == false) {
                            analyzedGroups.add(group);
                            if (Objects.isNull(task)) {
                                FXCollections.sort(analyzedGroups, applySortOrder(sortOrder, sortBy));
                            }
                        }
                        markGroupSeen(group, groupSeen);
                    });
                    return group;
                }
            } catch (TskCoreException ex) {
                LOGGER.log(
                        Level.SEVERE, "failed to get files for group: "
                                + groupKey.getAttribute().attrName.toString() + " = " + groupKey.getValue(),
                        ex); //NON-NLS
            }
        }
    }
    return null;
}

From source file:org.kitodo.production.services.file.FileService.java

/**
 * This method is needed for migration purposes. It maps existing filePaths
 * to the correct URI. File.separator doesn't work because on Windows it
 * appends backslash to URI./*from   ww  w .jav a  2s  . c om*/
 *
 * @param process
 *            the process, the uri is needed for.
 * @return the URI.
 */
public URI getProcessBaseUriForExistingProcess(Process process) {
    URI processBaseUri = process.getProcessBaseUri();
    if (Objects.isNull(processBaseUri) && Objects.nonNull(process.getId())) {
        process.setProcessBaseUri(fileManagementModule.createUriForExistingProcess(process.getId().toString()));
    }
    return process.getProcessBaseUri();
}

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

/**
 * Except for the authors, take all additional into the metadata.
 *///www  . j  av  a  2  s  . c o m
private void processAdditionalFieldWhichMetadata(AdditionalField field,
        LegacyDocStructHelperInterface tempStruct, LegacyDocStructHelperInterface tempChild) {

    if (!field.getMetadata().equals(LIST_OF_CREATORS)) {
        LegacyPrefsHelper prefs = ServiceManager.getRulesetService()
                .getPreferences(this.prozessKopie.getRuleset());
        LegacyMetadataTypeHelper mdt = LegacyPrefsHelper.getMetadataType(prefs, field.getMetadata());
        LegacyMetadataHelper metadata = LegacyLogicalDocStructHelper.getMetadata(tempStruct, mdt);
        if (Objects.nonNull(metadata)) {
            metadata.setStringValue(field.getValue());
        }
        // if the topstruct and the first child should be given the
        // value
        if (Objects.nonNull(tempChild)) {
            metadata = LegacyLogicalDocStructHelper.getMetadata(tempChild, mdt);
            if (Objects.nonNull(metadata)) {
                metadata.setStringValue(field.getValue());
            }
        }
    }
}

From source file:com.qpark.eip.core.model.analysis.AnalysisDao.java

/**
 * Get the {@link ServiceType} with serviceId of the modelVersion.
 *
 * @param modelVersion//from   w ww.  j av a2  s .  c om
 *            the model version.
 * @param serviceId
 *            the serviceId.
 * @return the {@link ServiceType} with serviceId of the modelVersion.
 * @since 3.5.1
 */
@Transactional(value = EipModelAnalysisPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED)
public ServiceType getServiceByServiceId(final String modelVersion, final String serviceId) {
    ServiceType value = null;
    final CriteriaBuilder cb = this.em.getCriteriaBuilder();
    final CriteriaQuery<ServiceType> q = cb.createQuery(ServiceType.class);
    final Root<ServiceType> f = q.from(ServiceType.class);
    q.where(cb.equal(f.<String>get(ServiceType_.modelVersion), modelVersion),
            cb.equal(f.<String>get(ServiceType_.serviceId), serviceId));
    final TypedQuery<ServiceType> typedQuery = this.em.createQuery(q);
    final List<ServiceType> list = typedQuery.getResultList();
    if (Objects.nonNull(list) && list.size() == 1) {
        value = list.get(0);
        EagerLoader.load(value);
    }
    return value;
}

From source file:org.openecomp.sdc.validation.impl.validators.EcompGuideLineValidator.java

private void checkIfNovaNameByGuidelines(String fileName, String envFileName,
        Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext) {
    if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
        return;// www . j a v a 2s . c  om
    }

    Object novaServerName = resourceEntry.getValue().getProperties().get("name");
    Map novaNameMap;
    String novaName;
    if (Objects.nonNull(novaServerName)) {
        if (novaServerName instanceof Map) {
            novaNameMap = (Map) novaServerName;
            Object novaNameGetParam = novaNameMap
                    .get(ResourceReferenceFunctions.GET_PARAM.getFunction()) == null ? null
                            : novaNameMap.get(ResourceReferenceFunctions.GET_PARAM.getFunction());
            if (Objects.nonNull(novaNameGetParam)) {
                checkNovaNameGetParamValueMap(fileName, novaNameGetParam, resourceEntry, globalContext);
                novaName = novaNameGetParam instanceof List ? (String) ((List) novaNameGetParam).get(0)
                        : (String) novaNameGetParam;
                checkIfNovaNameParameterInEnvIsStringOrList(fileName, envFileName, resourceEntry, novaName,
                        globalContext);
            }
        } else {
            globalContext.addMessage(fileName, ErrorLevel.WARNING,
                    ErrorMessagesFormatBuilder.getErrorWithParameters(
                            Messages.MISSING_GET_PARAM.getErrorMessage(), "nova server name",
                            resourceEntry.getKey()));
        }
    }

}