Class NaturalComparator<T>

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

    public class NaturalComparator<T>
    extends SingletonComparator<T>
    The NaturalComparator will compare object using their natural order.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private NaturalComparator()
      Prevent construction.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(T o1, T o2)  
      static <T> java.util.Comparator<T> getComparator​(java.lang.Class<T> clazz)
      Return the natural comparator for the class if it implements Comparable, otherwise null is returned.
      static <T> NaturalComparator<T> INSTANCE()
      Returns singleton instance.
      static <T> NaturalComparator<T> INSTANCE​(java.lang.Class<T> c)
      Returns singleton instance.
      • 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
    • Constructor Detail

      • NaturalComparator

        private NaturalComparator()
        Prevent construction.
    • Method Detail

      • getComparator

        public static <T> java.util.Comparator<T> getComparator​(java.lang.Class<T> clazz)
        Return the natural comparator for the class if it implements Comparable, otherwise null is returned.
        Parameters:
        clazz - class to get comparator for
        Returns:
        comparator for class, null if not available
      • INSTANCE

        public static <T> NaturalComparator<T> INSTANCE()
        Returns singleton instance.
      • INSTANCE

        public static <T> NaturalComparator<T> INSTANCE​(java.lang.Class<T> c)
        Returns singleton instance.
      • compare

        public int compare​(T o1,
                           T o2)