RECODER 0.92

recoder.util
Interface Order

All Superinterfaces:
Equality
All Known Implementing Classes:
NamedModelElement.LexicalOrder, Order.CustomLexicalOrder, Order.Identity, Order.Lexical, Order.Natural, ProgramModelElement.LexicalOrder, Relations.ModelElementLexicalOrder

public interface Order
extends Equality

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:

As both relations are related by
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.

Author:
AL

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

NATURAL

static final Order NATURAL
Natural order relation object based on the objects' natural hash codes. The order is total except for null objects.


IDENTITY

static final Order IDENTITY
Identity order relation object based on the objects' identities. The order is total, including null objects (which are minimum elements).


LEXICAL

static final Order LEXICAL
Lexical order relation object based on the objects' textual representation. The order is total except for null objects.

Method Detail

isComparable

boolean isComparable(java.lang.Object x,
                     java.lang.Object y)
Check if both objects can be related.

Parameters:
x - the first object.
y - the second object.
Returns:
true if both objects can be compared, false otherwise.

less

boolean less(java.lang.Object x,
             java.lang.Object y)
Check if the first object is less than the second one. This comparison is strict: less(x, y) implies !equals(x, y) .

Parameters:
x - the first object.
y - the second object.
Returns:
true if the first object is less than the second one.

greater

boolean greater(java.lang.Object x,
                java.lang.Object y)
Check if the first object is greater than the second one. This comparison is strict: greater(x, y) implies !equals(x, y).

Parameters:
x - the first object.
y - the second object.
Returns:
true if the first object is greater than the second one.

lessOrEquals

boolean lessOrEquals(java.lang.Object x,
                     java.lang.Object y)
Check if the first object is less than or equals the second one.

Parameters:
x - the first object.
y - the second object.
Returns:
true if the first object is less than or equals the second one.

greaterOrEquals

boolean greaterOrEquals(java.lang.Object x,
                        java.lang.Object y)
Check if the first object is greater than or equals the second one.

Parameters:
x - the first object.
y - the second object.
Returns:
true if the first object is greater than or equals the second one.

RECODER 0.92