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:com.oneops.transistor.service.BomManagerImpl.java

private SortedMap<Integer, SortedMap<Integer, List<CmsCIRelation>>> getOrderedClouds(
        List<CmsCIRelation> cloudRels, boolean reverse) {

    SortedMap<Integer, SortedMap<Integer, List<CmsCIRelation>>> result = reverse
            ? new TreeMap<Integer, SortedMap<Integer, List<CmsCIRelation>>>(Collections.reverseOrder())
            : new TreeMap<Integer, SortedMap<Integer, List<CmsCIRelation>>>();

    for (CmsCIRelation binding : cloudRels) {

        Integer priority = Integer.valueOf(binding.getAttribute("priority").getDjValue());
        Integer order = 1;//from  w w  w  .jav a2 s .  c  o  m
        if (binding.getAttributes().containsKey("dpmt_order")) {
            order = Integer.valueOf(binding.getAttribute("dpmt_order").getDjValue());
        }
        if (!result.containsKey(priority)) {
            result.put(priority, new TreeMap<Integer, List<CmsCIRelation>>());
        }
        if (!result.get(priority).containsKey(order)) {
            result.get(priority).put(order, new ArrayList<CmsCIRelation>());
        }
        result.get(priority).get(order).add(binding);
    }

    return result;
}

From source file:org.springframework.amqp.rabbit.admin.RabbitBrokerAdmin.java

/**
 * Find a directory whose name starts with a substring in a given parent directory. If there is none return null,
 * otherwise sort the results and return the best match (an exact match if there is one or the last one in a lexical
 * sort).//from w  w  w  .  ja  v a 2s . com
 *
 * @param parent
 * @param child
 * @return the full name of a directory
 */
private String findDirectoryName(String parent, String child) {
    String result = null;
    String[] names = new File(parent).list(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.equals("rabbitmq") && new File(dir, name).isDirectory();
        }
    });
    if (names.length == 1) {
        result = new File(parent, names[0]).getAbsolutePath();
        return result;
    }
    List<String> sorted = Arrays.asList(new File(parent).list(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.startsWith("rabbitmq") && new File(dir, name).isDirectory();
        }
    }));
    Collections.sort(sorted, Collections.reverseOrder());
    if (!sorted.isEmpty()) {
        result = new File(parent, sorted.get(0)).getAbsolutePath();
    }
    return result;
}

From source file:org.tightblog.service.WeblogEntryManager.java

/**
 * Get Weblog Entries grouped by calendar day.
 *
 * @param wesc WeblogEntrySearchCriteria object listing desired search parameters
 * @return Map of Lists of WeblogEntries keyed by calendar day
 *//*from w w w  .  ja  v  a 2s .  c om*/
public Map<LocalDate, List<WeblogEntry>> getDateToWeblogEntryMap(WeblogEntrySearchCriteria wesc) {
    Map<LocalDate, List<WeblogEntry>> map = new TreeMap<>(Collections.reverseOrder());

    List<WeblogEntry> entries = getWeblogEntries(wesc);

    for (WeblogEntry entry : entries) {
        entry.setCommentRepository(weblogEntryCommentRepository);
        LocalDate tmp = entry.getPubTime() == null ? LocalDate.now()
                : entry.getPubTime().atZone(ZoneId.systemDefault()).toLocalDate();
        List<WeblogEntry> dayEntries = map.computeIfAbsent(tmp, k -> new ArrayList<>());
        dayEntries.add(entry);
    }
    return map;
}

From source file:org.codehaus.mojo.sql.SqlExecMojo.java

/**
 * Sort the transaction list.//from   ww w  .  j av a2s . c om
 */
private void sortTransactions() {
    if (FILE_SORTING_ASC.equalsIgnoreCase(this.orderFile)) {
        Collections.sort(transactions);
    } else if (FILE_SORTING_DSC.equalsIgnoreCase(this.orderFile)) {
        Collections.sort(transactions, Collections.reverseOrder());
    }
}

From source file:hudson.plugins.jobConfigHistory.FileHistoryDao.java

/**
 * Determines if the {@link XmlFile} contains a duplicate of
 * the last saved information, if there is previous history.
 *
 * @param xmlFile//  w w w.  ja  v  a2s .c  o  m
 *           The {@link XmlFile} configuration file under consideration.
 * @return true if previous history is accessible, and the file duplicates the previously saved information.
 */
boolean hasDuplicateHistory(XmlFile xmlFile) {
    boolean isDuplicated = false;
    final ArrayList<String> timeStamps = new ArrayList<String>(getRevisions(xmlFile).keySet());
    if (!timeStamps.isEmpty()) {
        Collections.sort(timeStamps, Collections.reverseOrder());
        final XmlFile lastRevision = getOldRevision(xmlFile, timeStamps.get(0));
        try {
            if (xmlFile.asString().equals(lastRevision.asString())) {
                isDuplicated = true;
            }
        } catch (IOException e) {
            LOG.log(Level.WARNING, "unable to check for duplicate previous history file: {0}\n{1}",
                    new Object[] { lastRevision, e });
        }
    }
    return isDuplicated;
}

From source file:uk.co.armedpineapple.cth.SDLActivity.java

public void startApp() {
    // Start up the C app thread

    if (mSDLThread == null) {

        List<FileDetails> saves = null;
        try {//  w w w .j a  v  a2  s .  c o m
            saves = Files.listFilesInDirectory(app.configuration.getSaveGamesPath(), new FilenameFilter() {

                @Override
                public boolean accept(File dir, String filename) {
                    return filename.toLowerCase(Locale.US).endsWith(".sav");
                }
            });
        } catch (IOException e) {
        }

        if (saves != null && saves.size() > 0) {
            Collections.sort(saves, Collections.reverseOrder());

            final String loadPath = saves.get(0).getFileName();

            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage(R.string.load_last_save);
            builder.setCancelable(false);
            builder.setPositiveButton(R.string.yes, new Dialog.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {

                    mSDLThread = new Thread(new SDLMain(app.configuration, loadPath), "SDLThread");
                    mSDLThread.start();
                }

            });
            builder.setNegativeButton(R.string.no, new Dialog.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    mSDLThread = new Thread(new SDLMain(app.configuration, ""), "SDLThread");
                    mSDLThread.start();
                }

            });
            builder.create().show();

        } else {

            mSDLThread = new Thread(new SDLMain(app.configuration, ""), "SDLThread");
            mSDLThread.start();
        }

    }
}

From source file:com.javielinux.utils.Utils.java

static public String toHTML(Context context, String text, String underline) {
    String out = text.replace("<", "&lt;");
    //out = out.replace(">", "&gt;");
    ArrayList<Integer> valStart = new ArrayList<Integer>();
    ArrayList<Integer> valEnd = new ArrayList<Integer>();

    Comparator<Integer> comparator = Collections.reverseOrder();

    // enlaces/*www.ja v  a2 s  .  c om*/

    String regex = "\\(?\\b(http://|https://|www[.])[-A-Za-z0-9+&@#/%?=~_()|!:,.;]*[-A-Za-z0-9+&@#/%=~_()|]";
    Pattern p = Pattern.compile(regex);
    Matcher m = p.matcher(out);
    while (m.find()) {
        valStart.add(m.start());
        valEnd.add(m.end());
    }

    // hashtag

    regex = "(#[\\w-]+)";
    p = Pattern.compile(regex);
    m = p.matcher(out);
    while (m.find()) {
        valStart.add(m.start());
        valEnd.add(m.end());
    }

    // usuarios twitter

    regex = "(@[\\w-]+)";
    p = Pattern.compile(regex);
    m = p.matcher(out);
    while (m.find()) {
        valStart.add(m.start());
        valEnd.add(m.end());
    }

    ThemeManager theme = new ThemeManager(context);

    String tweet_color_link = theme.getStringColor("tweet_color_link");
    String tweet_color_hashtag = theme.getStringColor("tweet_color_hashtag");
    String tweet_color_user = theme.getStringColor("tweet_color_user");

    Collections.sort(valStart, comparator);
    Collections.sort(valEnd, comparator);

    for (int i = 0; i < valStart.size(); i++) {
        int s = valStart.get(i);
        int e = valEnd.get(i);
        String link = out.substring(s, e);
        if (link.equals(underline)) {
            link = "<u>" + out.substring(s, e) + "</u>";
        }
        if (out.substring(s, s + 1).equals("#")) {
            out = out.substring(0, s) + "<font color=\"#" + tweet_color_hashtag + "\">" + link + "</font>"
                    + out.substring(e, out.length());
        } else if (out.substring(s, s + 1).equals("@")) {
            out = out.substring(0, s) + "<font color=\"#" + tweet_color_user + "\">" + link + "</font>"
                    + out.substring(e, out.length());
        } else {
            out = out.substring(0, s) + "<font color=\"#" + tweet_color_link + "\">" + link + "</font>"
                    + out.substring(e, out.length());
        }
    }

    return out;
}

From source file:languages.TabFile.java

public void sortDescending(int sortKey) {
    setSortKey(sortKey);
    values.sort(Collections.reverseOrder());
}

From source file:org.apache.nifi.registry.service.extension.StandardExtensionService.java

private SortedSet<ExtensionBundleVersionMetadata> getExtensionBundleVersionsSet(
        final ExtensionBundleEntity existingBundle) {
    final SortedSet<ExtensionBundleVersionMetadata> sortedVersions = new TreeSet<>(Collections.reverseOrder());

    final List<ExtensionBundleVersionEntity> existingVersions = metadataService
            .getExtensionBundleVersions(existingBundle.getId());
    if (existingVersions != null) {
        existingVersions.stream().forEach(s -> sortedVersions.add(DataModelMapper.map(s)));
    }/*from  w  w w .j  a  va  2s  .  co  m*/
    return sortedVersions;
}

From source file:com.mahali.gpslogger.MainActivity.java

public ArrayList<GPSSession> loadGPSSessions() {
    Log.i(TAG, "loadGPSSessions");
    File gps_files[] = dirFile.listFiles();

    ArrayList<GPSSession> sessions = new ArrayList<GPSSession>();

    for (int i = 0; i < gps_files.length; i++) {
        File f = gps_files[i];//from  w ww .  j  a v  a2  s. c o m
        String fileName = f.getName();

        if (verifyFileType(fileName)) {
            sessions.add(new GPSSession(fileName, f.getAbsolutePath(), f.length()));
        }
    }

    // Reverse order so most recent session is at top of list
    Comparator<GPSSession> c = Collections.reverseOrder();
    Collections.sort(sessions, c);

    return sessions;
}