Class ArraysPlume.ComparableArrayComparatorLengthFirst<T extends Comparable<T>>

java.lang.Object
org.plumelib.util.ArraysPlume.ComparableArrayComparatorLengthFirst<T>
Type Parameters:
T - the type of the array elements
All Implemented Interfaces:
Serializable, Comparator<T[]>
Enclosing class:
ArraysPlume

public static final class ArraysPlume.ComparableArrayComparatorLengthFirst<T extends Comparable<T>> extends Object implements Comparator<T[]>, Serializable
Compare two arrays first by length (a shorter array is considered less), and if of equal length compare lexically (element-by-element).

Note: this comparator imposes orderings that are inconsistent with Object.equals(java.lang.Object). That is, it may return 0 if the arrays contain identical objects but are not equal according to equals().

See Also:
  • Constructor Details

    • ComparableArrayComparatorLengthFirst

      public ComparableArrayComparatorLengthFirst()
      Create a new ComparableArrayComparatorLengthFirst.
  • Method Details

    • compare

      @Pure public int compare(@PolyNull T[] a1, @PolyNull T[] a2)
      Compare two arrays by length, then lexically (element-by-element).
      Specified by:
      compare in interface Comparator<T extends Comparable<T>>
      Parameters:
      a1 - first array to compare
      a2 - second array to compare
      Returns:
      a negative integer, zero, or a positive integer, depending on whether the first argument is less than, equal to, or greater than the second argument