Comparator that compares Comparable
objects.
This Comparator is useful, for example, for enforcing the natural order in
custom implementations of SortedSet and
SortedMap.
Note
In the 2.0 and 2.1 releases of Commons Collections, this class would
throw a ClassCastException if either of the arguments to
compare were null, not
Comparable, or for which
compareTo gave inconsistent results.
This is no longer the case. See compare for
details.
java.util.Collections#reverseOrder()
| Modifier and Type | Field and Description |
|---|---|
| public static final ComparableComparator | INSTANCE
The singleton instance. |
| private static final long | serialVersionUID
Serialization version. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static < the element type E extends Comparable | Returns: the singleton ComparableComparatorGets the singleton instance of a ComparableComparator. |
| public int | Returns: negative if obj1 is less, positive if greater, zero if equalthe first object to compare obj1, final E the second object to compare obj2)Implements java. Comparable arguments.
|
| public boolean | Returns: true if equalthe object to compare with object)Overrides java. Implements java. true iff that Object is is a Comparator
whose ordering is known to be equivalent to mine.
|
| public int | Returns: a hash code for this comparator.Overrides java. equals.
|
| INSTANCE | back to summary |
|---|---|
| public static final ComparableComparator<E extends Comparable<? super E>> INSTANCE The singleton instance.
| |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serialization version. | |
| ComparableComparator | back to summary |
|---|---|
| public ComparableComparator() Constructor whose use should be avoided.
Please use the | |
| comparableComparator | back to summary |
|---|---|
| public static <E extends Comparable Gets the singleton 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.
| |
| compare | back to summary |
|---|---|
| public int compare(final E obj1, final E obj2) Implements java. Compare the two ((Comparable)obj1).compareTo(obj2)
| |
| equals | back to summary |
|---|---|
| public boolean equals(final Object object) Overrides java. Implements java. Returns
This implementation returns | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Implement a hash code for this comparator that is consistent with
| |