@Test public void testSortingMap() { Map<String, String> testMap = getTestMap(); Map<String, String> sortedMap = sortMapByValue(testMap, true); assertEquals(testMap.size(), sortedMap.size()); TreeSet<Object> sortedValues = new TreeSet<>((s1, s2) -> { if (s1 instanceof Comparable && s2 instanceof Comparable) { return ((Comparable) s1).compareTo(s2); } else return -1; }); sortedValues.addAll(testMap.values()); Iterator<Entry<String, String>> iteratorSortedMap = sortedMap.entrySet().iterator(); Iterator<Object> iteratorSortedValues = sortedValues.iterator(); while (iteratorSortedMap.hasNext()) { Entry<String, String> entry = iteratorSortedMap.next(); Object value = iteratorSortedValues.next(); assertEquals(value, entry.getValue()); } sortedMap = sortMapByValue(testMap, false); assertEquals(testMap.size(), sortedMap.size()); sortedValues = new TreeSet<>((s1, s2) -> -((Comparable) s1).compareTo(s2)); sortedValues.addAll(testMap.values()); iteratorSortedMap = sortedMap.entrySet().iterator(); iteratorSortedValues = sortedValues.iterator(); while (iteratorSortedMap.hasNext()) { Entry<String, String> entry = iteratorSortedMap.next(); Object value = iteratorSortedValues.next(); assertEquals(value, entry.getValue()); } }
public static Map<String, String> sortMapByValue(Map<String, String> map, boolean asc) { TreeMap<String, String> treeMap = new TreeMap<>(new ValueComparer(map, asc)); treeMap.putAll(map); return treeMap; }
ListProviderUtil { public static Map<String, String> sortMapByValue(Map<String, String> map, boolean asc) { TreeMap<String, String> treeMap = new TreeMap<>(new ValueComparer(map, asc)); treeMap.putAll(map); return treeMap; } }
ListProviderUtil { public static Map<String, String> sortMapByValue(Map<String, String> map, boolean asc) { TreeMap<String, String> treeMap = new TreeMap<>(new ValueComparer(map, asc)); treeMap.putAll(map); return treeMap; } private  ListProviderUtil(); }
ListProviderUtil { public static Map<String, String> sortMapByValue(Map<String, String> map, boolean asc) { TreeMap<String, String> treeMap = new TreeMap<>(new ValueComparer(map, asc)); treeMap.putAll(map); return treeMap; } private  ListProviderUtil(); static Map<String, String> sortMapByValue(Map<String, String> map, boolean asc); static Map<String, String> filterMap(Map<String, String> map, ResourceListQuery query); static Map<String, String> invertMap(Map<String, String> map); }
ListProviderUtil { public static Map<String, String> sortMapByValue(Map<String, String> map, boolean asc) { TreeMap<String, String> treeMap = new TreeMap<>(new ValueComparer(map, asc)); treeMap.putAll(map); return treeMap; } private  ListProviderUtil(); static Map<String, String> sortMapByValue(Map<String, String> map, boolean asc); static Map<String, String> filterMap(Map<String, String> map, ResourceListQuery query); static Map<String, String> invertMap(Map<String, String> map);  }