public interface Comparator4D<T>
compare((Object) e1, (Object) e2) == 0
and
e1.equals((Object) e2)
In general, Comparators should be Serializable, because when they are passed to Serializable data structures such as SortedMap or SortedSet, the entire data structure will only serialize correctly if the comparator is Serializable.
Comparable
,
TreeMap
,
TreeSet
,
SortedMap
,
SortedSet
,
Arrays#sort(Object[], Comparator)
Modifier and Type | Method and Description |
---|---|
int |
compare(T o1,
T o2)
Return an integer that is negative, zero or positive depending on whether
the first argument is less than, equal to or greater than the second
according to this ordering.
|
boolean |
equals(java.lang.Object obj)
Return true if the object is equal to this object.
|
int compare(T o1, T o2)
Although it is permissible for a comparator to provide an order inconsistent with equals, that should be documented.
o1
- the first objecto2
- the second objectjava.lang.ClassCastException
- if the elements are not of types that can be
compared by this ordering.boolean equals(java.lang.Object obj)
Object.equals()
, be a Comparator, and impose the
same ordering as this Comparator. The default implementation
inherited from Object is usually adequate.equals
in class java.lang.Object
obj
- The objectObject.equals(Object)