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:net.sourceforge.fenixedu.domain.accounting.events.export.SIBSOutgoingPaymentFile.java

public static SIBSOutgoingPaymentFile readLastSuccessfulSentPaymentFile() {
    List<SIBSOutgoingPaymentFile> files = readSuccessfulSentPaymentFiles();

    if (files.isEmpty()) {
        return null;
    }//from w w  w .  java  2 s .  co m

    Collections.sort(files, Collections.reverseOrder(SUCCESSFUL_SENT_DATE_TIME_COMPARATOR));
    return files.iterator().next();
}

From source file:org.wso2.carbon.andes.admin.mqtt.AndesMQTTAdminService.java

/**
 * Retrieve subscriptions matching the given criteria.
 *
 * @param isDurable Are the subscriptions to be retrieved durable (true/false)
 * @param isActive Are the subscriptions to be retrieved active (true/false/*, * meaning any)
 * @param protocolType The protocol type of the subscriptions to be retrieved
 * @param destinationType The destination type of the subscriptions to be retrieved
 *
 * @return The list of subscriptions matching the given criteria
 * @throws BrokerManagerAdminException//  ww w .  ja  v  a 2  s . c o m
 */
public Subscription[] getSubscriptions(String isDurable, String isActive, String protocolType,
        String destinationType) throws BrokerManagerAdminException {

    List<Subscription> allSubscriptions = new ArrayList<Subscription>();
    Subscription[] subscriptionsDTO;
    try {
        SubscriptionManagerService subscriptionManagerService = AndesBrokerManagerMQTTAdminServiceDSHolder
                .getInstance().getSubscriptionManagerService();
        List<org.wso2.carbon.andes.core.types.Subscription> subscriptions = subscriptionManagerService
                .getSubscriptions(isDurable, isActive, protocolType, destinationType);
        subscriptionsDTO = new Subscription[subscriptions.size()];
        for (org.wso2.carbon.andes.core.types.Subscription sub : subscriptions) {
            Subscription subscriptionDTO = new Subscription();
            subscriptionDTO.setSubscriptionIdentifier(sub.getSubscriptionIdentifier());
            subscriptionDTO.setSubscribedQueueOrTopicName(sub.getSubscribedQueueOrTopicName());
            subscriptionDTO.setSubscriberQueueBoundExchange(sub.getSubscriberQueueBoundExchange());
            subscriptionDTO.setSubscriberQueueName(sub.getSubscriberQueueName());
            subscriptionDTO.setDurable(sub.isDurable());
            subscriptionDTO.setActive(sub.isActive());
            subscriptionDTO
                    .setNumberOfMessagesRemainingForSubscriber(sub.getNumberOfMessagesRemainingForSubscriber());
            subscriptionDTO.setConnectedNodeAddress(sub.getConnectedNodeAddress());
            subscriptionDTO.setProtocolType(sub.getProtocolType());
            subscriptionDTO.setDestinationType(sub.getDestinationType());
            subscriptionDTO.setOriginHostAddress(sub.getOriginHostAddress());

            allSubscriptions.add(subscriptionDTO);
        }
        CustomSubscriptionComparator comparator = new CustomSubscriptionComparator();
        Collections.sort(allSubscriptions, Collections.reverseOrder(comparator));
        allSubscriptions.toArray(subscriptionsDTO);
    } catch (SubscriptionManagerException e) {
        String errorMessage = e.getMessage();
        log.error(errorMessage, e);
        throw new BrokerManagerAdminException(errorMessage, e);
    }
    return subscriptionsDTO;
}

From source file:org.nuxeo.ecm.platform.relations.web.listener.ejb.RelationActionsBean.java

@Override
@Factory(value = "currentDocumentOutgoingRelations", scope = ScopeType.EVENT)
public List<StatementInfo> getOutgoingStatementsInfo() {
    if (outgoingStatementsInfo != null) {
        return outgoingStatementsInfo;
    }//from  w w w.ja  va 2  s . com
    DocumentModel currentDoc = getCurrentDocument();
    Resource docResource = getDocumentResource(currentDoc);
    if (docResource == null) {
        outgoingStatements = Collections.emptyList();
        outgoingStatementsInfo = Collections.emptyList();
    } else {
        Graph graph = relationManager.getGraphByName(RelationConstants.GRAPH_NAME);
        outgoingStatements = graph.getStatements(docResource, null, null);
        if (graph instanceof JenaGraph) {
            // add old statements, BBB
            Resource oldDocResource = getOldDocumentResource(currentDoc);
            outgoingStatements.addAll(graph.getStatements(oldDocResource, null, null));
        }
        outgoingStatementsInfo = getStatementsInfo(outgoingStatements);
        // sort by modification date, reverse
        Comparator<StatementInfo> comp = Collections.reverseOrder(new StatementInfoComparator());
        Collections.sort(outgoingStatementsInfo, comp);
    }
    return outgoingStatementsInfo;
}

From source file:net.sourceforge.fenixedu.domain.accounting.events.export.SIBSOutgoingPaymentFile.java

public static SIBSOutgoingPaymentFile readLastGeneratedPaymentFile() {
    List<SIBSOutgoingPaymentFile> files = readGeneratedPaymentFiles();
    Collections.sort(files, Collections.reverseOrder(CREATION_DATE_TIME_COMPARATOR));

    return files.iterator().next();
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.phd.CommonPhdIndividualProgramProcessDA.java

public ActionForward viewUnreadAlertMessages(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) {//from   ww  w  . j a  v  a  2 s.c  om

    TreeSet<PhdAlertMessage> orderedMessages = new TreeSet<PhdAlertMessage>(
            Collections.reverseOrder(PhdAlertMessage.COMPARATOR_BY_WHEN_CREATED_AND_ID));
    orderedMessages.addAll(getLoggedPerson(request).getUnreadedPhdAlertMessages());

    request.setAttribute("unread", "true");
    request.setAttribute("alertMessages", orderedMessages);
    return mapping.findForward("viewAlertMessages");
}

From source file:net.sourceforge.fenixedu.domain.accounting.events.export.SIBSOutgoingPaymentFile.java

public static SIBSOutgoingPaymentFile readPreviousOfLastGeneratedPaymentFile() {
    List<SIBSOutgoingPaymentFile> files = readGeneratedPaymentFiles();
    Collections.sort(files, Collections.reverseOrder(CREATION_DATE_TIME_COMPARATOR));

    if (files.size() <= 1) {
        return null;
    }/*from   w w  w.  jav  a 2 s .  co m*/

    return files.get(1);
}

From source file:org.optaplanner.benchmark.impl.result.ProblemBenchmarkResult.java

private void determineRanking(List<SingleBenchmarkResult> rankedSingleBenchmarkResultList) {
    Comparator singleBenchmarkRankingComparator = new SingleBenchmarkRankingComparator();
    Collections.sort(rankedSingleBenchmarkResultList,
            Collections.reverseOrder(singleBenchmarkRankingComparator));
    int ranking = 0;
    SingleBenchmarkResult previousSingleBenchmarkResult = null;
    int previousSameRankingCount = 0;
    for (SingleBenchmarkResult singleBenchmarkResult : rankedSingleBenchmarkResultList) {
        if (previousSingleBenchmarkResult != null && singleBenchmarkRankingComparator
                .compare(previousSingleBenchmarkResult, singleBenchmarkResult) != 0) {
            ranking += previousSameRankingCount;
            previousSameRankingCount = 0;
        }/*from  w w w  .j  av a  2s . c om*/
        singleBenchmarkResult.setRanking(ranking);
        previousSingleBenchmarkResult = singleBenchmarkResult;
        previousSameRankingCount++;
    }
    winningSingleBenchmarkResult = rankedSingleBenchmarkResultList.isEmpty() ? null
            : rankedSingleBenchmarkResultList.get(0);
    worstSingleBenchmarkResult = rankedSingleBenchmarkResultList.isEmpty() ? null
            : rankedSingleBenchmarkResultList.get(rankedSingleBenchmarkResultList.size() - 1);
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.phd.CommonPhdIndividualProgramProcessDA.java

private ActionForward forwardToAlertMessageArchive(ActionMapping mapping, HttpServletRequest request,
        YearMonth yearMonthBean) {
    Integer year = yearMonthBean.getYear();
    if (year == null) {
        year = Integer.valueOf(ExecutionYear.readCurrentExecutionYear().getYear());
    }/*ww  w  .j a v a2s.  c  om*/
    Month month = yearMonthBean.getMonth();

    TreeSet<PhdAlertMessage> orderedMessages = new TreeSet<PhdAlertMessage>(
            Collections.reverseOrder(PhdAlertMessage.COMPARATOR_BY_WHEN_CREATED_AND_ID));
    if (month == null) {
        for (PhdAlertMessage message : getLoggedPerson(request).getPhdAlertMessagesSet()) {
            if (year == message.getWhenCreated().getYear()) {
                orderedMessages.add(message);
            }
        }
    } else {
        for (PhdAlertMessage message : getLoggedPerson(request).getPhdAlertMessagesSet()) {
            if ((year == message.getWhenCreated().getYear())
                    && (month.getNumberOfMonth() == message.getWhenCreated().getMonthOfYear())) {
                orderedMessages.add(message);
            }
        }
    }

    request.setAttribute("yearMonthBean", yearMonthBean);
    request.setAttribute("alertMessages", orderedMessages);
    return mapping.findForward("viewAlertMessageArchive");
}

From source file:org.drools.planner.benchmark.core.DefaultPlannerBenchmark.java

private void determineRanking() {
    List<SolverBenchmark> rankedSolverBenchmarkList = new ArrayList<SolverBenchmark>(solverBenchmarkList);
    // Do not rank a SolverBenchmark that has a failure
    for (Iterator<SolverBenchmark> it = rankedSolverBenchmarkList.iterator(); it.hasNext();) {
        SolverBenchmark solverBenchmark = it.next();
        if (solverBenchmark.hasAnyFailure()) {
            it.remove();// ww  w . ja va2s . c o  m
        }
    }
    if (solverBenchmarkRankingComparator != null) {
        Collections.sort(rankedSolverBenchmarkList, Collections.reverseOrder(solverBenchmarkRankingComparator));
    } else if (solverBenchmarkRankingWeightFactory != null) {
        SortedMap<Comparable, SolverBenchmark> rankedSolverBenchmarkMap = new TreeMap<Comparable, SolverBenchmark>(
                new ReverseComparator());
        for (SolverBenchmark solverBenchmark : rankedSolverBenchmarkList) {
            Comparable rankingWeight = solverBenchmarkRankingWeightFactory
                    .createRankingWeight(rankedSolverBenchmarkList, solverBenchmark);
            Object previous = rankedSolverBenchmarkMap.put(rankingWeight, solverBenchmark);
            if (previous != null) {
                throw new IllegalStateException("The solverBenchmarkList contains 2 times"
                        + " the same solverBenchmark (" + previous + ") and (" + solverBenchmark + ").");
            }
        }
        rankedSolverBenchmarkList.clear();
        rankedSolverBenchmarkList.addAll(rankedSolverBenchmarkMap.values());
    } else {
        throw new IllegalStateException("Ranking is impossible"
                + " because solverBenchmarkRankingComparator and solverBenchmarkRankingWeightFactory are null.");
    }
    int ranking = 0;
    for (SolverBenchmark solverBenchmark : rankedSolverBenchmarkList) {
        solverBenchmark.setRanking(ranking);
        ranking++;
    }
    winningSolverBenchmark = rankedSolverBenchmarkList.isEmpty() ? null : rankedSolverBenchmarkList.get(0);
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.administrativeOffice.scholarship.utl.report.StudentLine.java

public LocalDate getFirstEnrolmentOnCurrentExecutionYear() {
    if (getRegistration() == null) {
        return null;
    }//w ww. j  a v a  2 s.c  o  m

    if (getRegistration().isInMobilityState()) {
        return getForExecutionYear().getBeginDateYearMonthDay().toLocalDate();
    }

    TreeSet<Enrolment> orderedEnrolmentSet = new TreeSet<Enrolment>(
            Collections.reverseOrder(CurriculumModule.COMPARATOR_BY_CREATION_DATE));
    orderedEnrolmentSet.addAll(getStudentCurricularPlan().getEnrolmentsByExecutionYear(getForExecutionYear()));

    return orderedEnrolmentSet.isEmpty() ? null
            : orderedEnrolmentSet.iterator().next().getCreationDateDateTime().toLocalDate();
}