Class ToStringComparator

java.lang.Object
org.plumelib.util.ToStringComparator
All Implemented Interfaces:
Comparator<Object>

public class ToStringComparator extends Object implements Comparator<Object>
A comparator that orders values based on the lexicographic ordering of their toString().

It handles null values, sorting them according to their printed representation "null".

  • Field Details

    • instance

      public static ToStringComparator instance
      The unique instance (this class is a singleton).
  • Method Details

    • compare

      public int compare(Object o1, Object o2)
      Specified by:
      compare in interface Comparator<Object>
    • sorted

      public static <T extends @Nullable @Signed Object> List<T> sorted(Iterable<T> in)
      Returns a copy of the input, sorted according to the elements' toString().
      Type Parameters:
      T - the type of the elements
      Parameters:
      in - a set of elements
      Returns:
      the elements, sorted according to toString()