Java has a Comparator<T> to enable matching of objects external to the class itself, to allow multiple / alternative methods for making ordered comparisons.
But the only standard way to do unordered comparisons is to override equals() inside the class.
What if I want to provide multiple / alternative unordered comparisons external to the class? (An obvious use case is to partition the collection into equivalence classes based on specific properties.)
Assuming that the end use is used for an unordered check (for example, not for sorting or indexing), whether Comparator<T> always implemented, which simply checks for equality, returns 0 if two objects are equal, and the value! = 0 when two objects are unequal ? ( note : the only reason I don't jump on this solution is because technically it can break the contract for Comparator without providing a relationship that satisfies transitivity and symmetry.)
It seems that there should have been a standard EqualsComparator<T> class or something like that.
(Does Guava handle something like this?)
java guava equivalence-classes
Jason s
source share