Package craterdog.utils
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>
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 Summary
Constructors -
Method Summary
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 Details
-
NaturalComparator
public NaturalComparator()
-
-
Method Details
-
compare
- Specified by:
compare
in interfaceComparator<T>
-