jdsl.core.ref
Class ComparableComparator
java.lang.Object
jdsl.core.ref.AbstractComparator
jdsl.core.ref.ComparableComparator
- All Implemented Interfaces:
- Comparator, EqualityComparator
- public class ComparableComparator
- extends AbstractComparator
- implements Comparator
Implementation of JDSL's Comparator interface in terms of the JDK's
Comparable interface. Compares any two Comparables, regardless of
their actual type.
- Version:
- JDSL 2.1.1
- Author:
- Mike Boilen (mgb), Luca Vismara (lv)
|
Method Summary |
int |
compare(Object x1,
Object x2)
Invokes the compareTo method of x1 on
x2. |
boolean |
isComparable(Object o)
Allows a container (or any client) to find out whether an object is
a member of the ordered set over which this comparator is defined. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ComparableComparator
public ComparableComparator()
compare
public int compare(Object x1,
Object x2)
throws ClassCastException
- Invokes the
compareTo method of x1 on
x2.
- Specified by:
compare in interface Comparator- Specified by:
compare in class AbstractComparator
- Parameters:
x1 - A Comparable to which x2 will
be compared.x2 - An Object which will be compared to
x1
- Returns:
- a negative value if a < b, zero if a == b, and a positive
value if a > b
- Throws:
ClassCastException - if x1 is
null or not a Comparable- See Also:
Comparable
isComparable
public boolean isComparable(Object o)
- Description copied from interface:
EqualityComparator
- Allows a container (or any client) to find out whether an object is
a member of the ordered set over which this comparator is defined.
- Specified by:
isComparable in interface EqualityComparator
- Parameters:
o - Object you propose to compare with this comparator
- Returns:
- Whether o is a non-null
Comparable - See Also:
Comparable