public class ReverseComparator<E> extends Objectimplements Comparator <E>, Serializable
compare method.
Collections.reverseOrder() ,
Serialized Form
| Constructor and Description |
|---|
ReverseComparator()
Creates a comparator that compares objects based on the inverse of their natural ordering.
|
ReverseComparator(Comparator
Creates a comparator that inverts the comparison of the given comparator.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compare(E obj1, E obj2)
Compares two objects in reverse order.
|
boolean |
equals(Object
Returns
true iff
that Object is is a
Comparator whose ordering is known to be equivalent to mine.
|
int |
hashCode()
Implement a hash code for this comparator that is consistent with
equals.
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitcomparing, comparing, comparingDouble, comparingInt, comparingLong, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLongpublic ReverseComparator()
Collections.reverseOrder()
public ReverseComparator(Comparator<? super E> comparator)
null, the ReverseComparator defaults to reversing the natural order, as per
Collections.reverseOrder() .
comparator - Comparator to reverse
public int compare(E obj1, E obj2)
compare in interface
Comparator<E>
obj1 - the first object to compare
obj2 - the second object to compare
public int hashCode()
equals.
public boolean equals(Objectobject)
true iff
that Object is is a
Comparator whose ordering is known to be equivalent to mine.
This implementation returns true iff object. equals getClass()this.getClass(), and the underlying comparators are equal. Subclasses may want to override this behavior to remain consistent with the equals contract.
equals in interface
Comparator<E>
equals in class
Object
object - the object to compare to