managed/src/main/java/com/yugabyte/yw/common/PlacementInfoUtil.java
// Helper API to sort an given map in ascending order of its values and return the same.
Helper API to sort an given map in ascending order of its values and return the same.
Helper API to sort an given map in ascending order of its values and return the same .
private static LinkedHashMap<UUID, Integer> sortByValues(Map<UUID, Integer> map,
                                                           boolean isAscending) {
    List<Map.Entry<UUID, Integer>> list = new LinkedList<Map.Entry<UUID, Integer>>(map.entrySet());
    if (isAscending) {
      Collections.sort(list, new Comparator<Map.Entry<UUID, Integer>>() {
        public int compare(Map.Entry<UUID, Integer> o1, Map.Entry<UUID, Integer> o2) {
          return (o1.getValue()).compareTo(o2.getValue());
        }
      });
    } else {
      Collections.sort(list, new Comparator<Map.Entry<UUID, Integer>>() {
        public int compare(Map.Entry<UUID, Integer> o1, Map.Entry<UUID, Integer> o2) {
          return (o2.getValue()).compareTo(o1.getValue());
        }
      });
    }
    LinkedHashMap<UUID, Integer> sortedHashMap = new LinkedHashMap<UUID, Integer>();
    for (Map.Entry<UUID, Integer> entry : list) {
      sortedHashMap.put(entry.getKey(), entry.getValue());
    }
    return sortedHashMap;
  }
private static LinkedHashMap < UUID , Integer > sortByValues ( Map < UUID , Integer > map , boolean isAscending ) { List < Map . Entry < UUID , Integer > > list = new LinkedList < Map . Entry < UUID , Integer > > ( map . entrySet ( ) ) ; if ( isAscending ) { Collections . sort ( list , new Comparator < Map . Entry < UUID , Integer > > ( ) { public int compare ( Map . Entry < UUID , Integer > o1 , Map . Entry < UUID , Integer > o2 ) { return ( o1 . getValue ( ) ) . compareTo ( o2 . getValue ( ) ) ; } } ) ; } else { Collections . sort ( list , new Comparator < Map . Entry < UUID , Integer > > ( ) { public int compare ( Map . Entry < UUID , Integer > o1 , Map . Entry < UUID , Integer > o2 ) { return ( o2 . getValue ( ) ) . compareTo ( o1 . getValue ( ) ) ; } } ) ; } LinkedHashMap < UUID , Integer > sortedHashMap = new LinkedHashMap < UUID , Integer > ( ) ; for ( Map . Entry < UUID , Integer > entry : list ) { sortedHashMap . put ( entry . getKey ( ) , entry . getValue ( ) ) ; } return sortedHashMap ; }
Helper API to sort an given map in ascending order of its values and return the same.
Helper API to sort an given map in ascending order of its values and return the same .