Class NaturalComparator<T>

java.lang.Object
org.magicwerk.brownies.collections.helper.SingletonComparator<T>
org.magicwerk.brownies.collections.helper.NaturalComparator<T>
Type Parameters:
T - element type
All Implemented Interfaces:
Serializable, Comparator<T>

public class NaturalComparator<T> extends SingletonComparator<T>
The NaturalComparator will compare object using their natural order.
See Also:
  • Field Details

  • Constructor Details

    • NaturalComparator

      private NaturalComparator()
      Prevent construction.
  • Method Details

    • getComparator

      public static <T> Comparator<T> getComparator(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(Class<T> c)
      Returns singleton instance.
    • compare

      public int compare(T o1, T o2)