src/main/java/org/apache/hadoop/hdfs/server/namenode/queries/Histograms.java
public static <K, V extends Comparable<? super V>> Map<K, List<V>> sortByValue(
      Map<K, List<V>> map, final int sortIndex, boolean ascending) {

    return map.entrySet()
        .stream()
        .sorted(
            ascending
                ? Comparator.comparing((Map.Entry<K, List<V>> c) -> c.getValue().get(sortIndex))
                : Comparator.comparing((Map.Entry<K, List<V>> c) -> c.getValue().get(sortIndex))
                    .reversed())
        .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, List<V>> sortByValue(
      Map<K, List<V>> map, final int sortIndex, boolean ascending) {
    return map.entrySet()
        .stream()
        .sorted(
            ascending
                ? Comparator.comparing((Map.Entry<K, List<V>> c) -> c.getValue().get(sortIndex))
                : Comparator.comparing((Map.Entry<K, List<V>> c) -> c.getValue().get(sortIndex))
                    .reversed())
        .collect(
            Collectors.toMap(
                Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
  }
public static < K , V extends Comparable < ? super V > > Map < K , List < V > > sortByValue ( Map < K , List < V > > map , final int sortIndex , boolean ascending ) { return map . entrySet ( ) . stream ( ) . sorted ( ascending ? Comparator . comparing ( ( Map . Entry < K , List < V > > c ) -> c . getValue ( ) . get ( sortIndex ) ) : Comparator . comparing ( ( Map . Entry < K , List < V > > c ) -> c . getValue ( ) . get ( sortIndex ) ) . reversed ( ) ) . 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 .