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 Details

  • Constructor Details

    • ObjectComparator

      @Deprecated public ObjectComparator()
      Deprecated.
      use it.
      Create a new ObjectComparator.
  • Method Details

    • compare

      @Pure public int compare(@Nullable Object o1, @Nullable Object o2)
      Compare two Objects based on their string representations. Null is considered less than any non-null Object.
      Specified by:
      compare in interface Comparator<@Nullable Object>
      Parameters:
      o1 - first object to compare
      o2 - 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's toString() representation