MCPcopy Index your code
hub / github.com/GregTech6/gregtech6 / sortByValuesDescending

Method sortByValuesDescending

src/main/java/gregapi/util/UT.java:1449–1456  ·  view source on GitHub ↗

Why the fuck do neither Java nor Guava have a Function to do this?

(Map<X,Y> aMap)

Source from the content-addressed store, hash-verified

1447
1448 /** Why the fuck do neither Java nor Guava have a Function to do this? */
1449 @SuppressWarnings("rawtypes")
1450 public static <X, Y extends Comparable> LinkedHashMap<X,Y> sortByValuesDescending(Map<X,Y> aMap) {
1451 List<Map.Entry<X,Y>> tEntrySet = new LinkedList<>(aMap.entrySet());
1452 Collections.sort(tEntrySet, new Comparator<Map.Entry<X,Y>>() {@SuppressWarnings("unchecked") @Override public int compare(Entry<X, Y> aValue1, Entry<X, Y> aValue2) {return -aValue1.getValue().compareTo(aValue2.getValue());}});
1453 LinkedHashMap<X,Y> rMap = new LinkedHashMap<>();
1454 for (Map.Entry<X,Y> tEntry : tEntrySet) rMap.put(tEntry.getKey(), tEntry.getValue());
1455 return rMap;
1456 }
1457
1458 public static <E> E select(long aIndex, E aReplacement, List<E> aList) {
1459 if (aList == null || aList.isEmpty()) return aReplacement;

Callers 1

Calls 1

putMethod · 0.45

Tested by

no test coverage detected