|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||
com.sas.util.ReverseComparator
public class ReverseComparator
A Comparator which reverses the result of another Comparator.
The original comparator is called with the same arguments
in the same order (since it is possible although probably not desireable) for
a comparator to return inconsistent results for compare(a,b) and compare(b,a).)
The result is negated and guaranteed to be one of
,
Comparator.LESS_THAN , or
Comparator.EQUALS , or
Comparator.GREATER_THAN.
Comparator.INCOMPARABLE
The ReverseComparator allows you to simplify other comparators by
not having to worry about ascending or descending sorts. If you
write all Comparators c to assume an ascending sort context, then
to sort in descending order, simply use ReverseComparator.reverse(c)
to reverse it.
| Field Summary |
|---|
| Fields inherited from interface com.sas.util.Comparator |
|---|
EQUALS, GREATER_THAN, INCOMPARABLE, LESS_THAN |
| Constructor Summary | |
|---|---|
ReverseComparator(com.sas.util.Comparator comparator)
Construct a Comparator which reverses the result of
another comparator. |
|
ReverseComparator(java.util.Comparator comparator)
Construct a Comparator which reverses the result of
another comparator. |
|
| Method Summary | |
|---|---|
java.lang.Object |
clone()
Clone this reverse comparator. |
int |
compare(java.lang.Object a,
java.lang.Object b)
Compare two objects using the original comparator, and reverse and return that result. |
java.util.Comparator |
getComparator()
Return the root comparator with which this ReverseCompatator was constructed. |
static java.util.Comparator |
reverse(java.util.Comparator comparator)
Return a comparator whose sense is a reversed compararison of comparator. |
| Constructor Detail |
|---|
public ReverseComparator(com.sas.util.Comparator comparator)
Comparator which reverses the result of
another comparator.
comparator - another comparator whose comparison
result you wish to reverse. This argument cannot be null.public ReverseComparator(java.util.Comparator comparator)
Comparator which reverses the result of
another comparator.
comparator - another comparator whose comparison
result you wish to reverse. This argument cannot be null.| Method Detail |
|---|
public int compare(java.lang.Object a,
java.lang.Object b)
compare in interface java.util.Comparatora - the first objectb - the second object
Comparator.LESS_THAN, Comparator.EQUALS,
Comparator.GREATER_THAN, Comparator.INCOMPARABLEpublic java.lang.Object clone()
clone in interface com.sas.PublicClonableclone in class java.lang.Objectpublic java.util.Comparator getComparator()
public static java.util.Comparator reverse(java.util.Comparator comparator)
c = ReverseComparator.reverse(c);
will sort in the reverse order. Reversing a comparator c2 twice
will restore the comparator; i.e.
for any comparator c,
c == ReverseComparator.reverse(ReverseComparator.reverse(c))
comparator - a comparator
ReverseComparator,
return its root comparator, else return a new ReverseComparator(comparator).
|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||