Example usage for java.util Comparator comparingInt

List of usage examples for java.util Comparator comparingInt

Introduction

In this page you can find the example usage for java.util Comparator comparingInt.

Prototype

public static <T> Comparator<T> comparingInt(ToIntFunction<? super T> keyExtractor) 

Source Link

Document

Accepts a function that extracts an int sort key from a type T , and returns a Comparator that compares by that sort key.

Usage

From source file:org.gradoop.flink.model.impl.operators.matching.single.cypher.pojos.EmbeddingMetaData.java

@Override
public String toString() {
    List<Map.Entry<Pair<String, EntryType>, Integer>> sortedEntries = entryMapping.entrySet().stream()
            .sorted(Comparator.comparingInt(Map.Entry::getValue)).collect(Collectors.toList());

    List<Map.Entry<Pair<String, String>, Integer>> sortiedProperties = propertyMapping.entrySet().stream()
            .sorted(Comparator.comparingInt(Map.Entry::getValue)).collect(Collectors.toList());

    return String.format("EmbeddingMetaData{entryMapping=%s, propertyMapping=%s}", sortedEntries,
            sortiedProperties);//from  w ww.  j  a  v  a  2 s  .c om
}

From source file:org.gradoop.flink.model.impl.operators.matching.single.cypher.pojos.EmbeddingMetaData.java

/**
 * Returns the variables that fulfil the specified predicate. The variables are ordered by
 * their appearance in the entry mapping.
 *
 * @param predicate predicate for entry types
 * @return variables that fulfil the predicate
 *//*from  w  w  w.j  a  va 2 s  .  c o  m*/
private List<String> getVariables(Predicate<EntryType> predicate) {
    return entryMapping.entrySet().stream().filter(entry -> predicate.test(entry.getKey().getRight()))
            .sorted(Comparator.comparingInt(Map.Entry::getValue)).map(entry -> entry.getKey().getLeft())
            .collect(Collectors.toList());
}

From source file:org.haiku.haikudepotserver.pkg.job.PkgScreenshotImportArchiveJobRunner.java

private void blendInArtificialOrderings(ScreenshotImportMetadatas metadata) {
    int maxExistingOrderOptional = metadata.getExistingScreenshots().stream()
            .mapToInt(ExistingScreenshotMetadata::getOrder).max().orElse(0) // dummy value
            + 1000;/*from w w  w  .  j av  a 2  s  .co m*/

    metadata.getFromArchiveScreenshots().stream()
            .sorted(Comparator.comparingInt(FromArchiveScreenshotMetadata::getOrder))
            .forEach((fa) -> fa.setDerivedOrder(fa.getOrder() + maxExistingOrderOptional));
}

From source file:org.jamocha.dn.compiler.pathblocks.PathBlocks.java

protected static void determineAndSolveConflicts(final PathBlockSet resultBlocks) {
    // determine conflicts
    final PathBlockSet deletedBlocks = new PathBlockSet();
    final DirectedGraph<Block, BlockConflict> blockConflictGraph = new SimpleDirectedGraph<>(BlockConflict::of);
    for (final Block block : resultBlocks.getBlocks()) {
        blockConflictGraph.addVertex(block);
    }/*  w w w  . j ava  2 s.  c  o m*/
    for (final Block x : blockConflictGraph.vertexSet()) {
        createArcs(blockConflictGraph, resultBlocks, x);
    }
    // solve conflicts
    while (true) {
        final Optional<BlockConflict> mostUsefulConflictsFirst = blockConflictGraph.edgeSet().stream()
                .max(Comparator.comparingInt(BlockConflict::getQuality));
        if (!mostUsefulConflictsFirst.isPresent()) {
            break;
        }
        final BlockConflict blockConflict = mostUsefulConflictsFirst.get();
        solveConflict(blockConflict, blockConflictGraph, resultBlocks, deletedBlocks);
    }
}

From source file:org.jboss.prod.jardif.JarDif.java

private void compare(Path maven, Path gradle) {
    System.out.println("===============================================");
    System.out.println(maven + " vs " + gradle);
    System.out.println("===============================================");
    Path gradleDir = new File(workDir, "gradle-" + gradle.getFileName().toString()).toPath();
    Path mvnDir = new File(workDir, "maven-" + maven.getFileName().toString()).toPath();
    ZipUtils.unzip(maven, mvnDir);/* w w  w  .  ja va 2s.  co m*/
    ZipUtils.unzip(gradle, gradleDir);

    List<String> mvnContents = OSUtils.runCommandIn("find . -type f", mvnDir);
    mvnContents.sort(Comparator.comparingInt(String::hashCode));
    List<String> gradleContents = OSUtils.runCommandIn("find . -type f", gradleDir);
    gradleContents.sort(Comparator.comparingInt(String::hashCode));

    Iterator<String> mvnFiles = mvnContents.stream().iterator();
    Iterator<String> gradleFiles = gradleContents.stream().iterator();

    if (!mvnFiles.hasNext() || !gradleFiles.hasNext()) {
        throw new IllegalStateException("One of the jars: " + maven + ", " + gradle + " is empty! Exitting");
    }
    String mvnFile = mvnFiles.next();
    String gradleFile = gradleFiles.next();

    while (mvnFiles.hasNext() && gradleFiles.hasNext()) {
        if (mvnFile.equals(gradleFile)) {
            compareFiles(new File(mvnDir.toFile(), mvnFile), new File(gradleDir.toFile(), gradleFile));
            mvnFile = mvnFiles.next();
            gradleFile = gradleFiles.next();
        } else if (mvnFile.hashCode() < gradleFile.hashCode()) {
            System.out.println("+" + mvnFile);
            mvnFile = mvnFiles.next();
        } else {
            System.out.println("-" + gradleFile);
            gradleFile = gradleFiles.next();
        }
    }

    mvnFiles.forEachRemaining(e -> System.out.println("+" + e));
    gradleFiles.forEachRemaining(e -> System.out.println("-" + e));
    System.out.println();
    System.out.println();
}

From source file:org.kuali.coeus.common.committee.impl.lookup.CommitteeLookupableHelperServiceImplBase.java

protected Map<String, String> getLatestDocumentNumber(List<CMT> committees, String routeHeaderCode) {
    return committees.stream()
            .filter(committee -> committee.getCommitteeDocument().getDocStatusCode().equals(routeHeaderCode))
            .collect(Collectors.groupingBy(committee -> committee.getCommitteeId())).entrySet().stream()
            .collect(Collectors.toMap(Map.Entry::getKey,
                    value -> value.getValue().stream()
                            .max(Comparator.comparingInt(committee -> committee.getSequenceNumber())).get()
                            .getCommitteeDocument().getDocumentNumber()));
}

From source file:org.niord.core.chart.ChartService.java

/**
 * Searches for charts matching the given term
 *
 * @param term the search term//from   w  w w.  j a  v a2s.  co  m
 * @param inactive whether to include inactive charts as well as active
 * @param limit the maximum number of results
 * @return the search result
 */
public List<Chart> searchCharts(String term, boolean inactive, int limit) {

    if (StringUtils.isNotBlank(term)) {
        Set<Boolean> activeFlag = new HashSet<>();
        activeFlag.add(Boolean.TRUE);
        if (inactive) {
            activeFlag.add(Boolean.FALSE);
        }
        return em.createNamedQuery("Chart.searchCharts", Chart.class).setParameter("active", activeFlag)
                .setParameter("term", "%" + term + "%").getResultList().stream()
                .sorted(Comparator.comparingInt(c -> c.computeSearchSortKey(term))).limit(limit)
                .collect(Collectors.toList());
    }
    return Collections.emptyList();
}

From source file:org.niord.core.message.MessageService.java

/**
 * Returns the message with the given IDs
 *
 * @param ids the message IDs/*from   w  ww  . ja  v  a  2s .c o m*/
 * @return the message with the given IDs
 */
private List<Message> getMessages(List<Integer> ids) {

    if (ids.isEmpty()) {
        return Collections.emptyList();
    }

    List<Message> messages = em.createNamedQuery("Message.findByIds", Message.class).setParameter("ids", ids)
            .getResultList();

    // Sort the result according to the order of the messages in the ID list
    messages.sort(Comparator.comparingInt(m -> ids.indexOf(m.getId())));

    return messages;
}

From source file:org.niord.core.publication.PublicationService.java

/**
 * Returns the publications with the given database IDs
 *
 * @param ids the database IDs//from   ww w . ja v a2 s.co  m
 * @return the publications with the database IDs
 */
public List<Publication> findByIds(List<Integer> ids) {

    if (ids == null || ids.isEmpty()) {
        return Collections.emptyList();
    }

    List<Publication> publications = em.createNamedQuery("Publication.findByIds", Publication.class)
            .setParameter("ids", ids).getResultList();

    // Sort the result according to the order of the publications in the ID list
    publications.sort(Comparator.comparingInt(m -> ids.indexOf(m.getId())));

    return publications;
}

From source file:org.openhab.binding.dwdunwetter.internal.data.SeverityComparator.java

@Override
public int compare(DwdWarningData o1, DwdWarningData o2) {

    Comparator.comparingInt(d -> ((DwdWarningData) d).getSeverity().getOrder());
    Comparator.comparing(DwdWarningData::getOnset);

    int result = Integer.compare(o1.getSeverity().getOrder(), o2.getSeverity().getOrder());
    if (result == 0) {
        result = ObjectUtils.compare(o1.getOnset(), o2.getOnset());
    }/*  w w w  . j  av a  2 s  .c  o m*/
    return result;
}