org.jutil.java.collections
Class ExtendedComparator

java.lang.Object
  |
  +--org.jutil.java.collections.ExtendedComparator
All Implemented Interfaces:
java.util.Comparator
Direct Known Subclasses:
ComparableComparator, InverseComparator

public abstract class ExtendedComparator
extends java.lang.Object
implements java.util.Comparator

A Comparator with more convenient methods than java.util.Comparator.

Version:
$Revision: 1.2 $
Author:
Tom Schrijvers, Marko van Dooren

Constructor Summary
ExtendedComparator()
           
 
Method Summary
static ExtendedComparator ensureExtended(java.util.Comparator comparator)
          public behavior

pre comparator != null;

// The result must behave exactly the same as the given comparator.
post (\forall Object o1; ;
(\forall Object o2; ;
\result.compare(o1, o2) == comparator.compare(o1, o2)));
Ensure that the result is an ExtendedComparator.
 boolean greater(java.lang.Object first, java.lang.Object second)
          public behavior

post \result == (compare(first, second) > 0);
 java.lang.Object max(java.lang.Object first, java.lang.Object second)
          public behavior

post \result == first | \result == second;
post compare(\result, first) >= 0;
post compare(\result, second) >= 0;
 java.lang.Object min(java.lang.Object first, java.lang.Object second)
          public behavior

post \result == first | \result == second;
post compare(\result, first) <= 0;
post compare(\result, second) <= 0;
 boolean notGreater(java.lang.Object first, java.lang.Object second)
          public behavior

post \result == ! greater(first, second);
 boolean notSmaller(java.lang.Object first, java.lang.Object second)
          public behavior

post \result == ! smaller(first, second);
 boolean smaller(java.lang.Object first, java.lang.Object second)
          public behavior

post \result == (compare(first, second) < 0);
 
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
compare, equals
 

Constructor Detail

ExtendedComparator

public ExtendedComparator()
Method Detail

max

public java.lang.Object max(java.lang.Object first,
                            java.lang.Object second)
public behavior

post \result == first | \result == second;
post compare(\result, first) >= 0;
post compare(\result, second) >= 0;

Return the maximum of both objects. In case of a tie, any one of both can be returned.

Parameters:
first - The first object
second - The second object

min

public java.lang.Object min(java.lang.Object first,
                            java.lang.Object second)
public behavior

post \result == first | \result == second;
post compare(\result, first) <= 0;
post compare(\result, second) <= 0;

Return the minimum of both objects. In case of a tie, any one of both can be returned.

Parameters:
first - The first object
second - The second object

greater

public boolean greater(java.lang.Object first,
                       java.lang.Object second)
public behavior

post \result == (compare(first, second) > 0);

Check whether or not the first object is greater than the second one.

Parameters:
first - The first object
second - The second object

smaller

public boolean smaller(java.lang.Object first,
                       java.lang.Object second)
public behavior

post \result == (compare(first, second) < 0);

Check whether or not the first object is smaller than the second one.

Parameters:
first - The first object
second - The second object

notSmaller

public boolean notSmaller(java.lang.Object first,
                          java.lang.Object second)
public behavior

post \result == ! smaller(first, second);

Check whether or not the first object is greater than or equal to the second one.

Parameters:
first - The first object
second - The second object

notGreater

public boolean notGreater(java.lang.Object first,
                          java.lang.Object second)
public behavior

post \result == ! greater(first, second);

Check whether or not the first object is smaller than or equal to the second one.

Parameters:
first - The first object
second - The second object

ensureExtended

public static ExtendedComparator ensureExtended(java.util.Comparator comparator)
public behavior

pre comparator != null;

// The result must behave exactly the same as the given comparator.
post (\forall Object o1; ;
(\forall Object o2; ;
\result.compare(o1, o2) == comparator.compare(o1, o2)));
Ensure that the result is an ExtendedComparator. If the given Comparator is not an ExtendedComparator, it will be wrapped.
Parameters:
comparator - The comparator of which one wants an ExtendedComparator that behaves the same.