|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--org.jutil.relation.Relation
|
+--org.jutil.relation.ReferenceSet
A class of Relation components for implementing a binding in which the object of the Reference has a relation with N other objects. This component behaves as a set.

In UML this class is used for implementing multiplicity n:

In Java, you get the following situation.

Note that the question mark is represented by a Relation object since
we don't know its multiplicity. The double binding between the ReferenceSet
object and A is made by passing this to the constructor of
ReferenceSet.
This is actually a lightweight version of the APSet class. of the Beedra framework of Jan Dockx.
This class is typically using in the following way.
public class A {
public A() {
_b= new ReferenceSet(this);
}
public List getBs() {
return _b.getOtherEnds();
}
// public Set getBs() {
// return new TreeSet(_b.getOtherEnds());
// }
public void addB(B b) {
_b.add(b.getALink());
}
public void removeB(B b) {
_b.remove(b.getALink());
}
private ReferenceSet _b;
}
The other class must have a method getALink(), which returns a
Relation object that represents the other side
of the bi-directional binding. In case the two classes are not in the same package that means
that getALink() must be public there, but that is also the case when
not working with these components. Note that if the binding should not be mutable from class
A the addB() may be removed. Similarly, getBLink() may
be removed if the binding is not mutable from class B.
If getBs() must return a Set, you should add the result of _b.getOtherEnds()
to a new Set (e.g. TreeSet). The general method getOtherEnds() must return a List
because in some bindings the order may be important.
| Class Specifications |
|
public invariant contains(null) == false; public invariant getObject() != null; public invariant ( \forall Relation e; contains(e); e.contains(this)); |
| Field Summary | |
static java.lang.String |
CVS_REVISION
|
| Constructor Summary | |
ReferenceSet(java.lang.Object object)
Initialize an empty ReferenceSet for the given object. |
|
| Method Summary | |
void |
add(Relation element)
Add the given Relation to this ReferenceSet. |
boolean |
contains(Relation element)
Check whether or not the given element is connected to this ReferenceSet. |
java.util.List |
getOtherEnds()
Return a set containing the objects at the n side of the 1-n binding. |
java.util.List |
getOtherRelations()
Return a set containing the Relations at the other side of this binding. |
protected boolean |
isValidElement(Relation relation)
|
protected void |
register(Relation element)
Add the given Relation to this ReferenceSet |
boolean |
registered(java.util.List oldConnections,
Relation registered)
|
void |
remove(Relation other)
Remove the given Relation from this ReferenceSet. |
int |
size()
Return the size of the ReferenceSet |
protected void |
unregister(Relation element)
Remove the given Relation from this ReferenceSet |
boolean |
unregistered(java.util.List oldConnections,
Relation unregistered)
|
| Methods inherited from class org.jutil.relation.Relation |
equals, getObject |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final java.lang.String CVS_REVISION
| Constructor Detail |
public ReferenceSet(java.lang.Object object)
object - The object on this side of the binding| Method Detail |
public void remove(Relation other)
element - The Relation to be removed.public void add(Relation element)
element - The Relation to be added.public java.util.List getOtherEnds()
public java.util.List getOtherRelations()
protected void unregister(Relation element)
element - The element to be removed.protected void register(Relation element)
element - The element to be added.
public boolean registered(java.util.List oldConnections,
Relation registered)
public boolean unregistered(java.util.List oldConnections,
Relation unregistered)
protected boolean isValidElement(Relation relation)
public int size()
public boolean contains(Relation element)
contains in class Relationelement - The element of which one wants to know if it is in
this ReferenceSet.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||