Package org.plumelib.util
Class StringsPlume.ObjectComparator
java.lang.Object
org.plumelib.util.StringsPlume.ObjectComparator
- All Implemented Interfaces:
Serializable
,Comparator<@Nullable Object>
- Enclosing class:
- StringsPlume
public static class StringsPlume.ObjectComparator
extends Object
implements Comparator<@Nullable Object>, Serializable
Orders Objects according to their
toString()
representation. Null is considered less
than any non-null Object.
Note: if toString returns a nondeterministic value, such as one that depends on the result
of hashCode()
, then this comparator may yield different orderings from run to run of a
program.
This cannot be replaced by Comparator.nullsFirst(Comparator.naturalOrder())
becase
Object
is not Comparable
.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final StringsPlume.ObjectComparator
The canonical ObjectComparator. -
Constructor Summary
-
Method Summary
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
-
Field Details
-
it
The canonical ObjectComparator.
-
-
Constructor Details
-
ObjectComparator
Deprecated.useit
.Create a new ObjectComparator.
-
-
Method Details
-
compare
Compare two Objects based on their string representations. Null is considered less than any non-null Object.- Specified by:
compare
in interfaceComparator<@Nullable Object>
- Parameters:
o1
- first object to compareo2
- second object to compare- Returns:
- a negative integer, zero, or a positive integer as the first argument's
toString()
representation is less than, equal to, or greater than the second argument'stoString()
representation
-
it
.