package week12; import java.util.Comparator; public class PairComparator, B> implements Comparator> { @Override public int compare(Pair o1, Pair o2) { return compare(o1 == null ? null : o1.first, o2 == null ? null : o2.first); } static > int compare(K firstKey, K secondKey) { if(firstKey == secondKey) return 0; if(firstKey == null) return 1; if(secondKey == null) return -1; return firstKey.compareTo(secondKey); } }