public static <A, B extends Comparable<? super B>> Comparator<Pair<A, B>> comparingBySecond() {
    return new Comparator<Pair<A, B>>() {
      @Override
      public int compare(Pair<A, B> o1, Pair<A, B> o2) {
        return o1.second.compareTo(o2.second);
      }
    };
  }
public static <A, B extends Comparable<? super B>> Comparator<Pair<A, B>> comparingBySecond()