org.jutil.relation
Class Relation

java.lang.Object
  |
  +--org.jutil.relation.Relation
Direct Known Subclasses:
Reference, ReferenceSet

public abstract class Relation
extends java.lang.Object

A class of objects that can be used to set up bi-directional relations between objects.

This class provides the general interface that is needed in order to create different types of bindings that can be created by taking two arbitrary multiplicities.


Constructor Summary
Relation(java.lang.Object object)
          Initialize a new Relation for the given object.
 
Method Summary
 boolean contains(Relation relation)
          Check whether or not the given Relation is connected to this one.
 boolean equals(java.lang.Object other)
           
 java.lang.Object getObject()
          Return the object on the n side of the 1-n binding represented by this OneSide
abstract  java.util.List getOtherEnds()
          Return the objects on the other side of the binding.
abstract  java.util.List getOtherRelations()
          Return the Relations on the other side of the binding.
protected abstract  boolean isValidElement(Relation relation)
          Check whether or not the given Relation may be connected to this Relation.
protected abstract  void register(Relation other)
          Add the given Relation as a participant in this binding.
abstract  boolean registered(java.util.List oldConnections, Relation registered)
          Check whether or not the current state corresponds to connecting to the given Relation when being connected to the Relations in the given list.
protected abstract  void unregister(Relation other)
          Remove the given Relation as a participant in this binding.
abstract  boolean unregistered(java.util.List oldConnections, Relation unregistered)
          Check whether or not the current state corresponds to disconnecting from the given Relation when being connected to the Relations in the given list.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Relation

public Relation(java.lang.Object object)
Initialize a new Relation for the given object. The new Relation will be unconnected.

Parameters:
object - The object at this side of the binding.

Specifications:
public behavior
requires object != null;
ensures getObject() == object;
Method Detail

contains

public boolean contains(Relation relation)
Check whether or not the given Relation is connected to this one.

Parameters:
relation - The relation which is possibly on the other end of the binding.

Specifications:
public behavior
ensures \result == getOtherRelations().contains(relation);

equals

public boolean equals(java.lang.Object other)
Specifications:
     also
public behavior
ensures \result == (other == this);

register

protected abstract void register(Relation other)
Add the given Relation as a participant in this binding.

Specifications:
protected behavior
requires isValidElement(other);
ensures registered(\old(getOtherRelations()),other);

unregister

protected abstract void unregister(Relation other)
Remove the given Relation as a participant in this binding.

Specifications:
protected behavior
requires contains(other);
ensures unregistered(\old(getOtherRelations()),other);

isValidElement

protected abstract boolean isValidElement(Relation relation)
Check whether or not the given Relation may be connected to this Relation.

Specifications:
public behavior
ensures \result == true|\result == false;

registered

public abstract boolean registered(java.util.List oldConnections,
                                   Relation registered)
Check whether or not the current state corresponds to connecting to the given Relation when being connected to the Relations in the given list.

Parameters:
oldConnections - The List of Relations this Relation was connected to before.
registered - The Relation this Relation has connected to.

Specifications:
public behavior
requires oldConnections != null;
requires !oldConnections.contains(null);
requires ( \forall Object o; oldConnections.contains(o); o instanceof Relation);
ensures !contains(registered) ==> \result == false;
ensures !( \forall Relation r; r != registered; oldConnections.contains(r) == contains(r)) ==> \result == false;

unregistered

public abstract boolean unregistered(java.util.List oldConnections,
                                     Relation unregistered)
Check whether or not the current state corresponds to disconnecting from the given Relation when being connected to the Relations in the given list.

Parameters:
oldConnections - The List of Relations this Relation was connected to before.
registered - The Relation this Relation has connected to.

Specifications:
public behavior
requires oldConnections != null;
requires !oldConnections.contains(null);
requires ( \forall Object o; oldConnections.contains(o); o instanceof Relation);
ensures contains(unregistered) ==> \result == false;
ensures !oldConnections.contains(unregistered) ==> \result == false;
ensures !( \forall Relation r; r != unregistered; oldConnections.contains(r) == contains(r)) ==> \result == false;

getOtherEnds

public abstract java.util.List getOtherEnds()
Return the objects on the other side of the binding.

Specifications:
public behavior
ensures \result != null;
ensures \result .size() == getOtherRelations().size();
ensures ( \forall Object o; \result .contains(o); ( \exists Relation r; getOtherRelations().contains(r); r.getObject() == o));

getOtherRelations

public abstract java.util.List getOtherRelations()
Return the Relations on the other side of the binding.

Specifications:
public behavior
ensures \result != null;
ensures ( \forall Object o; \result .contains(o); o instanceof Relation);
ensures !\result .contains(null);

getObject

public java.lang.Object getObject()
Return the object on the n side of the 1-n binding represented by this OneSide

Specifications:
public behavior
ensures \result != null;