List of usage examples for java.util Collections sort
@SuppressWarnings("unchecked") public static <T extends Comparable<? super T>> void sort(List<T> list)
From source file:Main.java
/** * Compares the content of the two list, no matter how they are ordered * @param test the list containing items to check * @param control the list containing the expected values * @return {@code true}// ww w . j a va 2 s . c o m */ public static <T extends Comparable<? super T>> boolean containsInAnyOrder(final List<T> test, final List<T> control) { if (test == null || control == null) { return false; } if (test.size() != control.size()) { return false; } final List<T> orderedControl = new LinkedList<T>(control); Collections.sort(orderedControl); final List<T> orderedTest = new LinkedList<T>(test); Collections.sort(orderedTest); final Iterator<T> testIterator = orderedTest.iterator(); for (Iterator<T> controlIterator = orderedControl.iterator(); controlIterator.hasNext();) { T controlItem = controlIterator.next(); T testItem = testIterator.next(); if (testItem == null || !testItem.equals(controlItem)) { return false; } } return true; }
From source file:Main.java
public static <T extends Comparable<T>> ArrayList<T> toSortedArrayList(Iterable<? extends T> i) { ArrayList<T> result = toArrayList(i); Collections.sort(result); return result; }
From source file:com.webarch.common.lang.Digest.java
/** * ??????//from www . j a v a 2 s. c o m * * @param values ? * @return ???? */ public static String generateSourceString(String... values) { List<String> list = Arrays.asList(values); Collections.sort(list); return StringUtils.join(list, ""); }
From source file:Main.java
public static <E extends Comparable<? super E>> List<E> sorted(Collection<E> col) { final List<E> list = new ArrayList<>(col); Collections.sort(list); return list;//from w w w .ja v a2 s . c o m }
From source file:Main.java
/** * Returns a list of keys from the map in alphabetical order * /*from w ww . j a va 2 s. c o m*/ * @param map The map to sort * @return The ordered list of keys */ private static List<String> getSortedListOfKeys(Hashtable<String, Object> map) { List<String> mList = new ArrayList<String>(map.keySet()); Collections.sort(mList); return mList; }
From source file:ml.shifu.shifu.core.binning.DynamicBinningTest.java
public static List<NumBinInfo> createNumBinInfos(int binCnt) { Random rd = new Random(System.currentTimeMillis()); List<Double> thresholds = new ArrayList<Double>(binCnt - 1); for (int i = 0; i < binCnt - 1; i++) { thresholds.add(rd.nextGaussian() * 200); }// w ww.j av a2s. c om Collections.sort(thresholds); List<NumBinInfo> binInfoList = NumBinInfo.constructNumBinfo(StringUtils.join(thresholds, ':'), ':'); for (NumBinInfo binInfo : binInfoList) { if (rd.nextDouble() > 0.45) { int total = rd.nextInt() % 1000; int positive = (int) (total * rd.nextDouble()); binInfo.setTotalInstCnt(total); binInfo.setPositiveInstCnt(positive); } } return binInfoList; }
From source file:br.prof.salesfilho.oci.util.OCIUtils.java
public static List<String> getImageFiles(String directory) { List<String> results = new ArrayList(); File[] files = new File(directory).listFiles((File dir, String name) -> name.toLowerCase().endsWith(".jpg") || name.toLowerCase().endsWith(".jpeg") || name.toLowerCase().endsWith(".png") || name.toLowerCase().endsWith(".tiff") || name.toLowerCase().endsWith(".tif") || name.toLowerCase().endsWith(".bmp") || name.toLowerCase().endsWith(".gif")); for (File file : files) { if (file.isFile()) { results.add(file.getAbsolutePath()); }/*w w w . jav a 2s. c om*/ } Collections.sort(results); return results; }
From source file:Main.java
void showResults() { Collections.sort(results); for (Result result : results) System.out.printf("%-30.30s : %d\n", result.site, result.time); System.out.println("------------------"); }
From source file:Main.java
/** * Method by Adrian: [/*from ww w .j a v a2s . c om*/ * <a href="http://stackoverflow.com/a/15704264/5620200">StackOverflow</a> ] * & Mike: [ <a href= * "http://stackoverflow.com/questions/1542170/arranging-nodes-in-a-jtree"> * StackOverflow</a> ] * * @param node * @return */ @SuppressWarnings("unchecked") public static DefaultMutableTreeNode sort(DefaultMutableTreeNode node) { List<DefaultMutableTreeNode> children = Collections.list(node.children()); List<String> orgCnames = new ArrayList<String>(); List<String> cNames = new ArrayList<String>(); DefaultMutableTreeNode temParent = new DefaultMutableTreeNode(); for (DefaultMutableTreeNode child : children) { DefaultMutableTreeNode ch = (DefaultMutableTreeNode) child; temParent.insert(ch, 0); String uppser = ch.toString().toUpperCase(); // Not dependent on package name, so if duplicates are found // they will later on be confused. Adding this is of // very little consequence and fixes the issue. if (cNames.contains(uppser)) { uppser += "$COPY"; } cNames.add(uppser); orgCnames.add(uppser); if (!child.isLeaf()) { sort(child); } } Collections.sort(cNames); for (String name : cNames) { int indx = orgCnames.indexOf(name); int insertIndex = node.getChildCount(); node.insert(children.get(indx), insertIndex); } // Fixing folder placement for (int i = 0; i < node.getChildCount() - 1; i++) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(i); for (int j = i + 1; j <= node.getChildCount() - 1; j++) { DefaultMutableTreeNode prevNode = (DefaultMutableTreeNode) node.getChildAt(j); if (!prevNode.isLeaf() && child.isLeaf()) { node.insert(child, j); node.insert(prevNode, i); } } } return node; }
From source file:com.spotify.echoprintserver.nativelib.Util.java
public static List<Integer> sortedDistinct(List<Integer> seq) { Set<Integer> codeSet = new TreeSet<Integer>(); codeSet.addAll(seq);//from ww w .j a v a 2 s.c o m List<Integer> uniqueSortedCodeSet = new ArrayList<Integer>(); uniqueSortedCodeSet.addAll(codeSet); Collections.sort(uniqueSortedCodeSet); return uniqueSortedCodeSet; }