001: /*
002: *
003: * Wilos Is a cLever process Orchestration Software - http://www.wilos-project.org
004: * Copyright (C) 2006-2007 Paul Sabatier University, IUP ISI (Toulouse, France) <massie@irit.fr>
005: * Copyright (C) 2007 Mathieu BENOIT <mathieu-benoit@hotmail.fr>
006: * Copyright (C) 2007-2008 Paul Sabatier University, IUP ISI (Toulouse, France) <massie@irit.fr>
007: *
008: * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
009: * General Public License as published by the Free Software Foundation; either version 2 of the License,
010: * or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
013: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License along with this program; if not,
017: * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
018: */
019:
020: package wilos.model.misc.concreteactivity;
021:
022: import java.util.Set;
023: import java.util.SortedSet;
024: import java.util.TreeSet;
025:
026: import org.apache.commons.lang.builder.EqualsBuilder;
027: import org.apache.commons.lang.builder.HashCodeBuilder;
028:
029: import wilos.model.misc.concretebreakdownelement.ConcreteBreakdownElement;
030: import wilos.model.misc.concreteworkbreakdownelement.ConcreteWorkBreakdownElement;
031: import wilos.model.misc.project.Project;
032: import wilos.model.spem2.activity.Activity;
033:
034: /**
035: *
036: * A ConcreteActivity is a specific {@link Activity} for a {@link Project}.
037: *
038: */
039: public class ConcreteActivity extends ConcreteWorkBreakdownElement
040: implements Cloneable {
041:
042: private SortedSet<ConcreteBreakdownElement> concreteBreakdownElements;
043:
044: private Activity activity;
045:
046: /**
047: * Class constructor.
048: *
049: */
050: public ConcreteActivity() {
051: super ();
052: this .concreteBreakdownElements = new TreeSet<ConcreteBreakdownElement>();
053: }
054:
055: /**
056: * Compares an object in parameter with the current instance of the class
057: * and returns true if both those objects are equals.
058: *
059: * @param obj
060: * the object to be compare with the current instance of
061: * ConcreteActivity
062: * @return true if the object is the same or has the same values as the
063: * current instance of ConcreteActivity, false otherwise
064: */
065: public boolean equals(Object obj) {
066: if (obj instanceof ConcreteActivity == false) {
067: return false;
068: }
069: if (this == obj) {
070: return true;
071: }
072: ConcreteActivity concreteActivity = (ConcreteActivity) obj;
073: return new EqualsBuilder().appendSuper(
074: super .equals(concreteActivity)).append(this .activity,
075: concreteActivity.activity).append(
076: this .concreteBreakdownElements,
077: concreteActivity.concreteBreakdownElements).isEquals();
078: }
079:
080: /**
081: * Returns a hash code value for the object. This method is supported for
082: * the benefit of hash tables.
083: *
084: * @return the hash code of the current instance of ConcreteActivity
085: */
086: public int hashCode() {
087: return new HashCodeBuilder(17, 37)
088: .appendSuper(super .hashCode()).append(this .activity)
089: .toHashCode();
090: }
091:
092: /**
093: * Returns a copy of the current instance of ConcreteActivity.
094: *
095: * @return a copy of the ConcreteActivity
096: * @throws CloneNotSupportedException
097: */
098: public ConcreteActivity clone() throws CloneNotSupportedException {
099: ConcreteActivity concreteActivity = new ConcreteActivity();
100: concreteActivity.copy(this );
101: return concreteActivity;
102: }
103:
104: /**
105: * Copy the values of the specified ConcreteActivity into the current
106: * instance of the class.
107: *
108: * @param _concreteActivity
109: * the concreteActivity to copy.
110: */
111: protected void copy(final ConcreteActivity _concreteActivity) {
112: super .copy(_concreteActivity);
113: this .activity = _concreteActivity.getActivity();
114: this .concreteBreakdownElements.addAll(_concreteActivity
115: .getConcreteBreakdownElements());
116: }
117:
118: /*
119: * Relation between ConcreteActivity and ConcreteBreakdownElement
120: */
121:
122: /**
123: * Adds a ConcreteBreakdownElement to the Collection of the current
124: * instance. Defines the relation between ConcreteActivity and
125: * ConcreteBreakdownElement.
126: *
127: * @param _concreteBeakdownElement
128: * the concreteBreakdownElement to be add
129: */
130:
131: public void addConcreteBreakdownElement(
132: ConcreteBreakdownElement _concreteBeakdownElement) {
133: this .getConcreteBreakdownElements().add(
134: _concreteBeakdownElement);
135: _concreteBeakdownElement.getSuperConcreteActivities().add(this );
136: }
137:
138: /**
139: * Adds a Set of ConcreteBreakdownElement to the current instance. Defines
140: * for them all the relation between ConcreteActivity and
141: * ConcreteBreakdownElement.
142: *
143: * @param _concreteBreakdownElements
144: * the Set of ConcreteBreakdownElement to add
145: */
146: public void addAllConcreteBreakdownElements(
147: Set<ConcreteBreakdownElement> _concreteBreakdownElements) {
148: for (ConcreteBreakdownElement cbde : _concreteBreakdownElements) {
149: cbde.addSuperConcreteActivity(this );
150: }
151: }
152:
153: /**
154: * Removes from the instance Collection a specified
155: * ConcreteBreakdownElement. Deletes the link between the ConcreteActivity
156: * and the ConcreteBreakdownElement.
157: *
158: * @param _concreteBreakdownElement
159: * the ConcreteBreakdownElement to be remove
160: */
161: public void removeConcreteBreakdownElement(
162: ConcreteBreakdownElement _concreteBreakdownElement) {
163: _concreteBreakdownElement.getSuperConcreteActivities().remove(
164: this );
165: this .getConcreteBreakdownElements().remove(
166: _concreteBreakdownElement);
167: }
168:
169: /**
170: * Removes all the ConcreteBreakdownElement from the Collection of the
171: * current instance.
172: */
173: public void removeAllConcreteBreakdownElements() {
174: for (ConcreteBreakdownElement bde : this
175: .getConcreteBreakdownElements())
176: bde.getSuperConcreteActivities().remove(this );
177: this .getConcreteBreakdownElements().clear();
178: }
179:
180: /*
181: * Relation between ConcreteActivity and Activity
182: *
183: */
184:
185: /**
186: * Specifies the Activity related to the current ConcreteActivity. Adds that
187: * ConcreteActivity to the Activity's Collection.
188: *
189: * @param _activity
190: * the Activity related to the current ConcreteActivity
191: */
192: public void addActivity(Activity _activity) {
193: this .activity = _activity;
194: _activity.addConcreteActivity(this );
195: }
196:
197: /**
198: * Remove the relation between the specified Activity and the
199: * ConcreteActivity.
200: *
201: * @param _activity
202: * the activity to be unlinked with the ConcreteActivity
203: */
204: public void removeActivity(Activity _activity) {
205: this .activity = null;
206: _activity.removeConcreteActivity(this );
207: }
208:
209: /*
210: * Getter & Setter.
211: *
212: */
213:
214: /**
215: * Returns a SortedSet of ConcreteBreakdownElement related to the
216: * ConcreteActivity.
217: *
218: * @return the SortedSet of ConcreteBreakdownElement
219: */
220: public SortedSet<ConcreteBreakdownElement> getConcreteBreakdownElements() {
221: return concreteBreakdownElements;
222: }
223:
224: /**
225: * Initialize the ConcreteActivity's Collection of ConcreteBreakdownElement
226: * with the specified SortedSet.
227: *
228: * @param concreteBreakdownElements
229: * the SortedSet to be assigned to the ConcreteActivity
230: */
231: public void setConcreteBreakdownElements(
232: SortedSet<ConcreteBreakdownElement> concreteBreakdownElements) {
233: this .concreteBreakdownElements = concreteBreakdownElements;
234: }
235:
236: /**
237: * Returns the Activity that is in relation with the ConcreteActivity.
238: *
239: * @return the Activity related to the ConcreteActivity
240: */
241: public Activity getActivity() {
242: return activity;
243: }
244:
245: /**
246: * Initialize the ConcreteActivity's Activity with the specified one.
247: *
248: * @param activity
249: * the Activity to be assigned to the ConcreteActivity
250: */
251: public void setActivity(Activity activity) {
252: this.activity = activity;
253: }
254: }
|