Package com.jidesoft.comparator
Class ComparableComparator
java.lang.Object
com.jidesoft.comparator.ComparableComparator
- All Implemented Interfaces:
Serializable
,Comparator<Object>
A Comparator that compares Comparable objects. Throws ClassCastExceptions if the objects are not
Comparable, or if they are null. Throws ClassCastException if the compareTo of both objects do
not provide an inverse result of each other as per the Comparable javadoc. This Comparator is
useful, for example, for enforcing the natural order in custom implementations of SortedSet and
SortedMap.
If both objects are null, they will be treated as equal. If one is null and the other is not, the null value will be treated as smaller then non-null value.
If both objects are null, they will be treated as equal. If one is null and the other is not, the null value will be treated as smaller then non-null value.
- Author:
- bayard@generationjava.com, JIDE Software
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
static ComparableComparator
Return a shared instance of a ComparableComparator.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
-
ComparableComparator
public ComparableComparator()Constructs a ComparableComparator.
-
-
Method Details
-
getInstance
Return a shared instance of a ComparableComparator. Developers are encouraged to use the comparator returned from this method instead of constructing a new instance to reduce allocation and GC overhead when multiple comparable comparators may be used in the same VM.- Returns:
- an instance of ComparableComparator.
-
compare
- Specified by:
compare
in interfaceComparator<Object>
-