T
- the type of objects that may be compared by this comparatorpublic class InstanceComparator<T> extends Object implements Comparator<T>
Number
s such that Long
s occur before Integer
s.
Only the specified instanceOrder
classes are considered during comparison.
If two objects are both instances of the ordered type this comparator will return a
value of 0
. Consider combining with Comparator.thenComparing(Comparator)
if additional sorting is required.
Comparator.thenComparing(Comparator)
Constructor and Description |
---|
InstanceComparator(Class<?>... instanceOrder)
Create a new
InstanceComparator instance. |
Modifier and Type | Method and Description |
---|---|
int |
compare(T o1,
T o2) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
public InstanceComparator(Class<?>... instanceOrder)
InstanceComparator
instance.instanceOrder
- the ordered list of classes that should be used when comparing
objects. Classes earlier in the list will be given a higher priority.public int compare(T o1, T o2)
compare
in interface Comparator<T>