Example usage for java.util Comparator reversed

List of usage examples for java.util Comparator reversed

Introduction

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

Prototype

default Comparator<T> reversed() 

Source Link

Document

Returns a comparator that imposes the reverse ordering of this comparator.

Usage

From source file:main.java.RMDupper.java

/**
 * This Method reads a SAM File and parses the input
 * Currently, only merged Reads with the "M" Flag in front are checked for Duplicates.
 * R/F Flags are simply written into output File, also other "non-flagged" ones.
 *///from   ww  w .  j  a va  2 s.c o  m
public void readSAMFile() {
    Comparator<SAMRecord> samRecordComparatorForRecordBuffer = new SAMRecordPositionAndQualityComparator();
    Comparator<SAMRecord> samRecordComparatorForDuplicateBuffer;

    if (this.allReadsAsMerged) {
        samRecordComparatorForDuplicateBuffer = new SAMRecordQualityComparator();
    } else {
        samRecordComparatorForDuplicateBuffer = new SAMRecordQualityComparatorPreferMerged();
    }

    PriorityQueue<ImmutableTriple<Integer, Integer, SAMRecord>> recordBuffer = new PriorityQueue<ImmutableTriple<Integer, Integer, SAMRecord>>(
            1000, Comparator.comparing(ImmutableTriple<Integer, Integer, SAMRecord>::getRight,
                    samRecordComparatorForRecordBuffer));
    PriorityQueue<ImmutableTriple<Integer, Integer, SAMRecord>> duplicateBuffer = new PriorityQueue<ImmutableTriple<Integer, Integer, SAMRecord>>(
            1000, Comparator.comparing(ImmutableTriple<Integer, Integer, SAMRecord>::getRight,
                    samRecordComparatorForDuplicateBuffer.reversed()));
    Set<String> discardSet = new HashSet<String>(1000);
    String referenceName = SAMRecord.NO_ALIGNMENT_REFERENCE_NAME;

    Iterator it = inputSam.iterator();
    while (it.hasNext()) {
        SAMRecord curr = (SAMRecord) it.next();
        if (curr.getReferenceName() == SAMRecord.NO_ALIGNMENT_REFERENCE_NAME) {
            this.outputSam.addAlignment(curr);
        } else {
            if (referenceName == curr.getReferenceName()) {
                queueOrOutput(this.dupStats, this.oc, this.outputSam, this.allReadsAsMerged, recordBuffer,
                        duplicateBuffer, discardSet, curr);
            } else {
                flushQueue(this.dupStats, this.oc, this.outputSam, this.allReadsAsMerged, recordBuffer,
                        duplicateBuffer, discardSet);
                queueOrOutput(this.dupStats, this.oc, this.outputSam, this.allReadsAsMerged, recordBuffer,
                        duplicateBuffer, discardSet, curr);
                referenceName = curr.getReferenceName();
            }
        }

        this.dupStats.total++;
        if (this.dupStats.total % 100000 == 0) {
            if (!piped) {
                System.err.println("Reads treated: " + this.dupStats.total);
            }
        }
    }
    flushQueue(this.dupStats, this.oc, this.outputSam, this.allReadsAsMerged, recordBuffer, duplicateBuffer,
            discardSet);
}

From source file:org.cloudsimplus.sla.responsetime.CloudletResponseTimeMinimizationExperiment.java

private void sortCloudletListByExpectedResponseTime() {
    //sort the cloudlet list by expected response time
    Comparator<Cloudlet> sortByExpectedCloudletResponseTime = null;
    for (Vm vm : getVmList()) {
        sortByExpectedCloudletResponseTime = Comparator
                .comparingDouble(cloudlet -> getExpectedCloudletResponseTime(cloudlet, vm));
    }//from  w  w  w  .  j a  v  a  2s .com
    cloudletList.sort(sortByExpectedCloudletResponseTime.reversed());
    System.out.println("\t\tCreated Cloudlets: " + getCloudletList());
}

From source file:org.fenixedu.academic.ui.spring.controller.teacher.authorization.AuthorizationService.java

/***
 * Get all revoked teacher authorizations ordered descendingly by revoke time.
 * //  w  w  w .  j a  v a2s.c  o m
 * @return
 */
public List<TeacherAuthorization> getRevokedAuthorizations() {
    Comparator<TeacherAuthorization> byRevokeTime = (a1, a2) -> {
        return a1.getRevokeTime().compareTo(a2.getRevokeTime());
    };

    return Bennu.getInstance().getRevokedTeacherAuthorizationSet().stream().distinct()
            .sorted(byRevokeTime.reversed()).collect(Collectors.toList());
}

From source file:org.languagetool.rules.spelling.morfologik.suggestions_ordering.SuggestionsOrderer.java

public List<String> orderSuggestionsUsingModel(List<String> suggestions, String word, AnalyzedSentence sentence,
        int startPos, int wordLength) {
    if (!isMlAvailable()) {
        return suggestions;
    }//from  w  w w . j  a  v a 2 s . c  om
    List<Pair<String, Float>> suggestionsScores = new LinkedList<>();
    for (String suggestion : suggestions) {
        String text = sentence.getText();
        String correctedSentence = text.substring(0, startPos) + suggestion
                + sentence.getText().substring(startPos + wordLength);

        float score = processRow(text, correctedSentence, word, suggestion, DEFAULT_CONTEXT_LENGTH);
        suggestionsScores.add(Pair.of(suggestion, score));
    }
    Comparator<Pair<String, Float>> comparing = Comparator.comparing(Pair::getValue);
    suggestionsScores.sort(comparing.reversed());
    List<String> result = new LinkedList<>();
    suggestionsScores.iterator().forEachRemaining((Pair<String, Float> p) -> result.add(p.getKey()));
    return result;
}

From source file:org.languagetool.rules.spelling.morfologik.suggestions_ordering.SuggestionsOrdererGSoC.java

@Override
public List<SuggestedReplacement> orderSuggestions(List<String> suggestions, String word,
        AnalyzedSentence sentence, int startPos) {
    if (!isMlAvailable()) {
        return suggestions.stream().map(SuggestedReplacement::new).collect(Collectors.toList());
    }/*from   ww w  .  j a v  a2 s .  c  o  m*/
    List<Pair<String, Float>> suggestionsScores = new LinkedList<>();
    for (String suggestion : suggestions) {
        String text = sentence.getText();
        String correctedSentence = text.substring(0, startPos) + suggestion
                + sentence.getText().substring(startPos + word.length());

        float score = processRow(text, correctedSentence, word, suggestion, DEFAULT_CONTEXT_LENGTH);
        suggestionsScores.add(Pair.of(suggestion, score));
    }
    Comparator<Pair<String, Float>> comparing = Comparator.comparing(Pair::getValue);
    suggestionsScores.sort(comparing.reversed());

    return suggestionsScores.stream().map(p -> {
        SuggestedReplacement s = new SuggestedReplacement(p.getKey());
        s.setConfidence(p.getRight());
        return s;
    }).collect(Collectors.toList());
}

From source file:org.matonto.catalog.rest.impl.CatalogRestImpl.java

/**
 * Creates a Response for a page of a sorted limited offset Set of Things based on the return type of the passed
 * function using the passed full Set of Resources.
 *
 * @param uriInfo The URI information of the request.
 * @param iris The Set of Resource for all of the Things.
 * @param thingFunction A Function to retrieve Things based on their Resource IDs.
 * @param sortBy The property IRI string to sort the Set of Things by.
 * @param offset The number of Things to skip.
 * @param limit The size of the page of Things to the return.
 * @param asc Whether the sorting should be ascending or descending.
 * @param filterFunction A Function to filter the set of Things.
 * @param <T> A class that extends Things.
 * @return A Response with a page of Things that has been filtered, sorted, and limited and headers for the total
 *      size and links to the next and prev pages if present.
 *///from w  ww  .j a v  a  2  s  .co  m
private <T extends Thing> Response createPaginatedThingResponse(UriInfo uriInfo, Set<Resource> iris,
        Function<Resource, T> thingFunction, String sortBy, int offset, int limit, boolean asc,
        Function<T, Boolean> filterFunction) {
    if (offset > iris.size()) {
        throw ErrorUtils.sendError("Offset exceeds total size", Response.Status.BAD_REQUEST);
    }
    IRI sortIRI = factory.createIRI(sortBy);
    Comparator<T> comparator = Comparator.comparing(dist -> dist.getProperty(sortIRI).get().stringValue());
    Stream<T> stream = iris.stream().map(thingFunction);
    if (!asc) {
        comparator = comparator.reversed();
    }
    if (filterFunction != null) {
        stream = stream.filter(filterFunction::apply);
    }
    List<T> filteredThings = stream.collect(Collectors.toList());
    List<T> things = filteredThings.stream().sorted(comparator).skip(offset).limit(limit)
            .collect(Collectors.toList());
    return createPaginatedResponse(uriInfo, things, filteredThings.size(), limit, offset);
}

From source file:org.polymap.rhei.table.DefaultFeatureTableColumn.java

/**
 * {@inheritDoc}//w  ww  .  ja v a  2s. co  m
 * <p/>
 * This default implementation returns a {@link DefaultColumnComparator}.
 */
@Override
public Comparator<IFeatureTableElement> newComparator(int sortDir) {
    Comparator<IFeatureTableElement> result = new DefaultColumnComparator(this);
    return sortDir == SWT.UP ? result.reversed() : result;
}

From source file:org.sleuthkit.autopsy.imageanalyzer.grouping.GroupSortBy.java

private static <T> Comparator<T> applySortOrder(final SortOrder sortOrder, Comparator<T> comparingInt) {
    switch (sortOrder) {
    case ASCENDING:
        return comparingInt;
    case DESCENDING:
        return comparingInt.reversed();
    case UNSORTED:
    default:/* ww w  . ja va2  s .  com*/
        return new NoOpComparator<>();
    }
}

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

private static <T> Comparator<T> applySortOrder(final SortOrder sortOrder, Comparator<T> comparator) {
    switch (sortOrder) {
    case ASCENDING:
        return comparator;
    case DESCENDING:
        return comparator.reversed();
    case UNSORTED:
    default:/*from  w w w. j ava2 s. c  om*/
        return new GroupSortBy.AllEqualComparator<>();
    }
}