T - the type of objects that may be compared for equality or order.public interface Equality<T> extends EqualityComparer<T>, Comparator<T>, Serializable
A comparator to be used for element equality as well as for ordering. Implementing classes should ensure that:
compare function is consistent with
equal. If two objects
compare to 0 then they are
equal and the
reciprocal is true (this ensures that sorted collections/maps
do not break the general contract of their parent class based on
object equal).hash function is consistent with
equal: If two objects are equal,
they have the same hashcode (the reciprocal is not true).null value is supported (even for
comparisons) and the hashcode value of null is 0.Equalities| Modifier and Type | Method and Description |
|---|---|
int |
compare(T left,
T right)
Compares the specified objects for order.
|
boolean |
equal(T left,
T right)
Indicates if the specified objects can be considered equal.
|
int |
hashOf(T object)
Returns the hash code for the specified object (consistent with
equal(Object, Object)). |
equalsint hashOf(T object)
equal(Object, Object)).
Two objects considered equal have the same hash code.
The hash code of null is always 0.object - the object to return the hashcode for.boolean equal(T left, T right)
(compare(o1, o2) == 0) but
usually faster.equal in interface EqualityComparer<T>left - the first object (or null).right - the second object (or null).true if both objects are considered equal;
false otherwise.int compare(T left, T right)
null is supported.compare in interface Comparator<T>left - the first object.right - the second object.Copyright © 2017. All rights reserved.