Example usage for java.util Objects isNull

List of usage examples for java.util Objects isNull

Introduction

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

Prototype

public static boolean isNull(Object obj) 

Source Link

Document

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

Usage

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

/**
 * Find processes by property.//from   w w w .  j a  v  a  2  s .co  m
 *
 * @param title
 *            of property
 * @param value
 *            of property
 * @param contains
 *            true or false
 * @return list of JSON objects with processes for specific property
 */
private List<Map<String, Object>> findByProperty(String title, String value, String type, String key,
        boolean contains) throws DataException {
    List<Map<String, Object>> properties;
    if (Objects.isNull(value)) {
        properties = ServiceManager.getPropertyService().findByTitle(title, type, contains);
    } else if (Objects.isNull(title)) {
        properties = ServiceManager.getPropertyService().findByValue(value, type, contains);
    } else {
        properties = ServiceManager.getPropertyService().findByTitleAndValue(title, value, type, contains);
    }

    return findDocuments(createSetQuery(key, properties, true));
}

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

/**
 * Metadata inheritance and enrichment.//from   ww  w.j  a v a 2  s.  c o  m
 */
private void updateMetadata() {
    if (ConfigCore.getBooleanParameter(ParameterCore.USE_METADATA_ENRICHMENT)) {
        LegacyDocStructHelperInterface enricher = rdf.getDigitalDocument().getLogicalDocStruct();
        Map<String, Map<String, LegacyMetadataHelper>> higherLevelMetadata = new HashMap<>();
        while (Objects.nonNull(enricher.getAllChildren())) {
            // save higher level metadata for lower enrichment
            List<LegacyMetadataHelper> allMetadata = enricher.getAllMetadata();
            if (Objects.isNull(allMetadata)) {
                allMetadata = Collections.emptyList();
            }
            iterateOverAllMetadata(higherLevelMetadata, allMetadata);

            // enrich children with inherited metadata
            for (LegacyDocStructHelperInterface nextChild : enricher.getAllChildren()) {
                enricher = nextChild;
                iterateOverHigherLevelMetadata(enricher, higherLevelMetadata);
            }
        }
    }
}

From source file:org.jamocha.rating.fraj.RatingProvider.java

private void recursiveRateNode(final Node node, final Map<Node, Double> nodeToCost,
        final Map<Node, Set<Pair<Set<Path>, Set<PathFilterList>>>> preNetwork,
        final StatisticsProvider statProvider) {

    // If node costs have been calculated return pre network filters
    if (preNetwork.containsKey(node)) {
        assert nodeToCost.containsKey(node);
        return;//  ww  w  .ja va 2 s  .co m
    }
    // Else calculate costs and then return pre network filters

    // Get the Set PathNodeFilterSets for each edge from the pre-Network by recursively calling
    // this method for every parent node
    final Edge[] incomingEdges;
    try {
        incomingEdges = node.getIncomingEdges();
    } catch (final UnsupportedOperationException e) {
        // node instanceof OTN
        preNetwork.put(node,
                node.getPathNodeFilterSets().stream()
                        .map(pnfs -> Pair.of(
                                Lambdas.newIdentityHashSet(
                                        PathCollector.newHashSet().collectAllInLists(pnfs).getPaths()),
                                Collections.<PathFilterList>singleton(pnfs)))
                        .collect(toSet()));
        nodeToCost.put(node, 0.0);
        return;
    }
    PathNodeFilterSet chosenPnfs = null;
    Pair<Set<Path>, Set<PathFilterList>> chosenPair = null;
    Set<Set<PathFilterList>> chosenEdgeSet = null;
    Map<Path, Set<PathFilterList>> chosenPathToComponent = null;
    for (final PathNodeFilterSet localPnfs : node.getPathNodeFilterSets()) {
        chosenEdgeSet = new HashSet<>();
        chosenPathToComponent = new HashMap<>();
        final Set<Path> localPaths = Lambdas
                .newIdentityHashSet(PathCollector.newHashSet().collectAllInLists(localPnfs).getPaths());
        final Set<Path> resultPaths = new HashSet<Path>();
        final Set<PathFilterList> resultFilters = new HashSet<>();
        final Set<Set<PathFilterList>> preNetworkFilters = new HashSet<>();
        for (final Edge edge : incomingEdges) {
            final Node sourceNode = edge.getSourceNode();
            recursiveRateNode(sourceNode, nodeToCost, preNetwork, statProvider);
            final Set<Pair<Set<Path>, Set<PathFilterList>>> set = preNetwork.get(sourceNode);
            for (final Pair<Set<Path>, Set<PathFilterList>> pair : set) {
                final Set<Path> paths = pair.getLeft();
                final Set<PathFilterList> filters = pair.getRight();
                if (!Collections.disjoint(paths, localPaths)) {
                    preNetworkFilters.add(filters);
                    resultFilters.addAll(filters);
                    resultPaths.addAll(paths);
                    chosenEdgeSet.add(filters);
                    for (final Path path : paths) {
                        chosenPathToComponent.put(path, filters);
                    }
                }
            }
        }
        resultFilters.add(localPnfs);
        final Pair<Set<Path>, Set<PathFilterList>> localPair = Pair.of(resultPaths, resultFilters);
        preNetwork.computeIfAbsent(node, Lambdas.newIdentityHashSet()).add(localPair);
        chosenPnfs = localPnfs;
        chosenPair = localPair;
    }
    assert null != chosenPnfs;
    assert null != chosenPair;
    assert null != chosenEdgeSet;
    assert null != chosenPathToComponent;

    // Create a List of all PathFilters in this node
    final List<PathFilter> pathFilters = new ArrayList<>(chosenPnfs.getFilters());
    // Create a Map that maps each Set of PathNodeFilterSets to a singletonList with a Pair of a
    // List of all other PathNodeFilterSetLists and the PathFilter List from this Node
    final Map<Set<PathFilterList>, List<Pair<List<Set<PathFilterList>>, List<PathFilter>>>> pathToComponents = new HashMap<Set<PathFilterList>, List<Pair<List<Set<PathFilterList>>, List<PathFilter>>>>();
    for (final Set<PathFilterList> edge : chosenEdgeSet) {
        final SetView<Set<PathFilterList>> otherEdges = Sets.difference(chosenEdgeSet,
                Collections.singleton(edge));
        pathToComponents.put(edge,
                Collections.singletonList(Pair.of(new ArrayList<>(otherEdges), pathFilters)));
    }

    // Rate the node, depending on the Type of node either Alpha or Beta
    final double cost;
    if (incomingEdges.length > 1) {
        // Create a Map that maps each path to the corresponding Set of PathNodeFilterSets
        cost = rateBeta(statProvider, chosenPnfs, pathToComponents, chosenPathToComponent);
    } else if (!Objects.isNull(node.getMemory())) {
        cost = rateMaterialisedAlpha(statProvider, chosenPnfs,
                Iterables.first(chosenEdgeSet).getOrElse(new HashSet<PathFilterList>()));
    } else {
        cost = rateVirtualAlpha(statProvider, chosenPnfs,
                Iterables.first(chosenEdgeSet).getOrElse(new HashSet<PathFilterList>()));
    }
    nodeToCost.put(node, cost);
    // Return the Set of PathNodeFilterSet that represents the pre-network including this
    // node
}

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

private void iterateOverHigherLevelMetadata(LegacyDocStructHelperInterface enricher,
        Map<String, Map<String, LegacyMetadataHelper>> higherLevelMetadata) {
    for (Entry<String, Map<String, LegacyMetadataHelper>> availableHigherMetadata : higherLevelMetadata
            .entrySet()) {//  w  ww.ja v a 2  s.c  om
        String enrichable = availableHigherMetadata.getKey();
        if (!isAddable(enricher, enrichable)) {
            continue;
        }

        for (Entry<String, LegacyMetadataHelper> higherElement : availableHigherMetadata.getValue()
                .entrySet()) {
            List<LegacyMetadataHelper> amNotNull = enricher.getAllMetadata();
            if (Objects.isNull(amNotNull)) {
                amNotNull = Collections.emptyList();
            }
            boolean breakMiddle = false;
            for (LegacyMetadataHelper existentMetadata : amNotNull) {
                if (existentMetadata.getMetadataType().getName().equals(enrichable)
                        && existentMetadata.getValue().equals(higherElement.getKey())) {
                    breakMiddle = true;
                    break;
                }
            }
            if (breakMiddle) {
                break;
            } else {
                enricher.addMetadata(higherElement.getValue());
            }
        }
    }
}

From source file:com.intuit.wasabi.repository.cassandra.impl.CassandraAssignmentsRepositoryTest.java

@Test
public void testBucketAssignmentCount() {
    Experiment experiment = Experiment.withID(Experiment.ID.valueOf(this.experimentId))
            .withIsPersonalizationEnabled(false).withIsRapidExperiment(false).build();
    List<BucketAssignmentCount> mockedList = new ArrayList<>();
    mockedList.add(BucketAssignmentCount.builder().bucketLabel("bucket-1").count(500L)
            .experimentId(this.experimentId).build());
    mockedList.add(BucketAssignmentCount.builder().bucketLabel(null).count(500L).experimentId(this.experimentId)
            .build());/*  w  ww  .  j  av a 2s .  c  o m*/
    Result<BucketAssignmentCount> result = mock(Result.class);
    when(bucketAssignmentCountAccessor.selectBy(eq(experiment.getID().getRawID()))).thenReturn(result);
    when(result.iterator()).thenReturn(mockedList.iterator());
    AssignmentCounts assignmentCounts = repository.getBucketAssignmentCount(experiment);
    assertThat(assignmentCounts.getExperimentID(), is(experiment.getID()));
    assertThat(assignmentCounts.getAssignments().size(), is(mockedList.size()));
    for (int i = 0; i < mockedList.size(); i++) {
        String label = mockedList.get(i).getBucketLabel();
        if (Objects.isNull(label)) {
            assertThat(assignmentCounts.getAssignments().get(i).getBucket(),
                    is(mockedList.get(i).getBucketLabel()));
        } else {
            assertThat(assignmentCounts.getAssignments().get(i).getBucket(),
                    is(Bucket.Label.valueOf(mockedList.get(i).getBucketLabel())));
        }
        assertThat(assignmentCounts.getAssignments().get(i).getCount(), is(mockedList.get(i).getCount()));
    }
    assertThat(assignmentCounts.getTotalUsers().getBucketAssignments(), is(500L));
    assertThat(assignmentCounts.getTotalUsers().getNullAssignments(), is(500L));
    assertThat(assignmentCounts.getTotalUsers().getTotal(), is(1000L));
}

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

/**
 * Parses the canonical part of the filename from the URIs of the media
 * units. Because we need to do this to be able to parse correctly, old
 * absolute URIs are converted to relative URIs.
 *///from w  ww . j a va2s .  com
private List<String> getCanonicalFileNamePartsAndSanitizeAbsoluteURIs(Workpiece workpiece,
        Map<String, Subfolder> subfolders, URI processBaseUri) {

    List<String> canonicals = new LinkedList<>();
    String baseUriString = processBaseUri.toString();
    if (!baseUriString.endsWith("/")) {
        baseUriString = baseUriString.concat("/");
    }
    for (MediaUnit mediaUnit : workpiece.getAllMediaUnits()) {
        String unitCanonical = "";
        for (Entry<MediaVariant, URI> entry : mediaUnit.getMediaFiles().entrySet()) {
            Subfolder subfolder = subfolders.get(entry.getKey().getUse());
            if (Objects.isNull(subfolder)) {
                logger.warn("Missing subfolder for USE {}", entry.getKey().getUse());
                continue;
            }
            URI mediaFile = entry.getValue();
            String fileUriString = mediaFile.toString();
            if (fileUriString.startsWith(baseUriString)) {
                mediaFile = URI.create(fileUriString.substring(baseUriString.length()));
                mediaUnit.getMediaFiles().put(entry.getKey(), mediaFile);
            }
            String fileCanonical = subfolder.getCanonical(mediaFile);
            if ("".equals(unitCanonical)) {
                unitCanonical = fileCanonical;
            } else if (unitCanonical.equals(fileCanonical)) {
                continue;
            } else {
                throw new IllegalArgumentException(
                        "Ambiguous canonical file name part in the same media unit: \"" + unitCanonical
                                + "\" and \"" + fileCanonical + "\"!");
            }
        }
        if (mediaUnit.getMediaFiles().size() > 0 && "".equals(unitCanonical)) {
            throw new IllegalArgumentException("Missing canonical file name part in media unit " + mediaUnit);
        }
        canonicals.add(unitCanonical);
    }
    return canonicals;
}

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

private boolean isAddable(LegacyDocStructHelperInterface enricher, String enrichable) {
    boolean addable = false;
    List<LegacyMetadataTypeHelper> addableTypesNotNull = enricher.getAddableMetadataTypes();
    if (Objects.isNull(addableTypesNotNull)) {
        addableTypesNotNull = Collections.emptyList();
    }//w ww .  j  a  v  a  2 s .  co  m
    for (LegacyMetadataTypeHelper addableMetadata : addableTypesNotNull) {
        if (addableMetadata.getName().equals(enrichable)) {
            addable = true;
            break;
        }
    }
    return addable;
}

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

/**
 * Get directory for TIFF images.//from www . j av a 2  s . c  o m
 *
 * @param useFallBack
 *            add description
 * @param processId
 *            id of process object
 * @param processTitle
 *            title of process object
 * @param processBaseURI
 *            base URI of process object
 * @return tif directory
 */
public URI getImagesTifDirectory(boolean useFallBack, Integer processId, String processTitle,
        URI processBaseURI) {
    URI dir = fileService.getProcessSubTypeURI(processId, processTitle, processBaseURI, ProcessSubType.IMAGE,
            null);

    /* nur die _tif-Ordner anzeigen, die nicht mir orig_ anfangen */
    FilenameFilter filterDirectory = new FileNameEndsAndDoesNotBeginWithFilter(DIRECTORY_PREFIX + "_",
            "_" + DIRECTORY_SUFFIX);
    URI tifDirectory = null;
    List<URI> directories = fileService.getSubUris(filterDirectory, dir);
    for (URI directory : directories) {
        tifDirectory = directory;
    }

    if (Objects.isNull(tifDirectory) && useFallBack && !SUFFIX.isEmpty()) {
        List<URI> folderList = fileService.getSubUrisForProcess(null, processId, processTitle, processBaseURI,
                ProcessSubType.IMAGE, "");
        for (URI folder : folderList) {
            if (folder.toString().endsWith(SUFFIX)) {
                tifDirectory = folder;
                break;
            }
        }
    }

    tifDirectory = getImageDirectory(useFallBack, dir, tifDirectory);

    URI result = fileService.getProcessSubTypeURI(processId, processTitle, processBaseURI, ProcessSubType.IMAGE,
            null);

    if (Objects.isNull(tifDirectory)) {
        tifDirectory = URI
                .create(result.getRawPath() + Helper.getNormalizedTitle(processTitle) + "_" + DIRECTORY_SUFFIX);
    }

    return tifDirectory;
}

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

/**
 * Adds a count to media that do not yet have a count. But only at the end,
 * or if none of the media has been counted yet at all. New media found in
 * intermediate places are marked uncounted.
 *//*  w  w w  .  java 2 s .c  o  m*/
private void repaginateMediaUnits(Workpiece workpiece) {
    List<MediaUnit> mediaUnits = workpiece.getMediaUnits();
    int first = 0;
    String value;
    switch (ConfigCore.getParameter(ParameterCore.METS_EDITOR_DEFAULT_PAGINATION)) {
    case "arabic":
        value = "1";
        break;
    case "roman":
        value = "I";
        break;
    default:
        value = " - ";
        break;
    }
    for (int i = mediaUnits.size() - 1; i >= 0; i--) {
        MediaUnit mediaUnit = mediaUnits.get(i);
        String orderlabel = mediaUnit.getOrderlabel();
        if (orderlabel == null || mediaUnit.getMediaFiles().isEmpty()) {
            continue;
        }
        first = i + 1;
        value = orderlabel;
        mediaUnits.get(i).setType("page");
        break;
    }
    Paginator paginator = new Paginator(value);
    if (first > 0) {
        paginator.next();
        for (int i = first; i < mediaUnits.size(); i++) {
            mediaUnits.get(i).setOrderlabel(paginator.next());
        }
    }
    for (MediaUnit mediaUnit : mediaUnits) {
        if (Objects.isNull(mediaUnit.getOrderlabel())) {
            mediaUnit.setOrderlabel(" - ");
        }
    }
}

From source file:org.dc.file.search.ui.DashboardForm.java

protected void fireEditingStopped() {
    // Guaranteed to return a non-null array
    Object[] listeners = listenerList.getListenerList();
    // Process the listeners last to first, notifying
    // those that are interested in this event
    for (int i = listeners.length - 2; i >= 0; i -= 2) {
        if (listeners[i] == CellEditorListener.class) {
            // Lazily create the event:
            if (Objects.isNull(changeEvent)) {
                changeEvent = new ChangeEvent(this);
            }/*w w w .j ava  2s . co  m*/
            ((CellEditorListener) listeners[i + 1]).editingStopped(changeEvent);
        }
    }
}