ProgramixGenericLib v5.0.1

com.programix.collections
Class ReverseComparator<T>

java.lang.Object
  extended by 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

Constructor Summary
ReverseComparator(Comparator<T> forwardComparator)
          Takes the supplied forward Comparator and holds it for use when the reversing is needed.
 
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
 
Methods inherited from interface java.util.Comparator
equals
 

Constructor Detail

ReverseComparator

public ReverseComparator(Comparator<T> forwardComparator)
Takes the supplied forward Comparator and holds it for use when the reversing is needed.

Method Detail

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>

ProgramixGenericLib v5.0.1

Copyright © 2001-2009 Programix Incorporated. All rights reserved. ProgramixGenericLib is free and is OSI Certified Open Source Software under the BSD license.