Example usage for java.util Collections sort

List of usage examples for java.util Collections sort

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public static <T extends Comparable<? super T>> void sort(List<T> list) 

Source Link

Document

Sorts the specified list into ascending order, according to the Comparable natural ordering of its elements.

Usage

From source file:net.daboross.bukkitdev.skywars.game.GenericTimer.java

public GenericTimer(Plugin plugin, List<TaskDefinition> tasksBeforeFinish, boolean runTaskAsync) {
    this.plugin = plugin;
    this.runTaskAsync = runTaskAsync;
    List<TaskDefinition> tasks = new ArrayList<>(tasksBeforeFinish);
    Collections.sort(tasks);
    this.firstTask = new TaskChainPart(tasks);
}

From source file:com.dangdang.config.service.NodeService.java

@Override
public List<String> listChildren(String node) {
    List<String> children = nodeDao.listChildren(node);
    if (children != null) {
        Collections.sort(children);
    }//  w  w  w  .  j  a  v  a2s  .  c  o  m
    return children;
}

From source file:edu.cuhk.hccl.IDConverter.java

private static void processFile(File inFile, File outFile) throws IOException {
    List<String> lines = FileUtils.readLines(inFile, "UTF-8");
    List<String> buffer = new ArrayList<String>();

    for (String line : lines) {
        String[] cols = line.split("\t");

        cols[0] = String.valueOf(mapping.getUserID(cols[0]));
        cols[1] = String.valueOf(mapping.getItemID(cols[1]));

        buffer.add(StringUtils.join(cols, '\t'));
    }//from   w  ww. ja  va2 s .  c  o  m

    Collections.sort(buffer);
    FileUtils.writeLines(outFile, buffer, false);

    System.out.printf("ID Converting finished for file: %s.\n", inFile.getAbsolutePath());
}

From source file:edu.ucla.cs.scai.swim.qa.ontology.dbpedia.tipicality.Test.java

private static ArrayList<String> rankedCategories(HashSet<String> chosenAttributes) {
    ArrayList<Pair> topKcategories = new ArrayList<>();
    for (String category : categories) {
        Integer cc = categoryCount.get(category); //number of instances in this category
        if (cc == null) {
            continue;
        }//from ww w .j  a  v a  2s  .  c o m
        double p = 1.0 * cc / n;
        double invcc = 1.0 / (cc + 0.5 * attributes.size());
        for (String a : chosenAttributes) {
            Integer pac = categoryAttributeCount.get(category).get(a);
            if (pac != null) {
                p *= (pac + 0.5) * invcc;
            } else {
                p *= 0.5 * invcc;
            }
        }
        if (topKcategories.size() < topCategories) {
            topKcategories.add(new Pair(category, p));
            Collections.sort(topKcategories);
        } else if (p > topKcategories.get(topCategories - 1).p) {
            topKcategories.set(topCategories - 1, new Pair(category, p));
            Collections.sort(topKcategories);
        }
    }
    ArrayList<String> rankedCategories = new ArrayList<>();
    for (Pair p : topKcategories) {
        rankedCategories.add(p.s);
    }
    return rankedCategories;
}

From source file:com.alibaba.openapi.client.util.InvokeUtil.java

private static String signature(List<String> paramValueList, String secretKey, String signatureDataPref) {
    final StringBuilder sb = signatureDataPref == null ? new StringBuilder()
            : new StringBuilder(signatureDataPref);
    Collections.sort(paramValueList);
    for (String paramValue : paramValueList) {
        sb.append(paramValue);//from   ww w  .ja  v  a 2s .  c  om
    }
    return SignatureUtil.hmacSha1ToHexStr(SignatureUtil.toBytes(sb.toString()),
            SignatureUtil.buildKey(SignatureUtil.toBytes(secretKey)));
}

From source file:com.richtodd.android.quiltdesign.block.ThemeContainer.java

public List<ThemeContainerEntry> getEntries(boolean loadThumbnails) throws RepositoryException {

    ArrayList<ThemeContainerEntry> m_entries = new ArrayList<ThemeContainerEntry>();

    for (RepositoryObjectProvider objectProvider : m_provider.getObjects(loadThumbnails)) {
        ThemeContainerEntry entry = new ThemeContainerEntry(objectProvider.getObjectName(),
                objectProvider.getLastChangedDate(), objectProvider.getThumbnail());
        m_entries.add(entry);/*from ww w .  ja va 2  s .co m*/
    }

    Collections.sort(m_entries);

    return m_entries;
}

From source file:gov.usgs.anss.query.MSOutputer.java

public void makeFile(NSCL nscl, String filename, ArrayList<MiniSeed> blks) throws IOException {
    MiniSeed ms2 = null;//from  w w w  . j  ava2s  .  c  o m
    if (options.filemask.equals("%N")) {
        filename += ".ms";
    }
    filename = filename.replaceAll("[__]", "_");
    FileOutputStream out = FileUtils.openOutputStream(new File(filename));
    if (!options.nosort) {
        Collections.sort(blks);
    }
    if (options.chkDups) {
        for (int i = blks.size() - 1; i > 0; i--) {
            if (blks.get(i).isDuplicate(blks.get(i - 1))) {
                blks.remove(i);
            }
        }
    }

    for (int i = 0; i < blks.size(); i++) {
        ms2 = (MiniSeed) blks.get(i);

        logger.fine("Out:" + ms2.getSeedName() + " " + ms2.getTimeString() + " ns=" + ms2.getNsamp() + " rt="
                + ms2.getRate());

        out.write(ms2.getBuf(), 0, ms2.getBlockSize());
    }
    out.close();
}

From source file:com.edmunds.etm.tools.urltoken.application.CommandLocator.java

public List<String> getNames() {
    List<String> names = new ArrayList<String>(commandsByName.keySet());
    Collections.sort(names);
    return names;
}

From source file:com.elogiclab.vosao.plugin.FlickrUtils.java

public static String buildQueryString(Map<String, String> params, String apiSecret) {
    StringBuilder result = new StringBuilder();
    StringBuffer unencoded = new StringBuffer(apiSecret);
    List keyList = new ArrayList(params.keySet());
    Collections.sort(keyList);
    Iterator it = keyList.iterator();
    while (it.hasNext()) {
        if (result.length() > 0) {
            result.append("&");
        }//from  w  ww.  jav a 2 s. c om
        String key = it.next().toString();
        result.append(key);
        result.append("=");
        result.append(params.get(key));
        unencoded.append(key);
        unencoded.append(params.get(key));
    }
    System.out.println(unencoded);

    String sig = digest(unencoded.toString());
    result.append("&api_sig=");
    result.append(sig);
    return result.toString();

}

From source file:de.pawlidi.openaletheia.utils.CipherUtils.java

/**
 * /*from w  ww .j  a v  a 2  s  .  c  o m*/
 * @param properties
 * @return
 */
public static byte[] computeSignature(Properties properties) {
    if (properties != null && !properties.isEmpty()) {
        StringBuilder builder = new StringBuilder();
        ArrayList keys = new ArrayList<Object>(properties.keySet());
        Collections.sort(keys);
        for (Object key : keys) {
            Object value = properties.get(key);
            if (value != null) {
                builder.append(key);
                builder.append("=");
                builder.append(value);
                builder.append("\n");
            }
        }
        String pattern = builder.toString();
        if (!pattern.isEmpty()) {
            return computeSignature(Converter.getBytesIso8859(pattern));
        }
    }
    return null;
}