ProgramixGenericLib v4.0.0

com.programix.collections
Class ReverseComparator

java.lang.Object
  extended by com.programix.collections.ReverseComparator
All Implemented Interfaces:
Comparator

public final class ReverseComparator
extends Object
implements Comparator

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 forwardComparator)
          Takes the supplied forward Comparator and holds it for use when the reversing is needed.
 
Method Summary
 int compare(Object obj1, Object 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 forwardComparator)
Takes the supplied forward Comparator and holds it for use when the reversing is needed.

Method Detail

compare

public int compare(Object obj1,
                   Object 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

ProgramixGenericLib v4.0.0

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