List of usage examples for java.util Collections reverseOrder
@SuppressWarnings("unchecked") public static <T> Comparator<T> reverseOrder(Comparator<T> cmp)
From source file:org.optaplanner.benchmark.impl.result.PlannerBenchmarkResult.java
private List<List<SolverBenchmarkResult>> createSameRankingListList(BenchmarkReport benchmarkReport, List<SolverBenchmarkResult> rankableSolverBenchmarkResultList) { List<List<SolverBenchmarkResult>> sameRankingListList = new ArrayList<List<SolverBenchmarkResult>>( rankableSolverBenchmarkResultList.size()); if (benchmarkReport.getSolverRankingComparator() != null) { Comparator<SolverBenchmarkResult> comparator = Collections .reverseOrder(benchmarkReport.getSolverRankingComparator()); Collections.sort(rankableSolverBenchmarkResultList, comparator); List<SolverBenchmarkResult> sameRankingList = null; SolverBenchmarkResult previousSolverBenchmarkResult = null; for (SolverBenchmarkResult solverBenchmarkResult : rankableSolverBenchmarkResultList) { if (previousSolverBenchmarkResult == null || comparator.compare(previousSolverBenchmarkResult, solverBenchmarkResult) != 0) { // New rank sameRankingList = new ArrayList<SolverBenchmarkResult>(); sameRankingListList.add(sameRankingList); }//from ww w . j av a 2s .c o m sameRankingList.add(solverBenchmarkResult); previousSolverBenchmarkResult = solverBenchmarkResult; } } else if (benchmarkReport.getSolverRankingWeightFactory() != null) { SortedMap<Comparable, List<SolverBenchmarkResult>> rankedMap = new TreeMap<Comparable, List<SolverBenchmarkResult>>( Collections.reverseOrder()); for (SolverBenchmarkResult solverBenchmarkResult : rankableSolverBenchmarkResultList) { Comparable rankingWeight = benchmarkReport.getSolverRankingWeightFactory() .createRankingWeight(rankableSolverBenchmarkResultList, solverBenchmarkResult); List<SolverBenchmarkResult> sameRankingList = rankedMap.get(rankingWeight); if (sameRankingList == null) { sameRankingList = new ArrayList<SolverBenchmarkResult>(); rankedMap.put(rankingWeight, sameRankingList); } sameRankingList.add(solverBenchmarkResult); } for (Map.Entry<Comparable, List<SolverBenchmarkResult>> entry : rankedMap.entrySet()) { sameRankingListList.add(entry.getValue()); } } else { throw new IllegalStateException("Ranking is impossible" + " because solverRankingComparator and solverRankingWeightFactory are null."); } return sameRankingListList; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.phd.CommonPhdIndividualProgramProcessDA.java
public ActionForward viewUnreadProcessAlertMessages(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { TreeSet<PhdAlertMessage> orderedMessages = new TreeSet<PhdAlertMessage>( Collections.reverseOrder(PhdAlertMessage.COMPARATOR_BY_WHEN_CREATED_AND_ID)); orderedMessages.addAll(getProcess(request).getUnreadAlertMessagesForLoggedPerson()); request.setAttribute("unread", "true"); request.setAttribute("alertMessages", orderedMessages); return mapping.findForward("viewProcessAlertMessages"); }
From source file:org.optaplanner.benchmark.impl.result.SingleBenchmarkResult.java
private void determineRanking(List<SubSingleBenchmarkResult> rankedSubSingleBenchmarkResultList) { Comparator subSingleBenchmarkRankingComparator = new SubSingleBenchmarkRankingComparator(); Collections.sort(rankedSubSingleBenchmarkResultList, Collections.reverseOrder(subSingleBenchmarkRankingComparator)); int ranking = 0; SubSingleBenchmarkResult previousSubSingleBenchmarkResult = null; int previousSameRankingCount = 0; for (SubSingleBenchmarkResult subSingleBenchmarkResult : rankedSubSingleBenchmarkResultList) { if (previousSubSingleBenchmarkResult != null && subSingleBenchmarkRankingComparator .compare(previousSubSingleBenchmarkResult, subSingleBenchmarkResult) != 0) { ranking += previousSameRankingCount; previousSameRankingCount = 0; }//from w w w . java2 s . c o m subSingleBenchmarkResult.setRanking(ranking); previousSubSingleBenchmarkResult = subSingleBenchmarkResult; previousSameRankingCount++; } }
From source file:org.sakaiproject.site.tool.EnrolmentsHandler.java
/** * Sort the given list of Enrolments by term. This sort is multi-factored: * First on start date of the term (Academic Session), secondly on section title. * //from w ww. j a va 2s. c o m * @param list the list of Enrolments to be sorted * @param sortAsc true if sorting ascending; false otherwise * @return the sorted list */ private List<Enrolment> sortByTerm(List<Enrolment> list, boolean sortAsc) { // Get a copy of the sessions (ordered by start date by default); reverse sort if necessary List<AcademicSession> sessions = new ArrayList<>(SESSION_HELPER.getSessions()); if (!sortAsc) { Collections.reverse(sessions); } // Create a bucket for each session Map<String, List<Enrolment>> buckets = new HashMap<>(); for (AcademicSession session : sessions) { buckets.put(session.getEid(), new ArrayList<>()); } // Sort the SectionWrapper objects into the buckets for (Enrolment wrapper : list) { buckets.get(wrapper.getSessionEID()).add(wrapper); } // Sort each bucket by the section title; rebuild the list now that everything is sorted List<Enrolment> retVal = new ArrayList<>(); for (AcademicSession session : sessions) { Collections.sort(buckets.get(session.getEid()), sortAsc ? SECTION_COMP : Collections.reverseOrder(SECTION_COMP)); retVal.addAll(buckets.get(session.getEid())); } return retVal; }
From source file:org.libreplan.business.planner.entities.EffortDistributor.java
private List<ResourceWithAvailableCapacity> resourcesFromMoreDesirableToLess( List<ResourceWithDerivedData> resourcesAssignable, PartialDay day) { List<ResourceWithAvailableCapacity> result = new ArrayList<>(); for (ResourceWithDerivedData each : resourcesAssignable) { result.add(each.withAvailableCapacityOn(day, assignedEffortForResource)); }//from w ww .j ava2 s . c om Collections.sort(result, Collections .reverseOrder(ResourceWithAvailableCapacity.getComparatorConsidering(resourcesAlreadyPicked))); return result; }
From source file:net.sourceforge.fenixedu.domain.candidacyProcess.mobility.MobilityIndividualApplicationProcess.java
public List<ErasmusAlert> getAlertsNotViewed() { List<ErasmusAlert> alertsNotViewed = new ArrayList<ErasmusAlert>(); CollectionUtils.select(getAlertSet(), arg0 -> { ErasmusAlert alert = (ErasmusAlert) arg0; return alert.isToFire(); }, alertsNotViewed);// w w w . j a v a 2s . c o m Collections.sort(alertsNotViewed, Collections.reverseOrder(ErasmusAlert.WHEN_CREATED_COMPARATOR)); return alertsNotViewed; }
From source file:net.sourceforge.fenixedu.domain.candidacyProcess.mobility.MobilityIndividualApplicationProcess.java
public ErasmusAlert getMostRecentAlert() { List<ErasmusAlert> alerts = new ArrayList<ErasmusAlert>(getAlertSet()); Collections.sort(alerts, Collections.reverseOrder(ErasmusAlert.WHEN_CREATED_COMPARATOR)); return alerts.iterator().next(); }
From source file:org.optaplanner.benchmark.impl.DefaultPlannerBenchmark.java
private List<List<SolverBenchmark>> createSameRankingListList( List<SolverBenchmark> rankableSolverBenchmarkList) { List<List<SolverBenchmark>> sameRankingListList = new ArrayList<List<SolverBenchmark>>( rankableSolverBenchmarkList.size()); if (solverBenchmarkRankingComparator != null) { Comparator<SolverBenchmark> comparator = Collections.reverseOrder(solverBenchmarkRankingComparator); Collections.sort(rankableSolverBenchmarkList, comparator); List<SolverBenchmark> sameRankingList = null; SolverBenchmark previousSolverBenchmark = null; for (SolverBenchmark solverBenchmark : rankableSolverBenchmarkList) { if (previousSolverBenchmark == null || comparator.compare(previousSolverBenchmark, solverBenchmark) != 0) { // New rank sameRankingList = new ArrayList<SolverBenchmark>(); sameRankingListList.add(sameRankingList); }//from w w w.j a v a2 s .com sameRankingList.add(solverBenchmark); previousSolverBenchmark = solverBenchmark; } } else if (solverBenchmarkRankingWeightFactory != null) { SortedMap<Comparable, List<SolverBenchmark>> rankedMap = new TreeMap<Comparable, List<SolverBenchmark>>( new ReverseComparator()); for (SolverBenchmark solverBenchmark : rankableSolverBenchmarkList) { Comparable rankingWeight = solverBenchmarkRankingWeightFactory .createRankingWeight(rankableSolverBenchmarkList, solverBenchmark); List<SolverBenchmark> sameRankingList = rankedMap.get(rankingWeight); if (sameRankingList == null) { sameRankingList = new ArrayList<SolverBenchmark>(); rankedMap.put(rankingWeight, sameRankingList); } sameRankingList.add(solverBenchmark); } for (Map.Entry<Comparable, List<SolverBenchmark>> entry : rankedMap.entrySet()) { sameRankingListList.add(entry.getValue()); } } else { throw new IllegalStateException("Ranking is impossible" + " because solverBenchmarkRankingComparator and solverBenchmarkRankingWeightFactory are null."); } return sameRankingListList; }
From source file:org.artifactory.build.BuildServiceImpl.java
@Override public List<BuildRun> getAllPreviousBuilds(String buildName, String buildNumber, String buildStarted) { final BuildRun currentBuildRun = getTransactionalMe().getBuildRun(buildName, buildNumber, buildStarted); Set<BuildRun> buildRuns = searchBuildsByName(buildName); final Comparator<BuildRun> buildNumberComparator = BuildRunComparators.getBuildStartDateComparator(); Iterables.removeIf(buildRuns, new Predicate<BuildRun>() { @Override//w w w . ja v a2s . co m public boolean apply(@Nullable BuildRun input) { // Remove all builds equals or after the current one return buildNumberComparator.compare(currentBuildRun, input) <= 0; } }); List<BuildRun> buildRunsList = Lists.newArrayList(buildRuns); Comparator<BuildRun> reverseComparator = Collections.reverseOrder(buildNumberComparator); Collections.sort(buildRunsList, reverseComparator); return buildRunsList; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.phd.CommonPhdIndividualProgramProcessDA.java
private ActionForward forwardToProcessAlertMessageArchive(ActionMapping mapping, HttpServletRequest request, YearMonth yearMonthBean) throws NumberFormatException { Integer year = yearMonthBean.getYear(); if (year == null) { year = Integer.valueOf(ExecutionYear.readCurrentExecutionYear().getYear()); }/* ww w .j av a2s. co m*/ 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 : getProcess(request).getAlertMessagesForLoggedPerson()) { if (year == message.getWhenCreated().getYear()) { orderedMessages.add(message); } } } else { for (PhdAlertMessage message : getProcess(request).getAlertMessagesForLoggedPerson()) { if ((year == message.getWhenCreated().getYear()) && (month.getNumberOfMonth() == message.getWhenCreated().getMonthOfYear())) { orderedMessages.add(message); } } } request.setAttribute("yearMonthBean", yearMonthBean); request.setAttribute("alertMessages", orderedMessages); return mapping.findForward("viewProcessAlertMessageArchive"); }