structure
Class ReverseComparator
java.lang.Object
structure.ReverseComparator
- All Implemented Interfaces:
- java.util.Comparator
public class ReverseComparator
- extends java.lang.Object
- implements java.util.Comparator
Field Summary |
protected java.util.Comparator |
base
|
Constructor Summary |
ReverseComparator()
Construct a comparator that generates reverse natural comparison |
ReverseComparator(java.util.Comparator base)
Construct a comparator that generates reverse of another comparator |
Method Summary |
int |
compare(java.lang.Object a,
java.lang.Object b)
Compare two values, a and b. |
boolean |
equals(java.lang.Object b)
Returns true if the other object is a NaturalComparator. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
base
protected java.util.Comparator base
ReverseComparator
public ReverseComparator()
- Construct a comparator that generates reverse natural comparison
- Postcondition:
- constructs a comparator that orders in reverse order
ReverseComparator
public ReverseComparator(java.util.Comparator base)
- Construct a comparator that generates reverse of another comparator
- Parameters:
base
- the ordering to be reversed- Postcondition:
- constructs a Comparator that orders in reverse order of base
compare
public int compare(java.lang.Object a,
java.lang.Object b)
- Compare two values, a and b. Simply calls the default
compareTo method for a on b.
- Specified by:
compare
in interface java.util.Comparator
- Parameters:
a
- object performing the compareb
- the object being compared
- Returns:
- value <, ==, > 0 if a <, ==, > b using a.compareTo
- Precondition:
- a, b non-null, and b is of type of a
- Postcondition:
- returns value <, ==, > 0 if a <, ==, > b
equals
public boolean equals(java.lang.Object b)
- Returns true if the other object is a NaturalComparator.
- Specified by:
equals
in interface java.util.Comparator
- Overrides:
equals
in class java.lang.Object
- Parameters:
b
- a possible NaturalComparator
- Returns:
- true if b is a NaturalComparator
- Postcondition:
- returns true if b is a NaturalComparator