net.sf.molae.pipe.sorted
Class ComparatorWithInfinity

java.lang.Object
  |
  +--net.sf.molae.pipe.sorted.ComparatorWithInfinity
All Implemented Interfaces:
Comparator

public final class ComparatorWithInfinity
extends Object
implements Comparator

Allows to define two constants for negative and positive infinity that are always less or greater than any other object, respecitively.


Constructor Summary
ComparatorWithInfinity(Comparator base, Object negativeInfinity, Object positiveInfinity)
          Constructs a ComparatorWithInfinity object.
 
Method Summary
 int compare(Object o1, Object o2)
          If either argument is positive or negative infinity as specified in the constructor, the corresponding result is returned, otherwise the base comparator is used.
 boolean equals(Object obj)
          Compares the specified object with this collection for equality.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ComparatorWithInfinity

public ComparatorWithInfinity(Comparator base,
                              Object negativeInfinity,
                              Object positiveInfinity)
Constructs a ComparatorWithInfinity object.
Parameters:
base - the underlying comparator.
negativeInfinity - an Object representing negative infinity.
positiveInfinity - an Object representing positive infinity.
Method Detail

compare

public int compare(Object o1,
                   Object o2)
If either argument is positive or negative infinity as specified in the constructor, the corresponding result is returned, otherwise the base comparator is used.
Specified by:
compare in interface Comparator
Throws:
ClassCastException - if o1 and o2 cannot be compared to one another using the comparator (or, if it is null, using natural ordering).
NullPointerException - if o1 or o2 is null and natural order is used, or if the comparator does not tolerate null elements.

equals

public boolean equals(Object obj)
Compares the specified object with this collection for equality. Returns true, iff the parameter is a ComparatorWithInfinity and all properties are equal.
Specified by:
equals in interface Comparator
Overrides:
equals in class Object
Parameters:
obj - the reference object with which to compare.
Returns:
true if the specified Object is equal to this comparator