src/main/java/org/apache/hadoop/hdfs/server/namenode/queries/Histograms.java
public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(
      Map<K, V> map, boolean ascending) {
    return map.entrySet()
        .stream()
        .sorted(
            ascending
                ? Map.Entry.comparingByValue()
                : Map.Entry.comparingByValue(Collections.reverseOrder()))
        .collect(
            Collectors.toMap(
                Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
  }
/**
   * Result is a histogram sorted by its values.
   *
   * @param <K> the type of the map keys
   * @param <V> the type of the map values
   * @param map map values to be sorted
   * @param ascending indicates whether ascending or descending sort order
   * @return sorted map
   */
Result is a histogram sorted by its values.
Result is a histogram sorted by its values .
public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(
      Map<K, V> map, boolean ascending) {
    return map.entrySet()
        .stream()
        .sorted(
            ascending
                ? Map.Entry.comparingByValue()
                : Map.Entry.comparingByValue(Collections.reverseOrder()))
        .collect(
            Collectors.toMap(
                Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
  }
public static < K , V extends Comparable < ? super V > > Map < K , V > sortByValue ( Map < K , V > map , boolean ascending ) { return map . entrySet ( ) . stream ( ) . sorted ( ascending ? Map . Entry . comparingByValue ( ) : Map . Entry . comparingByValue ( Collections . reverseOrder ( ) ) ) . collect ( Collectors . toMap ( Map . Entry :: getKey , Map . Entry :: getValue , ( e1 , e2 ) -> e1 , LinkedHashMap :: new ) ) ; }
Result is a histogram sorted by its values.
Result is a histogram sorted by its values .