nz.ac.waikato.jdsl.core.api
Interface Comparator

All Superinterfaces:
EqualityComparator
All Known Implementing Classes:
ComparableComparator, ComparatorExtender, ComparatorReverser, IntegerComparator

public interface Comparator
extends EqualityComparator

Defines a total ordering for a set of objects. Its methods allow for the comparison of all objects in the set over which the comparator is defined. It is up to individual implementations to define the set over which they are valid and to reject those objects which they cannot compare by throwing ClassCastExceptions.

Consistency
The implementation should respect the following consistency constraints: for each pair of objects a,b such that isComparable(a,b)

Version:
JDSL 2.1.1
Author:
Maurizio Pizzonia (map), Luca Vismara (lv)

Method Summary
 int compare(java.lang.Object a, java.lang.Object b)
          A C-style comparison function that returns a negative value if the first object is less than the second, a positive value if the second object is less, and 0 if the two objects are equal.
 boolean isGreaterThan(java.lang.Object a, java.lang.Object b)
          Tests the strict order of two objects in the set over which this comparator is defined.
 boolean isGreaterThanOrEqualTo(java.lang.Object a, java.lang.Object b)
          Tests non-strict order of two objects in the universe over which this comparator is defined.
 boolean isLessThan(java.lang.Object a, java.lang.Object b)
          Tests the strict order of two objects in the set over which this comparator is defined.
 boolean isLessThanOrEqualTo(java.lang.Object a, java.lang.Object b)
          Tests non-strict order of two objects in the universe over which this comparator is defined.
 
Methods inherited from interface nz.ac.waikato.jdsl.core.api.EqualityComparator
isComparable, isEqualTo
 

Method Detail

compare

int compare(java.lang.Object a,
            java.lang.Object b)
            throws java.lang.ClassCastException
A C-style comparison function that returns a negative value if the first object is less than the second, a positive value if the second object is less, and 0 if the two objects are equal.

Parameters:
a - First Object to compare
b - Second Object to compare
Returns:
A negative value if a is less than b, 0 if they are equal, or a positive value if a is greater than b.
Throws:
java.lang.ClassCastException

isGreaterThan

boolean isGreaterThan(java.lang.Object a,
                      java.lang.Object b)
                      throws java.lang.ClassCastException
Tests the strict order of two objects in the set over which this comparator is defined.

Parameters:
a - First Object to compare
b - Second Object to compare
Returns:
True if and only if a is greater than b
Throws:
java.lang.ClassCastException - If either object passed in as a parameter is not a member of the set over which the comparator is defined.

isLessThan

boolean isLessThan(java.lang.Object a,
                   java.lang.Object b)
                   throws java.lang.ClassCastException
Tests the strict order of two objects in the set over which this comparator is defined.

Parameters:
a - First Object to compare
b - Second Object to compare
Returns:
True if and only if a is less than b
Throws:
java.lang.ClassCastException - If either object passed in as a parameter is not a member of the set over which the comparator is defined.

isGreaterThanOrEqualTo

boolean isGreaterThanOrEqualTo(java.lang.Object a,
                               java.lang.Object b)
                               throws java.lang.ClassCastException
Tests non-strict order of two objects in the universe over which this comparator is defined.

Parameters:
a - First Object to compare
b - Second Object to compare
Returns:
True if a is greater b or if a is equal to b
Throws:
java.lang.ClassCastException - If either object passed in as a parameter is not a member of the set over which the comparator is defined.

isLessThanOrEqualTo

boolean isLessThanOrEqualTo(java.lang.Object a,
                            java.lang.Object b)
                            throws java.lang.ClassCastException
Tests non-strict order of two objects in the universe over which this comparator is defined.

Parameters:
a - First Object to compare
b - Second Object to compare
Returns:
True if a is less than b or if a is equal to b
Throws:
java.lang.ClassCastException - If either object passed in as a parameter is not a member of the set over which the comparator is defined.


Copyright © 2009 ModelJUnit Project. All Rights Reserved.