com.programix.collections
Class ReverseComparator<T>
java.lang.Object
com.programix.collections.ReverseComparator<T>
- All Implemented Interfaces:
- Comparator<T>
public final class ReverseComparator<T>
- extends Object
- implements Comparator<T>
This Comparator wrapper reverses the sense of the
Comparator supplied at the time of construction.
If the original Comparator would have returned a 1,
then this reverses it and returns a -1 (and vice versa).
- Author:
- Paul Hyde
- See Also:
NullFirstComparator,
NullLastComparator,
ComparableComparator
|
Method Summary |
int |
compare(T obj1,
T obj2)
This implementation of the
compare method on
Comparator will quickly check
if both references are the same using == (which
evaluates to true if both references are pointing
to the same object or both are null). |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ReverseComparator
public ReverseComparator(Comparator<T> forwardComparator)
- Takes the supplied forward
Comparator and
holds it for use when the reversing is needed.
compare
public int compare(T obj1,
T obj2)
- This implementation of the
compare method on
Comparator will quickly check
if both references are the same using == (which
evaluates to true if both references are pointing
to the same object or both are null).
If the references are the same, then this will quickly return
0.
If the references are not the same, then the forward comparator supplied
at construction is used.
- Specified by:
compare in interface Comparator<T>
Copyright © 2001-2009
Programix Incorporated.
All rights reserved.
ProgramixGenericLib is free
and is
OSI Certified
Open Source Software under the BSD
license.