Class NullComparator<T>

  • Type Parameters:
    T - element type
    All Implemented Interfaces:
    java.io.Serializable, java.util.Comparator<T>

    public class NullComparator<T>
    extends SingletonComparator<T>
    A NullComparator extends an existing comparator so it can handle null values.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Comparator<T> comparator  
      private boolean nullsFirst  
    • Constructor Summary

      Constructors 
      Constructor Description
      NullComparator​(java.util.Comparator<T> comparator, boolean nullsFirst)
      Constructor.
    • Method Summary

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

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

        reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Field Detail

      • comparator

        private java.util.Comparator<T> comparator
      • nullsFirst

        private boolean nullsFirst
    • Constructor Detail

      • NullComparator

        public NullComparator​(java.util.Comparator<T> comparator,
                              boolean nullsFirst)
        Constructor.
        Parameters:
        comparator - comparator to extend
        nullsFirst - true to sort nulls first, false to sort null last
    • Method Detail

      • compare

        public int compare​(T key1,
                           T key2)