List of utility methods to do Map Sort
List | sortClustersKeys(final Map Sort cluster keys by their packages size. List<String> returnValue; returnValue = new ArrayList<String>(clusters.keySet()); Collections.sort(returnValue, new Comparator<String>() { public int compare(final String first, final String second) { return new Integer(clusters.get(first).size()).compareTo(clusters.get(second).size()); }); return returnValue; ... |
List | sortDoubleMap(Map sort Double Map List<Map.Entry<String, Double>> mapSorted = new ArrayList<Map.Entry<String, Double>>(map.entrySet()); Collections.sort(mapSorted, new Comparator<Map.Entry<String, Double>>() { public int compare(Map.Entry<String, Double> o1, Map.Entry<String, Double> o2) { return (o2.getValue()).compareTo(o1.getValue()); }); return mapSorted; |
Map | sortedByRankThenLength(Map sorted By Rank Then Length List<Entry<String, int[]>> ll = new LinkedList<Entry<String, int[]>>(map.entrySet()); Collections.sort(ll, new Comparator<Entry<String, int[]>>() { @Override public int compare(Entry<String, int[]> o1, Entry<String, int[]> o2) { int val = Integer.compare(o2.getValue().length, o1.getValue().length); if (val == 0) val = Integer.compare(o1.getKey().length(), o2.getKey().length()); return val; ... |
SortedSet | sortedKeys(Map Returns the keys for the map in a set sorted alphabetically. return new TreeSet<String>(map.keySet()); |
Map | sortedMap(Map Method to sort a map based on the comparator if (map != null && comparator != null) { Map<K, V> returnValue = new HashMap<>(); List<K> list = new ArrayList<>(); for (K key : map.keySet()) { list.add(key); Collections.sort(list, comparator); for (int i = 0; i < list.size(); i++) { ... |
String | sortedString(Map sorted String List<T> t = new ArrayList<T>(c.keySet()); Collections.sort(t); List<V> l = new ArrayList<V>(); List<String> pairs = new ArrayList<String>(); for (T k : t) { pairs.add(k + "=" + c.get(k)); return "{" + join(", ", pairs) + "}"; ... |
String | sortedString(Map sorted String List<T> t = new ArrayList<T>(c.keySet()); Collections.sort(t); List<String> pairs = new ArrayList<String>(); for (T k : t) { pairs.add(k + "=" + c.get(k)); return "{" + join(", ", pairs) + "}"; |
Map | sortedTable(Map sorted Table if (map != null) { return new TreeMap<String, Object>(map); } else { return new TreeMap<String, Object>(); |
Map | sortedView(Map sorted View List<Map.Entry<String, Long>> values = new LinkedList<Map.Entry<String, Long>>(original.entrySet()); Collections.sort(values, new Comparator<Map.Entry<String, Long>>() { public int compare(Map.Entry<String, Long> o1, Map.Entry<String, Long> o2) { int i = o1.getValue().compareTo(o2.getValue()); return (-i); }); Map<String, Long> view = new LinkedHashMap<String, Long>(); ... |
LinkedHashMap | sortEntries(Map sort Entries LinkedHashMap<K, V> returnMap = new LinkedHashMap<K, V>(); List<Entry<K, V>> entries = new LinkedList<Entry<K, V>>(map.entrySet()); Collections.sort(entries, comparator); for (Entry<K, V> entry : entries) { returnMap.put(entry.getKey(), entry.getValue()); return returnMap; |