| java.lang.Comparable
All known Subclasses: de.uka.ilkd.key.logic.op.Metavariable, de.uka.ilkd.key.rule.export.DisplayNameModelInfo, java.lang.Byte, java.io.File, java.lang.Float, java.lang.Long, java.lang.Integer, de.uka.ilkd.key.rule.export.OptionModelInfo, java.lang.Character, de.uka.ilkd.key.ocl.gf.GFCommand, de.uka.ilkd.key.proof.reuse.ReusePoint, de.uka.ilkd.key.strategy.RuleAppContainer, java.util.Date, de.uka.ilkd.key.rule.export.CategoryModelInfo, java.io.ObjectStreamField, java.math.BigInteger, java.lang.Double,
Comparable | public interface Comparable (Code) | | Interface for objects that can be ordering among other objects. The
ordering can be total, such that two objects only compare equal
if they are also equal by the equals method, or partial such
that this is not necessarily true. For example, a case-sensitive
dictionary order comparison of Strings is total, but if it is
case-insensitive it is partial, because "abc" and "ABC" compare as
equal even though "abc".equals("ABC") returns false. However, if you use
a partial ordering, it is a good idea to document your class as
"inconsistent with equals", because the behavior of your class in a
SortedMap will be different than in a HashMap.
Lists, arrays, and sets of objects that implement this interface can
be sorted automatically, without the need for an explicit
java.util.Comparator . Note that e1.compareTo(null)
should throw an Exception; as should comparison between incompatible
classes.
author: Geoff Berry author: Warren Levy See Also: java.util.Comparator See Also: java.util.Collections.sort(java.util.List) See Also: java.util.Arrays.sort(Object[]) See Also: java.util.SortedSet See Also: java.util.SortedMap See Also: java.util.TreeSet See Also: java.util.TreeMap since: 1.2 |
Method Summary | |
int | compareTo(Object o) Compares this object with another, and returns a numerical result based
on the comparison. |
compareTo | int compareTo(Object o)(Code) | | Compares this object with another, and returns a numerical result based
on the comparison. If the result is negative, this object sorts less
than the other; if 0, the two are equal, and if positive, this object
sorts greater than the other. To translate this into boolean, simply
perform o1.compareTo(o2) <op> 0 , where op
is one of <, <=, =, !=, >, or >=.
You must make sure that the comparison is mutual, ie.
sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) (where sgn() is
defined as -1, 0, or 1 based on the sign). This includes throwing an
exception in either direction if the two are not comparable; hence,
compareTo(null) should always throw an Exception.
You should also ensure transitivity, in two forms:
x.compareTo(y) > 0 && y.compareTo(z) > 0 implies
x.compareTo(z) > 0 ; and x.compareTo(y) == 0
implies x.compareTo(z) == y.compareTo(z) .
Parameters: o - the object to be compared an integer describing the comparison throws: NullPointerException - if o is null throws: ClassCastException - if o cannot be compared |
|
|