T
- The Comparable
type of element to be compared.public class FixedOrderComparator<T extends Comparable<? super T>> extends Object implements Comparator<T>, Serializable
Comparator
that accepts a fixed definition of terms specifying an
order. When compare(Comparable,Comparable)
is invoked, the
comparator first attempts to equate each argument to the order terms. If
either argument is matched, the term's order determines the result of the
comparison. If neither argument is matched, the result of the comparison is
determined by with Comparable.compareTo(Object)
.Constructor and Description |
---|
FixedOrderComparator(T... order)
Creates a new
FixedOrderComparator with the specified order of
terms. |
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
@SafeVarargs public FixedOrderComparator(T... order)
FixedOrderComparator
with the specified order of
terms. The vararg array cannot be null
, but member terms can be
null
.order
- The terms that defined the order.NullPointerException
- If order
is null.public int compare(T o1, T o2)
compare
in interface Comparator<T extends Comparable<? super T>>
Copyright © 2020 LibJ. All rights reserved.