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() 

Source Link

Document

Returns a comparator that imposes the reverse of the natural ordering on a collection of objects that implement the Comparable interface.

Usage

From source file:marshalsec.gadgets.CommonsBeanutils.java

@Primary
@Args(minArgs = 1, args = { "jndiUrl" }, defaultArgs = { MarshallerBase.defaultJNDIUrl })
default Object makeCommonsBeanutilsJNDI(UtilFactory uf, String... args) throws Exception {
    BeanComparator<Object> cmp = new BeanComparator<>("lowestSetBit", Collections.reverseOrder());
    Object trig = uf.makeComparatorTrigger(JDKUtil.makeJNDIRowSet(args[0]), cmp);
    Reflections.setFieldValue(cmp, "property", "databaseMetaData");
    return trig;/*w  w w . java 2 s  .c  om*/
}

From source file:org.openmrs.module.rwandaprimarycare.AllEncountersController.java

@RequestMapping("/module/rwandaprimarycare/allEncounters")
public String listAllEncounters(@RequestParam("patientId") int patientId, ModelMap model)
        throws PrimaryCareException {

    //LK: Need to ensure that all primary care methods only throw a PrimaryCareException
    //So that errors will be directed to a touch screen error page
    try {//from w  w  w .  jav  a  2s.c om
        Patient patient = Context.getPatientService().getPatient(patientId);
        SortedMap<Date, List<Encounter>> encounters = new TreeMap<Date, List<Encounter>>(
                Collections.reverseOrder());
        for (Encounter e : Context.getEncounterService().getEncountersByPatient(patient)) {
            Calendar cal = Calendar.getInstance();
            cal.setTime(e.getEncounterDatetime());
            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);
            cal.set(Calendar.MILLISECOND, 0);
            Date day = cal.getTime();
            List<Encounter> holder = encounters.get(day);
            if (holder == null) {
                holder = new ArrayList<Encounter>();
                encounters.put(day, holder);
            }
            holder.add(e);
        }
        model.addAttribute("patient", patient);
        model.addAttribute("encounters", encounters);
        model.addAttribute("vitalsEncounterType", PrimaryCareBusinessLogic.getVitalsEncounterType());
        model.addAttribute("registrationEncounterType",
                PrimaryCareBusinessLogic.getRegistrationEncounterType());
    } catch (Exception e) {
        throw new PrimaryCareException(e);
    }
    return "/module/rwandaprimarycare/allEncounters";
}

From source file:ispyb.common.util.IspybFileUtils.java

/**
 * returns the list of files in the given directoryFile (and sub-directories) with the given fileName
 * /*from   w w w.  j  a  va  2  s .  c  o m*/
 * @param directoryFile
 * @param fileName
 * @return
 */
public static List<File> getListFile(File directoryFile, String fileName) {
    List<File> resultFilesList = new ArrayList<File>();
    if (directoryFile == null)
        return resultFilesList;
    // File[] list = directoryFile.listFiles();
    List<File> listFile = Arrays.asList(directoryFile.listFiles());
    Collections.sort(listFile, Collections.reverseOrder());
    if (listFile != null) {
        for (int k = 0; k < listFile.size(); k++) {
            if (listFile.get(k).isFile() && listFile.get(k).getName().equals(fileName)) {
                resultFilesList.add(listFile.get(k));
            } else if (listFile.get(k).isDirectory()) {
                List<File> subList = getListFile(listFile.get(k), fileName);
                resultFilesList.addAll(subList);
            }
        }
    }
    return resultFilesList;
}

From source file:org.kuali.kpme.tklm.common.CalendarFormAction.java

protected void setCalendarFields(HttpServletRequest request, CalendarForm calendarForm) {
    Set<String> calendarYears = new TreeSet<String>(Collections.reverseOrder());
    List<CalendarEntry> calendarEntries = getCalendarEntries(calendarForm.getCalendarEntry());

    for (CalendarEntry calendarEntry : calendarEntries) {
        String calendarEntryYear = calendarEntry.getBeginPeriodFullDateTime().toString("yyyy");
        calendarYears.add(calendarEntryYear);
    }/*from   w  ww .  ja v  a2  s.c om*/

    String currentCalendarYear = calendarForm.getCalendarEntry().getBeginPeriodFullDateTime().toString("yyyy");
    String selectedCalendarYear = StringUtils.isNotBlank(calendarForm.getSelectedCalendarYear())
            ? calendarForm.getSelectedCalendarYear()
            : currentCalendarYear;

    calendarForm.setCalendarYears(new ArrayList<String>(calendarYears));
    calendarForm.setPayPeriodsMap(ActionFormUtils.getPayPeriodsMap(
            ActionFormUtils.getAllCalendarEntriesForYear(calendarEntries, selectedCalendarYear), null));

    calendarForm.setSelectedCalendarYear(selectedCalendarYear);
    calendarForm.setSelectedPayPeriod(calendarForm.getCalendarEntry().getHrCalendarEntryId());
}

From source file:femr.util.DataStructure.Mapping.AbstractMultiMap.java

/**
 * Gets a list of Date Keys and sorts them in descending order
 *
 * @return A List of dates as type string
 *//*w w w  .ja  v  a2s.c  o  m*/
public List<String> getDateList() {
    Collections.sort(dateList, Collections.reverseOrder());
    return dateList;
}

From source file:com.mycompany.listBoxer.services.impl.ListBoxerServiceImpl.java

@Override
public List<String> getByCriteria(SelectionCriteria selCriteria) {
    /*//from   ww w .ja  v  a  2s.  c o m
     * According to FilterMockitoTest
     * 
     * 1.get elements by range (first letter)
     * 
     * 2.do alphabetic/numeric (!!! move to listener) check and filter list
     * according to it
     * 
     * 3.apply assortment
     */
    List<String> rangeList = getElementsByRange(getContent(), selCriteria);

    if (selCriteria.getAsc())
        Collections.sort(rangeList, new IntegerComparator());
    else if (selCriteria.getDesc())
        Collections.sort(rangeList, Collections.reverseOrder());

    return rangeList;
}

From source file:com.graphaware.reco.generic.result.Recommendations.java

/**
 * Get a list of recommendation ordered by decreasing score (relevance).
 *
 * @param limit the maximum number of recommendations to get.
 * @return list of recommendations paired with their composite scores, ordered by decreasing relevance.
 *//*from   w  w w .  ja  v a2s.  c o  m*/
public List<Recommendation<OUT>> get(int limit) {
    List<Recommendation<OUT>> result = new LinkedList<>(scoredItems.values());

    Collections.sort(result, Collections.reverseOrder());

    return result.subList(0, Math.min(limit, result.size()));
}

From source file:com.poloure.simplerss.AsyncNewTagAdapters.java

@Override
protected TreeMap<Long, FeedItem>[] doInBackground(Void... nothing) {
    String[] tags = PagerAdapterTags.s_tagList.toArray(new String[PagerAdapterTags.s_tagList.size()]);

    TreeMap<Long, FeedItem>[] maps = new TreeMap[tags.length];
    for (int i = 0; tags.length > i; i++) {
        maps[i] = new TreeMap<Long, FeedItem>(Collections.reverseOrder());
    }//from w  w w .j av  a  2s  .  c  om

    // For each feed.
    for (IndexItem indexItem : m_activity.m_index) {
        // Get a list of tags that this feed belongs to.
        List<String> feedsTags = Arrays.asList(indexItem.m_tags);

        // Load the data from file.
        ObjectIO reader = new ObjectIO(m_activity, Long.toString(indexItem.m_uid));
        Map<Long, FeedItem> tempMap = (Map<Long, FeedItem>) reader.read();

        // In case the user is still using the old -content.txt file name.
        if (new File(m_activity.getFilesDir(), indexItem.m_uid + "-content.txt").exists()) {
            reader = new ObjectIO(m_activity, indexItem.m_uid + "-content.txt");
            tempMap = (Map<Long, FeedItem>) reader.read();
            m_activity.deleteFile(indexItem.m_uid + "-content.txt");

            ObjectIO writer = new ObjectIO(m_activity, Long.toString(indexItem.m_uid));
            writer.write(tempMap);
        }

        // Put the item in each map that the feed is tagged with.
        if (null != tempMap) {
            for (int j = 0; tags.length > j; j++) {
                if (0 == j || feedsTags.contains(tags[j])) {
                    maps[j].putAll(tempMap);
                }
            }
        }
    }
    return maps;
}

From source file:de.kasoki.jfeedly.model.Entries.java

/** Sort articles by date, the newest one comes first */
public void sortByDateNewestFirst() {
    Collections.sort(entries, Collections.reverseOrder());
}

From source file:org.mycontroller.standalone.jobs.SystemBackupJob.java

private void removeOldFiles(BackupSettings backupSettings) throws IOException {
    String[] filter = { "zip" };
    Collection<File> zipFiles = FileUtils.listFiles(
            FileUtils.getFile(AppProperties.getInstance().getBackupSettings().getBackupLocation()), filter,
            true);/*from  w w  w . j  av  a2  s  .  c  om*/

    List<BackupFile> backupFiles = new ArrayList<BackupFile>();
    for (File zipFile : zipFiles) {
        if (zipFile.getName().startsWith(backupSettings.getPrefix())) {//Filter with file name
            backupFiles.add(BackupFile.builder().name(zipFile.getName()).size(zipFile.length())
                    .timestamp(zipFile.lastModified()).canonicalPath(zipFile.getCanonicalPath()).build());
        }
    }
    //Do order reverse
    Collections.sort(backupFiles, Collections.reverseOrder());

    if (backupFiles.size() > backupSettings.getRetainMax()) {
        _logger.debug("Available backup files:{}, Maximum files retain:{}", backupFiles.size(),
                backupSettings.getRetainMax());
        for (int deleteIndex = backupSettings.getRetainMax(); deleteIndex < backupFiles.size(); deleteIndex++) {
            try {
                FileUtils.forceDelete(FileUtils.getFile(backupFiles.get(deleteIndex).getCanonicalPath()));
                _logger.debug("Backup file deleted, {}", backupFiles.get(deleteIndex));
            } catch (Exception ex) {
                _logger.error("Backup file deletion failed", ex);
            }
        }
    } else {
        _logger.debug("Available backup files:{}", backupFiles.size());
    }
}