Example usage for java.util Collections reverseOrder

List of usage examples for java.util Collections reverseOrder

Introduction

In this page you can find the example usage for java.util Collections reverseOrder.

Prototype

@SuppressWarnings("unchecked")
public static <T> Comparator<T> reverseOrder(Comparator<T> cmp) 

Source Link

Document

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

Usage

From source file:org.openmrs.module.casereport.page.controller.SubmittedCaseReportsPageController.java

public void get(PageModel model, @SpringBean CaseReportService service,
        @SpringBean(FhirDocumentGeneratorListener.BEAN_ID) FhirDocumentGeneratorListener listener)
        throws Exception {

    List<CaseReport> caseReports = service.getSubmittedCaseReports(null);
    model.put("caseReports", caseReports);
    SimpleObject reportUuidDocumentMap = new SimpleObject();
    SimpleObject reportUuidSubmittedTriggersMap = new SimpleObject();
    //Sort by date changed(date submitted) with most recent first
    Collections.sort(caseReports, Collections.reverseOrder(new Comparator<CaseReport>() {

        @Override/*  w  w w .  j  a v a  2s .c  o  m*/
        public int compare(CaseReport cr1, CaseReport cr2) {
            return OpenmrsUtil.compare(cr1.getDateChanged(), cr2.getDateChanged());
        }
    }));

    for (CaseReport caseReport : caseReports) {
        String uuid = caseReport.getUuid();
        String document = FileUtils.readFileToString(
                new File(listener.getOutputDirectory(), uuid + FhirDocumentGeneratorListener.FILE_EXT_TXT),
                FhirDocumentGeneratorListener.ENCODING_UTF8);
        reportUuidDocumentMap.put(uuid, document);
        CaseReportForm form = getObjectMapper().readValue(caseReport.getReportForm(), CaseReportForm.class);
        List<String> triggers = new ArrayList<String>();
        for (UuidAndValue uuidAndValue : form.getTriggers()) {
            triggers.add(uuidAndValue.getValue().toString());
        }
        reportUuidSubmittedTriggersMap.put(uuid, StringUtils.join(triggers, ", "));
    }

    model.put("reportUuidSubmittedTriggersMap", reportUuidSubmittedTriggersMap);
    model.put("reportUuidDocumentMap", getObjectMapper().writeValueAsString(reportUuidDocumentMap));
}

From source file:org.sakaiproject.scorm.ui.reporting.util.InteractionProvider.java

public Iterator<Interaction> iterator(int first, int count) {

    // Get the sort type
    SortParam sort = getSort();/*  w  w w . j  av a 2  s  . c  o m*/
    String sortProp = sort.getProperty();
    boolean sortAsc = sort.isAscending();

    // Set the sort type in the comparator
    if (StringUtils.equals(sortProp, "description")) {
        comp.setCompType(CompType.Description);
    } else if (StringUtils.equals(sortProp, "type")) {
        comp.setCompType(CompType.Type);
    } else if (StringUtils.equals(sortProp, "result")) {
        comp.setCompType(CompType.Result);
    } else {
        comp.setCompType(CompType.InteractionID);
    }

    // Sort using the comparator in the direction requested
    if (sortAsc) {
        Collections.sort(interactions, comp);
    } else {
        Collections.sort(interactions, Collections.reverseOrder(comp));
    }

    // Return sub list of sorted collection
    return interactions.subList(first, first + count).iterator();
}

From source file:org.sakaiproject.scorm.ui.reporting.util.SummaryProvider.java

public Iterator<ActivitySummary> iterator(int first, int count) {

    // Get the sort type
    SortParam sort = getSort();/* w  ww  .jav a 2 s .  com*/
    String sortProp = sort.getProperty();
    boolean sortAsc = sort.isAscending();

    // Set the sort type in the comparator
    if (StringUtils.equals(sortProp, "scaled")) {
        comp.setCompType(CompType.Score);
    } else if (StringUtils.equals(sortProp, "completionStatus")) {
        comp.setCompType(CompType.CompletionStatus);
    } else if (StringUtils.equals(sortProp, "successStatus")) {
        comp.setCompType(CompType.SuccessStatus);
    } else {
        comp.setCompType(CompType.Title);
    }

    // Sort using the comparator in the direction requested
    if (sortAsc) {
        Collections.sort(summaries, comp);
    } else {
        Collections.sort(summaries, Collections.reverseOrder(comp));
    }

    // Return sub list of sorted collection
    return summaries.subList(first, first + count).iterator();
}

From source file:org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreHelper.java

private static Iterable<BlobReferences> scan(DocumentNodeStore store, Comparator<BlobReferences> comparator,
        int num) {
    long totalGarbage = 0;
    Iterable<NodeDocument> docs = getDocuments(store.getDocumentStore());
    PriorityQueue<BlobReferences> queue = new PriorityQueue<BlobReferences>(num, comparator);
    List<Blob> blobs = Lists.newArrayList();
    long docCount = 0;
    for (NodeDocument doc : docs) {
        if (++docCount % 10000 == 0) {
            System.out.print(".");
        }/*w w  w  .jav a 2s  .  c  o m*/
        blobs.clear();
        BlobReferences refs = collectReferences(doc, store);
        totalGarbage += refs.garbageSize;
        queue.add(refs);
        if (queue.size() > num) {
            queue.remove();
        }
    }

    System.out.println();
    List<BlobReferences> refs = Lists.newArrayList();
    refs.addAll(queue);
    Collections.sort(refs, Collections.reverseOrder(comparator));
    System.out.println("Total garbage size: " + FileUtils.byteCountToDisplaySize(totalGarbage));
    System.out.println("Total number of nodes with blob references: " + docCount);
    System.out.println("total referenced / old referenced / # blob references / path");
    return refs;
}

From source file:net.oremland.rss.reader.fragments.BaseListFragment.java

protected Comparator getListComparator() {
    return Collections.reverseOrder(Collections.reverseOrder());
}

From source file:net.sf.jtmt.clustering.NearestNeighborClusterer.java

/**
 * Cluster./*from ww w .  j a v  a2 s .  c  om*/
 *
 * @param collection the collection
 * @return the list
 */
public List<Cluster> cluster(DocumentCollection collection) {
    // get neighbors for every document
    Map<String, Double> similarityMap = collection.getSimilarityMap();
    //    for (String key : similarityMap.keySet()) {
    //      log.debug("sim(" + key + ") => " + similarityMap.get(key));
    //    }
    Map<String, List<String>> neighborMap = new HashMap<String, List<String>>();
    for (String documentName : collection.getDocumentNames()) {
        neighborMap.put(documentName, collection.getNeighbors(documentName, similarityMap, numNeighbors));
    }
    // compute sum of similarities of every document with its numNeighbors
    Map<String, Double> fitnesses = getFitnesses(collection, similarityMap, neighborMap);
    List<String> sortedDocNames = new ArrayList<String>();
    // sort by sum of similarities descending
    sortedDocNames.addAll(collection.getDocumentNames());
    Collections.sort(sortedDocNames,
            Collections.reverseOrder(new ByValueComparator<String, Double>(fitnesses)));
    //    for (String sortedDocName : sortedDocNames) {
    //      log.debug(sortedDocName + " => " + fitnesses.get(sortedDocName));
    //    }
    List<Cluster> clusters = new ArrayList<Cluster>();
    int clusterId = 0;
    // Loop through the list of documents in descending order of the sum of the
    // similarities.
    Map<String, String> documentClusterMap = new HashMap<String, String>();
    for (String docName : sortedDocNames) {
        // skip if document already assigned to cluster
        if (documentClusterMap.containsKey(docName)) {
            continue;
        }
        // create cluster with current document
        Cluster cluster = new Cluster("C" + clusterId);
        cluster.addDocument(docName, collection.getDocument(docName));
        documentClusterMap.put(docName, cluster.getId());
        // find all neighboring documents to the left and right of the current
        // document that are not assigned to a cluster, and have a similarity
        // greater than our threshold. Add these documents to the new cluster
        List<String> neighbors = neighborMap.get(docName);
        for (String neighbor : neighbors) {
            if (documentClusterMap.containsKey(neighbor)) {
                continue;
            }
            double similarity = similarityMap.get(StringUtils.join(new String[] { docName, neighbor }, ":"));
            if (similarity < similarityThreshold) {
                continue;
            }
            cluster.addDocument(neighbor, collection.getDocument(neighbor));
            documentClusterMap.put(neighbor, cluster.getId());
        }
        clusters.add(cluster);
        clusterId++;
    }
    return clusters;
}

From source file:org.dkf.jmule.adapters.SearchResultListAdapter.java

public void addResults(final List<SearchEntry> entries, boolean hasMoreResults) {
    log.debug("results {} more {}", entries.size(), hasMoreResults ? "yes" : "no");
    moreResults = hasMoreResults;//from   w  w  w .j  a  v a 2s.  c o  m
    list.addAll(entries);
    Collections.sort(list, Collections.reverseOrder(sourcesCountComparator));
    visualList.addAll(list);
    notifyDataSetChanged();
}

From source file:org.wso2.carbon.identity.application.authentication.framework.handler.sequence.impl.SelectAcrFromFunction.java

private String selectBestOutcome(List<String> acrListRequested, String[] possibleOutcomes) {

    Map<Integer, String> acrRequestedWithPriority = new TreeMap<>(
            Collections.reverseOrder((Comparator<Integer>) (o1, o2) -> o2.compareTo(o1)));
    String acrSelected = null;/*from   w ww.ja  v a 2  s.co  m*/

    for (String acrChecked : acrListRequested) {
        for (int x = 0; x < possibleOutcomes.length; x++) {
            String outcomeToTest = possibleOutcomes[x];
            if (outcomeToTest.equals(acrChecked)) {
                if (log.isDebugEnabled()) {
                    log.debug("Reassigning Best Match for the outcome : " + outcomeToTest + " with priority : "
                            + x + 1);
                }
                acrRequestedWithPriority.put(x + 1, acrChecked);
                break;
            }
        }
    }
    if (!acrRequestedWithPriority.entrySet().isEmpty()) {
        acrSelected = acrRequestedWithPriority.entrySet().iterator().next().getValue();
    }
    return acrSelected;
}

From source file:gov.nih.nci.ncicb.tcga.dcc.datareports.service.DatareportsServiceImpl.java

public List<X> getSortedList(final List<X> list, final Map<String, Comparator> comparatorMap, final String sort,
        final String dir) {
    if (ASC.equals(dir)) {
        Collections.sort(list, comparatorMap.get(sort));
    } else if (DESC.equals(dir)) {
        Collections.sort(list, Collections.reverseOrder(comparatorMap.get(sort)));
    }/*  ww  w  .  jav  a  2s  .c  om*/
    return list;
}

From source file:org.geoserver.wps.MemoryProcessStatusStore.java

@Override
public List<ExecutionStatus> list(Query query) {
    List<ExecutionStatus> result = new ArrayList<>();

    // extract and filter
    Filter filter = query.getFilter();
    for (ExecutionStatus status : statuses.values()) {
        if (filter.evaluate(status)) {
            result.add(status);//  w w  w.  ja  va 2 s .  c o m
        }
    }

    // sort
    SortBy[] sorts = query.getSortBy();
    if (sorts != null) {
        List<Comparator<ExecutionStatus>> comparators = new ArrayList<>();
        for (SortBy sort : sorts) {
            if (sort == SortBy.NATURAL_ORDER) {
                comparators.add(new BeanComparator("creationTime"));
            } else if (sort == SortBy.REVERSE_ORDER) {
                comparators.add(Collections.reverseOrder(new BeanComparator("creationTime")));
            } else {
                String property = sort.getPropertyName().getPropertyName();
                //map property to ExecutionStatus values
                if ("node".equalsIgnoreCase(property)) {
                    property = "nodeId";
                } else if ("user".equalsIgnoreCase(property)) {
                    property = "userName";
                } else if ("task".equalsIgnoreCase(property)) {
                    property = "task";
                }
                Comparator<ExecutionStatus> comparator = new BeanComparator(property);
                if (sort.getSortOrder() == SortOrder.DESCENDING) {
                    comparator = Collections.reverseOrder(comparator);
                }
                comparators.add(comparator);
            }
        }

        if (comparators.size() > 1) {
            Comparator<ExecutionStatus> comparator = new CompositeComparator<>(comparators);
            Collections.sort(result, comparator);
        } else if (comparators.size() == 1) {
            Collections.sort(result, comparators.get(0));
        }
    }

    // paging
    Integer startIndex = query.getStartIndex();
    if (startIndex != null && startIndex > 0) {
        if (startIndex > result.size()) {
            result.clear();
        } else {
            result = result.subList(startIndex, result.size());
        }
    }
    if (result.size() > query.getMaxFeatures()) {
        result = result.subList(0, query.getMaxFeatures());
    }

    return result;
}