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.services.file.FileService.java

/**
 * Lists all Files at the given Path.//www.ja v  a 2  s.c  om
 *
 * @param file
 *            the directory to get the Files from
 * @return an Array of Files.
 */
private File[] listFiles(File file) {
    File[] unchecked = file.listFiles();
    return Objects.nonNull(unchecked) ? unchecked : new File[0];
}

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

/**
 * Run through all metadata and children of given docstruct to trim the strings
 * calls itself recursively./*  w  w  w . j a  v a 2  s.c  o  m*/
 */
private void trimAllMetadata(LegacyDocStructHelperInterface inStruct) {
    // trim all metadata values
    if (Objects.nonNull(inStruct.getAllMetadata())) {
        for (LegacyMetadataHelper md : inStruct.getAllMetadata()) {
            if (Objects.nonNull(md.getValue())) {
                md.setStringValue(md.getValue().trim());
            }
        }
    }

    // run through all children of docstruct
    if (Objects.nonNull(inStruct.getAllChildren())) {
        for (LegacyDocStructHelperInterface child : inStruct.getAllChildren()) {
            trimAllMetadata(child);
        }
    }
}

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

/**
 * The method addToBatches() adds a given process to the allover and the
 * annual batch. If the break mark changes, the logistics batch will be
 * flushed and the process will be added to a new logistics batch.
 *
 * @param process/*  ww  w  . j ava2 s . co  m*/
 *            process to add
 * @param issues
 *            list of individual issues in the process
 * @param processTitle
 *            the title of the process
 */
private void addToBatches(Process process, List<IndividualIssue> issues, String processTitle)
        throws DataException {
    if (Objects.nonNull(createBatches)) {
        int lastIndex = issues.size() - 1;
        int breakMark = issues.get(lastIndex).getBreakMark(createBatches);
        if (Objects.nonNull(currentBreakMark) && breakMark != currentBreakMark) {
            flushLogisticsBatch(processTitle);
        }
        if (Objects.isNull(batchLabel)) {
            batchLabel = createBatches.format(issues.get(lastIndex).getDate());
        }
        logisticsBatch.getProcesses().add(process);
        currentBreakMark = breakMark;
    }
    fullBatch.getProcesses().add(process);
}

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

/**
 * Set current plugin.//from  w w  w. j  av  a 2 s .c  o  m
 *
 * @param currentPlugin
 *            the currentPlugin to set
 */
public void setCurrentPlugin(String currentPlugin) {
    this.currentPlugin = currentPlugin;
    if (Objects.nonNull(this.currentPlugin) && !this.currentPlugin.isEmpty()) {
        this.plugin = (IImportPlugin) PluginLoader.getPluginByTitle(PluginType.IMPORT, this.currentPlugin);

        if (Objects.nonNull(this.plugin)) {
            if (this.plugin.getImportTypes().contains(ImportType.FOLDER)) {
                this.allFilenames = this.plugin.getAllFilenames();
            }
            this.plugin.setPrefs(ServiceManager.getRulesetService().getPreferences(template.getRuleset()));
        }
    }
}

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

public double[] getInterpolateRayleighThickness(double... taur) {
    if (Objects.nonNull(taur)) {
        double[] val = new double[taur.length];
        for (int i = 0; i < taur.length; i++) {
            val[i] = linearInterpolate.value(taur[i]);
        }//from   w  w  w  .j a  va2 s . com
        return val;
    }
    throw new NullPointerException("The linearInterpolate Rayleigh thickness is empty.");
}

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

private TreeNode updateNodeSelectionRecursive(GalleryMediaContent galleryMediaContent, TreeNode treeNode) {
    TreeNode matchingTreeNode = null;
    for (TreeNode currentTreeNode : treeNode.getChildren()) {
        if (currentTreeNode.getChildCount() < 1
                && treeNodeMatchesGalleryMediaContent(galleryMediaContent, currentTreeNode)) {
            currentTreeNode.setSelected(true);
            matchingTreeNode = currentTreeNode;
        } else {/*from  w  w w  .  jav  a  2  s.  co  m*/
            currentTreeNode.setSelected(false);
            matchingTreeNode = updateNodeSelectionRecursive(galleryMediaContent, currentTreeNode);
        }
        if (Objects.nonNull(matchingTreeNode)) {
            break;
        }
    }
    return matchingTreeNode;
}

From source file:org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationNovaServerImpl.java

private void getOrTranslatePortTemplate(String heatFileName,
        HeatOrchestrationTemplate heatOrchestrationTemplate, Object port, ServiceTemplate serviceTemplate,
        String novaServerResourceId, TranslationContext context, NodeTemplate novaNodeTemplate) {
    Optional<AttachedResourceId> attachedPortId = HeatToToscaUtil.extractAttachedResourceId(heatFileName,
            heatOrchestrationTemplate, context, port);

    if (!attachedPortId.isPresent()) {
        return;/*from   ww  w .  j av a2 s. c  o  m*/
    }

    if (attachedPortId.get().isGetResource()) {
        String resourceId = (String) attachedPortId.get().getEntityId();
        Resource portResource = HeatToToscaUtil.getResource(heatOrchestrationTemplate, resourceId,
                heatFileName);
        if (!Arrays.asList(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
                HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource())
                .contains(portResource.getType())) {
            logger.warn("NovaServer connect to port resource with id : " + resourceId + " and type : "
                    + portResource.getType()
                    + ". This resource type is not supported, therefore the connection to the port is "
                    + "ignored. " + "Supported types are: "
                    + HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource() + ", "
                    + HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource());
            return;
        } else if (HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource()
                .equals(portResource.getType())) {
            Map<String, Object> properties = portResource.getProperties();
            if (!MapUtils.isEmpty(properties) && Objects.nonNull(properties.get("port_tuple_refs"))) {
                novaNodeTemplate.getProperties().put("contrail_service_instance_ind", true);
            }
        }
        Optional<String> translatedPortId = ResourceTranslationFactory.getInstance(portResource)
                .translateResource(heatFileName, serviceTemplate, heatOrchestrationTemplate, portResource,
                        resourceId, context);
        if (translatedPortId.isPresent()) {
            NodeTemplate portNodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate,
                    translatedPortId.get());
            addBindingReqFromPortToCompute(novaServerResourceId, portNodeTemplate);
        } else {
            logger.warn("NovaServer connect to port resource with id : " + resourceId + " and type : "
                    + portResource.getType()
                    + ". This resource type is not supported, therefore the connection to the port is "
                    + "ignored.");
        }
    }
}

From source file:org.kitodo.production.services.data.TaskService.java

/**
 * Execute all scripts for step./*from ww  w.j a v  a 2 s .c  o  m*/
 *
 * @param task
 *            StepObject
 * @param automatic
 *            boolean
 */
public void executeScript(Task task, boolean automatic) throws DataException {
    String script = task.getScriptPath();
    boolean scriptFinishedSuccessful = true;
    logger.debug("starting script {}", script);
    if (Objects.nonNull(script) && !script.trim().isEmpty()) {
        scriptFinishedSuccessful = executeScript(task, script, automatic);
    }
    if (!scriptFinishedSuccessful) {
        abortTask(task);
    }
}

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

public double[] getSquarePower(double[] sinOZARads) {
    if (Objects.nonNull(sinOZARads)) {
        return Arrays.stream(sinOZARads).map(p -> Math.pow(p, 2)).toArray();
    }//from  w w w.j  a v a2  s .  c  o  m
    throw new NullPointerException("The array is null.");
}

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

private boolean treeNodeMatchesGalleryMediaContent(GalleryMediaContent galleryMediaContent, TreeNode treeNode) {
    if (treeNode.getData() instanceof StructureTreeNode) {
        StructureTreeNode structureTreeNode = (StructureTreeNode) treeNode.getData();
        MediaUnit mediaUnit = null;/*from  w  w  w .jav  a 2 s  .  com*/
        if (structureTreeNode.getDataObject() instanceof MediaUnit) {
            mediaUnit = (MediaUnit) structureTreeNode.getDataObject();
        } else if (structureTreeNode.getDataObject() instanceof View) {
            View view = (View) structureTreeNode.getDataObject();
            mediaUnit = view.getMediaUnit();
        }
        if (Objects.nonNull(mediaUnit) && mediaUnit.getMediaFiles().size() > 0) {
            Map<MediaVariant, URI> mediaVariants = mediaUnit.getMediaFiles();
            return mediaVariants.values().contains(galleryMediaContent.getPreviewUri());
        }
    }
    return false;
}