|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Comparator
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)
compare(a, b) == 0
isEqualTo(a, b)
compare(a, b) < 0
isLessThan(a, b)
!isGreaterThanOrEqualTo(a, b)
compare(a, b) > 0
isGreaterThan(a, b)
!isLessThanOrEqualTo(a, b)
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 |
---|
int compare(java.lang.Object a, java.lang.Object b) throws java.lang.ClassCastException
a
- First Object to compareb
- Second Object to compare
java.lang.ClassCastException
boolean isGreaterThan(java.lang.Object a, java.lang.Object b) throws java.lang.ClassCastException
a
- First Object to compareb
- Second Object to compare
java.lang.ClassCastException
- If either object passed in as a parameter
is not a member of the set over which the comparator is defined.boolean isLessThan(java.lang.Object a, java.lang.Object b) throws java.lang.ClassCastException
a
- First Object to compareb
- Second Object to compare
java.lang.ClassCastException
- If either object passed in as a parameter
is not a member of the set over which the comparator is defined.boolean isGreaterThanOrEqualTo(java.lang.Object a, java.lang.Object b) throws java.lang.ClassCastException
a
- First Object to compareb
- Second Object to compare
java.lang.ClassCastException
- If either object passed in as a parameter
is not a member of the set over which the comparator is defined.boolean isLessThanOrEqualTo(java.lang.Object a, java.lang.Object b) throws java.lang.ClassCastException
a
- First Object to compareb
- Second Object to compare
java.lang.ClassCastException
- If either object passed in as a parameter
is not a member of the set over which the comparator is defined.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |