001: /*
002: * Wilos Is a cLever process Orchestration Software - http://www.wilos-project.org
003: * Copyright (C) 2006-2007 Paul Sabatier University, IUP ISI (Toulouse, France) <massie@irit.fr>
004: * Copyright (C) 2007 Mathieu BENOIT <mathieu-benoit@hotmail.fr>
005: *
006: * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
007: * General Public License as published by the Free Software Foundation; either version 2 of the License,
008: * or (at your option) any later version.
009: *
010: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
011: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License along with this program; if not,
015: * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
016: */
017:
018: package wilos.model.spem2.task;
019:
020: import org.apache.commons.lang.builder.EqualsBuilder;
021: import org.apache.commons.lang.builder.HashCodeBuilder;
022:
023: import wilos.model.spem2.element.Element;
024:
025: /**
026: *
027: * This class represents a section which represents structural subsections of a taskDefinition.
028: *
029: */
030: public class Step extends Element implements Cloneable,
031: Comparable<Step> {
032:
033: /**
034: * the attached taskDefinition
035: */
036: private TaskDefinition taskDefinition;
037:
038: /**
039: * Default constructor
040: */
041: public Step() {
042: super ();
043: }
044:
045: /**
046: * Returns a copy of the current instance of Step
047: *
048: * @return a copy of the Step
049: * @throws CloneNotSupportedException
050: */
051: @Override
052: public Step clone() throws CloneNotSupportedException {
053: Step step = new Step();
054: step.copy(this );
055: return step;
056: }
057:
058: /**
059: * Copy the values of the specified Step into the current instance
060: * of the class.
061: *
062: * @param _step
063: * The Step to copy.
064: */
065: protected void copy(final Step _step) {
066: super .copy(_step);
067: this .taskDefinition = _step.getTaskDefinition();
068: }
069:
070: /**
071: * Defines if the specified Object is the same or has the same values as the
072: * current instance of the Step.
073: *
074: * @param obj
075: * the Object to be compare to the Step
076: * @return true if the specified Object is the same, false otherwise
077: */
078: public boolean equals(Object obj) {
079: if (obj instanceof Step == false) {
080: return false;
081: }
082: if (this == obj) {
083: return true;
084: }
085: Step step = (Step) obj;
086: return new EqualsBuilder().appendSuper(super .equals(step))
087: .append(this .taskDefinition, step.taskDefinition)
088: .isEquals();
089: }
090:
091: /**
092: * Returns a hash code value for the object. This method is supported for
093: * the benefit of hash tables.
094: *
095: * @return the hash code of the current instance of Step
096: */
097: public int hashCode() {
098: return new HashCodeBuilder(17, 37)
099: .appendSuper(super .hashCode()).append(
100: this .taskDefinition).toHashCode();
101: }
102:
103: /**
104: * Compares the Step in parameter with the current instance of the class.
105: *
106: * @return 0 if both the Step are equals, -1 otherwise
107: */
108: public int compareTo(Step _step) {
109: // Return 0, if this is equal to _step.
110: if (this .equals(_step))
111: return 0;
112: else
113: return -1;
114: }
115:
116: /**
117: * Add a step to a TaskDefiniton
118: *
119: * @param _taskDefinition
120: */
121: public void addTaskDefinition(TaskDefinition _taskDefinition) {
122: this .setTaskDefinition(_taskDefinition);
123: _taskDefinition.getSteps().add(this );
124: }
125:
126: /**
127: * Detach a step to its TaskDefinition
128: *
129: * @param _taskDefinition
130: */
131: public void removeTaskDefinition(TaskDefinition _taskDefinition) {
132: _taskDefinition.getSteps().remove(this );
133: this .taskDefinition = null;
134: }
135:
136: /**
137: * Getter of taskDefinition.
138: *
139: * @return the taskDefinition.
140: */
141: public TaskDefinition getTaskDefinition() {
142: return this .taskDefinition;
143: }
144:
145: /**
146: * Setter of taskDefinition.
147: *
148: * @param _taskDefinition
149: * The taskDefinition to set.
150: */
151: public void setTaskDefinition(TaskDefinition _taskDefinition) {
152: this.taskDefinition = _taskDefinition;
153: }
154: }
|