Package org.plumelib.util
Class ArraysPlume.ObjectArrayComparatorLengthFirst
java.lang.Object
org.plumelib.util.ArraysPlume.ObjectArrayComparatorLengthFirst
- All Implemented Interfaces:
Serializable,Comparator<Object[]>
- Enclosing class:
ArraysPlume
public static final class ArraysPlume.ObjectArrayComparatorLengthFirst
extends Object
implements Comparator<Object[]>, 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().
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.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ArraysPlume.ObjectArrayComparatorLengthFirstThe canonical ObjectArrayComparatorLengthFirst. -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
it
The canonical ObjectArrayComparatorLengthFirst.
-
-
Constructor Details
-
ObjectArrayComparatorLengthFirst
Deprecated.useit.Create a new ObjectArrayComparatorLengthFirst.
-
-
Method Details
-
compare
Compare two arrays by length, then lexically (element-by-element). Null elements are considered smaller than non-null elements.- Specified by:
comparein interfaceComparator<Object[]>- Parameters:
a1- first array to comparea2- 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
-
it.