|
RECODER 0.92 | |||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||
public interface Order
This interface defines two order relation between objects. The
lessOrEquals predicate defines an order, the less
predicate defines a strict order. Both orders may be partial. The following
must hold:
lessOrEquals(x, y) && lessOrEquals(y, x)
implies equals(x, y) and less(x, y)
implies !less(y, x)lessOrEquals(x, x) and !less(x, x)
(less(x, y) && less(y, z)) implies
less(x, z) (same for lessOrEquals).isComparable(x, y) implies
less(x, y) || less(y, x)
lessOrEquals(x, y) == (less(x, y) || equals(x, y))
, this interface extends an equality relation.
The usual way is to calculate all relations at once and returning a
status code such as int compareTo(x, y). However, this
function alone can not capture partial orders and is not efficient if the
single comparisons become costly - see for instance the subset relation. The
prize to pay for the more explicite interface is a slight code overhead, but
this should not lead to a noticeable loss of performance. And of course,
lessOrEquals(x, y) should be a bit more comprehensible
than compareTo(x, y) <= 0.
Whether or not objects of different type or null objects are
allowed is up to the specific implementation. This isComparable
predicate should be defined for all objects. The orders are total, if
the predicate yields true for any input - with the possible exception of
null objects. If two objects are not comparable, the result of
the other predicates is not defined unless stated explicitely.
| Nested Class Summary | |
|---|---|
static class |
Order.CustomLexicalOrder
Custom lexical order implementation comparing objects by comparison of a unicode string mapping. |
static class |
Order.Identity
Identity order implementation comparing objects by address. |
static class |
Order.Lexical
Lexical order implementation comparing objects by their unicode string representations. |
static class |
Order.Natural
Natural order implementation using the inherited default methods. |
| Field Summary | |
|---|---|
static Order |
IDENTITY
Identity order relation object based on the objects' identities. |
static Order |
LEXICAL
Lexical order relation object based on the objects' textual representation. |
static Order |
NATURAL
Natural order relation object based on the objects' natural hash codes. |
| Method Summary | |
|---|---|
boolean |
greater(java.lang.Object x,
java.lang.Object y)
Check if the first object is greater than the second one. |
boolean |
greaterOrEquals(java.lang.Object x,
java.lang.Object y)
Check if the first object is greater than or equals the second one. |
boolean |
isComparable(java.lang.Object x,
java.lang.Object y)
Check if both objects can be related. |
boolean |
less(java.lang.Object x,
java.lang.Object y)
Check if the first object is less than the second one. |
boolean |
lessOrEquals(java.lang.Object x,
java.lang.Object y)
Check if the first object is less than or equals the second one. |
| Methods inherited from interface recoder.util.Equality |
|---|
equals |
| Field Detail |
|---|
static final Order NATURAL
null objects.
static final Order IDENTITY
null objects (which are minimum
elements).
static final Order LEXICAL
null
objects.
| Method Detail |
|---|
boolean isComparable(java.lang.Object x,
java.lang.Object y)
x - the first object.y - the second object.
boolean less(java.lang.Object x,
java.lang.Object y)
less(x, y) implies !equals(x, y)
.
x - the first object.y - the second object.
boolean greater(java.lang.Object x,
java.lang.Object y)
greater(x, y) implies
!equals(x, y).
x - the first object.y - the second object.
boolean lessOrEquals(java.lang.Object x,
java.lang.Object y)
x - the first object.y - the second object.
boolean greaterOrEquals(java.lang.Object x,
java.lang.Object y)
x - the first object.y - the second object.
|
RECODER 0.92 | |||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||