FileDocCategorySizeDatePackage
ReverseComparator.javaAPI DocAndroid 1.5 API2137Wed May 06 22:42:46 BST 2009org.apache.commons.io.comparator

ReverseComparator

public class ReverseComparator extends Object implements Serializable, Comparator
Reverses the result of comparing two objects using the delegate {@link Comparator}.
version
$Revision: 609243 $ $Date: 2008-01-06 00:30:42 +0000 (Sun, 06 Jan 2008) $
since
Commons IO 1.4

Fields Summary
private final Comparator
delegate
Constructors Summary
public ReverseComparator(Comparator delegate)
Construct an instance with the sepecified delegate {@link Comparator}.

param
delegate The comparator to delegate to

        if (delegate == null) {
            throw new IllegalArgumentException("Delegate comparator is missing");
        }
        this.delegate = delegate;
    
Methods Summary
public intcompare(java.lang.Object obj1, java.lang.Object obj2)
Compare using the delegate Comparator, but reversing the result.

param
obj1 The first object to compare
param
obj2 The second object to compare
return
the result from the delegate {@link Comparator#compare(Object, Object)} reversing the value (i.e. positive becomes negative and vice versa)

        return delegate.compare(obj2, obj1); // parameters switched round