Changeset 1146 for trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskBuilder.java
- Timestamp:
- 04/04/13 16:06:07 (11 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskBuilder.java
r1126 r1146 17 17 import java.util.List; 18 18 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 19 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 20 21 import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 21 22 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 22 23 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 23 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder; 24 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 24 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 25 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; 26 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 27 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; 28 import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 25 29 26 30 /** … … 30 34 * @author 2012, last modified by $Author: patrick$ 31 35 */ 32 public class TaskTreeBuilder implements ITaskTreeBuilder { 36 public class TaskBuilder implements ITaskBuilder { 37 38 /* (non-Javadoc) 39 * @see ITaskBuilder#addChild(ITaskInstance, ITaskInstance) 40 */ 41 @Override 42 public void addChild(ITaskInstance parent, ITaskInstance child) throws IllegalArgumentException 43 { 44 if (!(parent instanceof TaskInstance)) { 45 throw new IllegalArgumentException 46 ("illegal type of task instance provided: " + parent.getClass()); 47 } 48 49 if (!(child instanceof TaskInstance)) { 50 throw new IllegalArgumentException 51 ("illegal type of task instance provided: " + parent.getClass()); 52 } 53 54 // check, that the correct number of children for the distinct types are added 55 ITask task = parent.getTask(); 56 57 if (task instanceof IEventTask) { 58 throw new IllegalArgumentException 59 ("can not add children to a task instance of an event task"); 60 } 61 else if (task instanceof ISelection) { 62 if (parent.getChildren().size() > 0) { 63 throw new IllegalArgumentException 64 ("the instance of a selection must have at most one child"); 65 } 66 } 67 else if (task instanceof IOptional) { 68 if (parent.getChildren().size() > 1) { 69 throw new IllegalArgumentException 70 ("the instance of an optional must have at most one child"); 71 } 72 } 73 /* else if (task instanceof IIteration) { 74 for (ITaskInstance childInstance : parent.getChildren()) { 75 if (!childInstance.getTask().equals(child.getTask())) { 76 throw new IllegalArgumentException 77 ("all children of an instance of an iteration must have exactly the " + 78 "same type"); 79 } 80 } 81 } 82 83 boolean foundChildTask = false; 84 if (parent.getTask() instanceof IStructuringTemporalRelationship) { 85 IStructuringTemporalRelationship parentTask = 86 (IStructuringTemporalRelationship) parent.getTask(); 87 88 for (ITask parentTaskChild : parentTask.getChildren()) { 89 if (parentTaskChild.equals(child.getTask())) { 90 foundChildTask = true; 91 break; 92 } 93 } 94 } 95 else if (parent.getTask() instanceof IMarkingTemporalRelationship) { 96 IMarkingTemporalRelationship parentTask = 97 (IMarkingTemporalRelationship) parent.getTask(); 98 99 foundChildTask = parentTask.getMarkedTask() != null ? 100 parentTask.getMarkedTask().equals(child.getTask()) : false; 101 } 102 103 if (!foundChildTask) { 104 throw new IllegalArgumentException 105 ("the task of the child instance to be added does not belong to the children " + 106 "of the task of the parent instance"); 107 }*/ 108 109 // finally, after all checks are positive, add the child 110 ((TaskInstance) parent).addChild(child); 111 } 112 113 /* (non-Javadoc) 114 * @see ITaskBuilder#addExecutedTask(IUserSession, ITaskInstance) 115 */ 116 @Override 117 public void addExecutedTask(IUserSession session, ITaskInstance taskInstance) { 118 if (!(session instanceof UserSession)) { 119 throw new IllegalArgumentException 120 ("illegal type of session provided: " + session.getClass()); 121 } 122 123 if (!(taskInstance instanceof TaskInstance)) { 124 throw new IllegalArgumentException 125 ("illegal type of task instance provided: " + taskInstance.getClass()); 126 } 127 128 ((UserSession) session).addExecutedTask(taskInstance); 129 } 130 131 /* (non-Javadoc) 132 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder#addTaskInstance(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance) 133 */ 134 @Override 135 public void addTaskInstance(ITaskInstanceList taskInstanceList, ITaskInstance taskInstance) { 136 if (taskInstanceList instanceof TaskInstance) { 137 ((TaskInstance) taskInstanceList).addChild(taskInstance); 138 } 139 else if (taskInstanceList instanceof UserSession) { 140 ((UserSession) taskInstanceList).addExecutedTask(taskInstance); 141 } 142 else { 143 throw new IllegalArgumentException 144 ("illegal type of task instance list provided: " + taskInstanceList.getClass()); 145 } 146 } 147 148 /* (non-Javadoc) 149 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder#addTaskInstance(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList, int, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance) 150 */ 151 @Override 152 public void addTaskInstance(ITaskInstanceList taskInstanceList, 153 int index, 154 ITaskInstance taskInstance) 155 { 156 if (taskInstanceList instanceof TaskInstance) { 157 ((TaskInstance) taskInstanceList).addChild(index, taskInstance); 158 } 159 else if (taskInstanceList instanceof UserSession) { 160 ((UserSession) taskInstanceList).addExecutedTask(index, taskInstance); 161 } 162 else { 163 throw new IllegalArgumentException 164 ("illegal type of task instance list provided: " + taskInstanceList.getClass()); 165 } 166 } 167 168 /* (non-Javadoc) 169 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder#setTaskInstance(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList, int, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance) 170 */ 171 @Override 172 public void setTaskInstance(ITaskInstanceList taskInstanceList, 173 int index, 174 ITaskInstance taskInstance) 175 { 176 if (taskInstanceList instanceof TaskInstance) { 177 ((TaskInstance) taskInstanceList).removeChild(index); 178 ((TaskInstance) taskInstanceList).addChild(index, taskInstance); 179 } 180 else if (taskInstanceList instanceof UserSession) { 181 ((UserSession) taskInstanceList).removeExecutedTask(index); 182 ((UserSession) taskInstanceList).addExecutedTask(index, taskInstance); 183 } 184 else { 185 throw new IllegalArgumentException 186 ("illegal type of task instance list provided: " + taskInstanceList.getClass()); 187 } 188 } 189 190 /* (non-Javadoc) 191 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder#setTask(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance, de.ugoe.cs.autoquest.tasktrees.treeifc.ITask) 192 */ 193 @Override 194 public void setTask(ITaskInstance taskInstance, ITask task) { 195 if (!(taskInstance instanceof TaskInstance)) { 196 throw new IllegalArgumentException 197 ("illegal type of task instance provided: " + taskInstance.getClass()); 198 } 199 200 ((TaskInstance) taskInstance).setTask(task); 201 } 33 202 34 203 /* … … 38 207 */ 39 208 @Override 40 public void addChild(ISequence parent, ITask TreeNodechild) {209 public void addChild(ISequence parent, ITask child) { 41 210 if (!(parent instanceof Sequence)) { 42 211 throw new IllegalArgumentException 43 ("illegal type of task tree node provided: " + parent.getClass());44 } 45 46 addChildInternal( parent, -1, child);212 ("illegal type of sequence provided: " + parent.getClass()); 213 } 214 215 addChildInternal((Sequence) parent, -1, child); 47 216 } 48 217 … … 53 222 */ 54 223 @Override 55 public void addChild(ISequence parent, int index, ITask TreeNodechild) {224 public void addChild(ISequence parent, int index, ITask child) { 56 225 if (!(parent instanceof Sequence)) { 57 226 throw new IllegalArgumentException 58 ("illegal type of task tree node provided: " + parent.getClass());59 } 60 61 addChildInternal( parent, index, child);227 ("illegal type of sequence provided: " + parent.getClass()); 228 } 229 230 addChildInternal((Sequence) parent, index, child); 62 231 } 63 232 … … 66 235 */ 67 236 @Override 68 public void setChild(ISequence parent, int index, ITask TreeNodechild) {237 public void setChild(ISequence parent, int index, ITask child) { 69 238 if (!(parent instanceof Sequence)) { 70 239 throw new IllegalArgumentException 71 ("illegal type of task tree node provided: " + parent.getClass());72 } 73 74 (( TaskTreeNode) parent).removeChild(index);75 addChildInternal( parent, index, child);240 ("illegal type of sequence provided: " + parent.getClass()); 241 } 242 243 ((Sequence) parent).removeChild(index); 244 addChildInternal((Sequence) parent, index, child); 76 245 } 77 246 … … 82 251 */ 83 252 @Override 84 public void addChild(ISelection parent, ITask TreeNodechild) {253 public void addChild(ISelection parent, ITask child) { 85 254 if (!(parent instanceof Selection)) { 86 255 throw new IllegalArgumentException 87 ("illegal type of task tree nodeprovided: " + parent.getClass());88 } 89 90 addChildInternal( parent, -1, child);256 ("illegal type of selection provided: " + parent.getClass()); 257 } 258 259 addChildInternal((Selection) parent, -1, child); 91 260 } 92 261 … … 97 266 */ 98 267 @Override 99 public void set Child(IIteration iteration, ITaskTreeNodenewChild) {268 public void setMarkedTask(IIteration iteration, ITask newChild) { 100 269 if (!(iteration instanceof Iteration)) { 101 270 throw new IllegalArgumentException … … 103 272 } 104 273 105 if (!(newChild instanceof Task TreeNode)) {106 throw new IllegalArgumentException 107 ("illegal type of task tree nodeprovided: " + newChild.getClass());108 } 109 110 ((Iteration) iteration).set Child(newChild);274 if (!(newChild instanceof Task)) { 275 throw new IllegalArgumentException 276 ("illegal type of task provided: " + newChild.getClass()); 277 } 278 279 ((Iteration) iteration).setMarkedTask(newChild); 111 280 } 112 281 … … 115 284 */ 116 285 @Override 117 public void set Child(IOptional optional, ITaskTreeNodenewChild) {286 public void setMarkedTask(IOptional optional, ITask newChild) { 118 287 if (!(optional instanceof Optional)) { 119 288 throw new IllegalArgumentException … … 121 290 } 122 291 123 if (!(newChild instanceof Task TreeNode)) {124 throw new IllegalArgumentException 125 ("illegal type of task tree nodeprovided: " + newChild.getClass());126 } 127 128 ((Optional) optional).set Child(newChild);292 if (!(newChild instanceof Task)) { 293 throw new IllegalArgumentException 294 ("illegal type of task provided: " + newChild.getClass()); 295 } 296 297 ((Optional) optional).setMarkedTask(newChild); 129 298 } 130 299 … … 136 305 @Override 137 306 public void removeChild(ISequence parent, int index) { 138 if (!(parent instanceof TaskTreeNode)) {139 throw new IllegalArgumentException 140 ("illegal type of task tree node provided: " + parent.getClass());141 } 142 143 (( TaskTreeNode) parent).removeChild(index);307 if (!(parent instanceof Sequence)) { 308 throw new IllegalArgumentException 309 ("illegal type of sequence provided: " + parent.getClass()); 310 } 311 312 ((Sequence) parent).removeChild(index); 144 313 } 145 314 … … 150 319 */ 151 320 @Override 152 public void removeChild(ISelection parent, ITask TreeNodechild) {153 if (!(parent instanceof TaskTreeNode)) {154 throw new IllegalArgumentException 155 ("illegal type of task tree nodeprovided: " + parent.getClass());156 } 157 158 List<ITask TreeNode> children = parent.getChildren();321 public void removeChild(ISelection parent, ITask child) { 322 if (!(parent instanceof Selection)) { 323 throw new IllegalArgumentException 324 ("illegal type of selection provided: " + parent.getClass()); 325 } 326 327 List<ITask> children = parent.getChildren(); 159 328 160 329 for (int i = 0; i < children.size(); i++) { … … 162 331 ((children.get(i) != null) && (children.get(i).equals(child)))) 163 332 { 164 (( TaskTreeNode) parent).removeChild(i);333 ((Selection) parent).removeChild(i); 165 334 break; 166 335 } … … 169 338 170 339 /* (non-Javadoc) 340 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder#removeTaskInstance(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList, int) 341 */ 342 @Override 343 public void removeTaskInstance(ITaskInstanceList taskInstanceList, int index) { 344 if (taskInstanceList instanceof TaskInstance) { 345 ((TaskInstance) taskInstanceList).removeChild(index); 346 } 347 else if (taskInstanceList instanceof UserSession) { 348 ((UserSession) taskInstanceList).removeExecutedTask(index); 349 } 350 else { 351 throw new IllegalArgumentException 352 ("illegal type of task instance list provided: " + taskInstanceList.getClass()); 353 } 354 } 355 356 /* (non-Javadoc) 171 357 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder#replaceChild(de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode) 172 358 */ 173 359 @Override 174 public void replaceChild(ISelection parent, ITask TreeNode oldChild, ITaskTreeNodenewChild) {175 if (!(parent instanceof TaskTreeNode)) {176 throw new IllegalArgumentException 177 ("illegal type of task tree nodeprovided: " + parent.getClass());178 } 179 180 List<ITask TreeNode> children = parent.getChildren();360 public void replaceChild(ISelection parent, ITask oldChild, ITask newChild) { 361 if (!(parent instanceof Selection)) { 362 throw new IllegalArgumentException 363 ("illegal type of selection provided: " + parent.getClass()); 364 } 365 366 List<ITask> children = parent.getChildren(); 181 367 182 368 for (int i = 0; i < children.size(); i++) { … … 184 370 ((children.get(i) != null) && (children.get(i).equals(oldChild)))) 185 371 { 186 (( TaskTreeNode) parent).removeChild(i);187 (( TaskTreeNode) parent).addChild(i, newChild);372 ((Selection) parent).removeChild(i); 373 ((Selection) parent).addChild(i, newChild); 188 374 break; 189 375 } … … 197 383 */ 198 384 @Override 199 public void setDescription(ITask TreeNodeparent, String description) {200 if (!(parent instanceof Task TreeNode)) {201 throw new IllegalArgumentException 202 ("illegal type of task tree nodeprovided: " + parent.getClass());203 } 204 205 ((Task TreeNode) parent).setDescription(description);385 public void setDescription(ITask parent, String description) { 386 if (!(parent instanceof Task)) { 387 throw new IllegalArgumentException 388 ("illegal type of task provided: " + parent.getClass()); 389 } 390 391 ((Task) parent).setDescription(description); 206 392 } 207 393 … … 209 395 * 210 396 */ 211 private void addChildInternal( ITaskTreeNode parent, int index, ITaskTreeNodechild) {212 if (!(child instanceof Task TreeNode)) {213 throw new IllegalArgumentException 214 ("illegal type of task tree nodeprovided: " + child.getClass());397 private void addChildInternal(StructuringTemporalRelationship parent, int index, ITask child) { 398 if (!(child instanceof Task)) { 399 throw new IllegalArgumentException 400 ("illegal type of task provided: " + child.getClass()); 215 401 } 216 402 217 403 if (index > -1) { 218 ((TaskTreeNode) parent).addChild(index, child);404 parent.addChild(index, child); 219 405 } 220 406 else { 221 ((TaskTreeNode) parent).addChild(child);407 parent.addChild(child); 222 408 } 223 409 }
Note: See TracChangeset
for help on using the changeset viewer.