Class NaturalComparator<T>

java.lang.Object
craterdog.utils.NaturalComparator<T>
Type Parameters:
T - The type of the objects being compared.
All Implemented Interfaces:
Comparator<T>

public class NaturalComparator<T> extends Object implements Comparator<T>
This class defines a comparator that compares two objects of the same type using their natural compareTo method if the type implements the Comparable interface, or by doing a lexical comparison on their string formats if not. This comparator handles null values as well. A null value is always less than an non null value and two null values are equal.
Author:
Derk Norton
  • Constructor Details

    • NaturalComparator

      public NaturalComparator()
  • Method Details

    • compare

      public int compare(T object1, T object2)
      Specified by:
      compare in interface Comparator<T>