Class KeyComparator<T,​C extends java.lang.Comparable<? super C>>

  • Type Parameters:
    T - the type to compare
    C - the type of the comparable key
    All Implemented Interfaces:
    java.util.Comparator<T>

    @GwtCompatible
    public final class KeyComparator<T,​C extends java.lang.Comparable<? super C>>
    extends java.lang.Object
    implements java.util.Comparator<T>
    A comparator that compares objects by calling the supplied key function on them and then comparing the resulting keys. It is null-safe if the key's compareTo method is null-safe.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(T a, T b)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Comparator

        equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Constructor Detail

      • KeyComparator

        public KeyComparator​(Functions.Function1<? super T,​C> keyFunction)
        Parameters:
        keyFunction - the key function to use for comparing objects. May not be null
    • Method Detail

      • compare

        public int compare​(T a,
                           T b)
        Specified by:
        compare in interface java.util.Comparator<T>