public class InvertibleComparator<T> extends Object implements Comparator<T>, Serializable
Constructor and Description |
---|
InvertibleComparator(Comparator<T> comparator)
Create an InvertibleComparator that sorts ascending by default.
|
InvertibleComparator(Comparator<T> comparator,
boolean ascending)
Create an InvertibleComparator that sorts based on the provided order.
|
Modifier and Type | Method and Description |
---|---|
int |
compare(T o1,
T o2) |
boolean |
equals(Object obj) |
int |
hashCode() |
void |
invertOrder()
Invert the sort order: ascending -> descending or
descending -> ascending.
|
boolean |
isAscending()
Return the sort order: ascending (true) or descending (false).
|
void |
setAscending(boolean ascending)
Specify the sort order: ascending (true) or descending (false).
|
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
comparing, comparing, comparingDouble, comparingInt, comparingLong, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
public InvertibleComparator(Comparator<T> comparator)
comparator
- the comparator to decoratepublic InvertibleComparator(Comparator<T> comparator, boolean ascending)
comparator
- the comparator to decorateascending
- the sort order: ascending (true) or descending (false)public void setAscending(boolean ascending)
public boolean isAscending()
public void invertOrder()
public int compare(T o1, T o2)
compare
in interface Comparator<T>
public boolean equals(Object obj)
equals
in interface Comparator<T>
equals
in class Object