📄 structureset.java
字号:
package org.jutil.structure;import org.jutil.java.collections.Visitor;import java.util.HashSet;import java.util.Set;/** * <p><b>DEPRECATED</b>A class of "components" for inplementing a 1-n binding. * This class is the 1 side of the binding (the side where the "n" * is in a UML diagram).</p> * * <p>This is actually a lightweight version of the APSet-APElement combination * of the <a href="http://www.beedra.org">Beedra</a> framework of Jan Dockx.</p> * * <p>This class is typically using in the following way. * See class StructureElement for class B.</p> * <pre><code>public class A { public A() { $b= new StructureSet(this); } public Set getBs() { return $b.getOtherEnds(); } public void addB(B b) { $b.add(b.getALink()); } public void removeB(B b) { $b.remove(b.getALink()); } private StructureSet $b;} * </code></pre> * @path $Source: /cvsroot/org-jutil/jutil.org/src/org/jutil/structure/StructureSet.java,v $ * @version $Revision: 1.7 $ * @date $Date: 2002/07/21 10:30:35 $ * @state $State: Exp $ * @author Marko van Dooren * @release $Name: $ * * @deprecated */public class StructureSet { /* The revision of this class */ public final static String CVS_REVISION ="$Revision: 1.7 $"; //@ public invariant contains(null) == false; //@ public invariant getObject() != null; /*@ @ public invariant (\forall StructureElement e; contains(e); @ e.getStructureSet() == this); @*/ /** * Initialize an empty StructureSet for the given object. * * @param object * The 1 side of the 1-n binding */ /*@ @ public behavior @ @ pre object != null; @ @ post getObject() == object; @ post (\forall StructureElement s;; !contains(s)); @*/ public StructureSet(Object object) { _object = object; _elements = new HashSet(); } /** * Return the object at the 1 side of the 1-n binding. */ public Object getObject() { return _object; } /** * Add the given StructureElement to this StructureSet. * * @param element * The StructureElement to be added. */ /*@ @ public behavior @ @ post contains(element) ==> element.getStructureSet() == null; @ post contains(element) ==> ! contains(element); @*/ public void remove(StructureElement element) { if (contains(element)) { element.connectTo(null); } } /** * Remove the given StructureElement from this StructureSet. * * @param element * The StructureElement to be removed. */ /*@ @ public behavior @ @ pre element != null; @ @ post element.getStructureSet() == this; @ post \old(element.getStructureSet()) != null && @ \old(element.getStructureSet()) != this ==> @ ! \old(element.getStructureSet()).contains(element); @ post contains(element); @*/ public void add(StructureElement element) { element.connectTo(this); } /** * Return a set containing the objects at the * n side of the 1-n binding. */ /*@ @ public behavior @ @ post (\forall Object o;; @ \result.contains(o) <==> @ (\exists StructureElement s; contains(s); @ s.getObject().equals(o))); @ post \result != null; @*/ public Set getOtherEnds() { final HashSet result = new HashSet(); new Visitor() { public void visit(Object element) { result.add(((StructureElement)element).getObject()); } }.applyTo(_elements); return result; } /** * Return a set containing the StructureElements at the * n side of the 1-n binding. */ /*@ @ public behavior @ @ post (\forall StructureElement s;; @ contains(s) <==> \result.contains(s)); @ post \result != null; @*/ public Set getStructureElements() { return new HashSet(_elements); } /** * Remove the given StructureElement from this StructureSet * * @param element * The element to be removed. */ /*@ @ behavior @ @ pre element != null; @ @ post ! contains(element); @*/ void unregister(StructureElement element) { _elements.remove(element); } /** * Add the given StructureElement to this StructureSet * * @param element * The element to be added. */ /*@ @ behavior @ @ pre element != null; @ @ post contains(element); @*/ void register(StructureElement element) { _elements.add(element); } /** * Return the size of the StructureSet */ /*@ @ public behavior @ @ post \result == (\num_of StructureElement e; contains(e);true); @*/ public int size() { return _elements.size(); } /** * Check whether or not the given element is connected to * this StructureSet. * * @param element * The element of which one wants to know if it is in * this StructureSet. */ public boolean contains(StructureElement element) { return _elements.contains(element); } /** * The set containing the StructureElements at the n side of the 1-n binding. */ /*@ @ private invariant ! _elements.contains(null); @ private invariant (\forall Object o; _elements.contains(o); @ o instanceof StructureElement); @*/ private HashSet _elements; /** * The object at the 1 side of the 1-n binding. */ /*@ @ private invariant _object != null; @*/ private Object _object;}/*<copyright>Copyright (C) 1997-2001. This software is copyrighted by the people and entities mentioned after the "@author" tags above, on behalf of the JUTIL.ORG Project. The copyright is dated by the dates after the "@date" tags above. All rights reserved.This software is published under the terms of the JUTIL.ORG SoftwareLicense version 1.1 or later, a copy of which has been included withthis distribution in the LICENSE file, which can also be found athttp://org-jutil.sourceforge.net/LICENSE. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the JUTIL.ORG Software License for more details.For more information, please see http://org-jutil.sourceforge.net/</copyright>*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -