Changeset 1733 for branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskBuilder.java
- Timestamp:
- 09/05/14 19:33:12 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskBuilder.java
r1422 r1733 36 36 * <p> 37 37 * this is the default implementation of the interface {@link ITaskBuilder}. It 38 * does not do anything fancy except implementing the interface. In some situations, it performs 39 * a check if the model or instances to be created a valid. However, this can not be done 40 * in any situation of the creation process. 38 * does not do anything fancy except implementing the interface. In some 39 * situations, it performs a check if the model or instances to be created a 40 * valid. However, this can not be done in any situation of the creation 41 * process. 41 42 * </p> 42 43 * … … 45 46 public class TaskBuilder implements ITaskBuilder { 46 47 47 /* (non-Javadoc) 48 * @see ITaskBuilder#addChild(ISequenceInstance, ITaskInstance) 49 */ 50 @Override 51 public void addChild(ISequenceInstance instance, ITaskInstance child) 52 throws IllegalArgumentException 53 { 54 if (!(instance instanceof SequenceInstance)) { 55 throw new IllegalArgumentException 56 ("illegal type of sequence instance provided: " + instance.getClass()); 57 } 58 59 if (!(child instanceof TaskInstance)) { 60 throw new IllegalArgumentException 61 ("illegal type of task instance provided: " + child.getClass()); 62 } 63 64 SequenceInstance seqInstance = (SequenceInstance) instance; 65 66 // check if new child instance matches the model, if this can be checked 67 IStructuringTemporalRelationship parentTask = 68 (IStructuringTemporalRelationship) instance.getTask(); 69 70 if (((parentTask.getChildren() != null) && (parentTask.getChildren().size() > 0)) && 71 ((parentTask.getChildren().size() <= seqInstance.size()) || 72 (!parentTask.getChildren().get(seqInstance.size()).equals(child.getTask())))) 73 { 74 throw new IllegalArgumentException 75 ("the task of the child instance to be added does not belong to the children " + 76 "of the task of the parent instance"); 77 } 78 79 seqInstance.addChild(child); 80 } 81 82 /* (non-Javadoc) 83 * @see ITaskBuilder#addChild(ISequenceInstance, int, ITaskInstance) 84 */ 85 public void addChild(ISequenceInstance instance, int index, ITaskInstance child) 86 throws IllegalArgumentException 87 { 88 if (!(instance instanceof SequenceInstance)) { 89 throw new IllegalArgumentException 90 ("illegal type of sequence instance provided: " + instance.getClass()); 91 } 92 93 if (!(child instanceof TaskInstance)) { 94 throw new IllegalArgumentException 95 ("illegal type of task instance provided: " + child.getClass()); 96 } 97 98 SequenceInstance seqInstance = (SequenceInstance) instance; 99 100 // check if new child instance matches the model, if this can be checked 101 IStructuringTemporalRelationship parentTask = 102 (IStructuringTemporalRelationship) instance.getTask(); 103 104 if (((parentTask.getChildren() != null) && (parentTask.getChildren().size() > 0)) && 105 ((parentTask.getChildren().size() <= index) || 106 (!parentTask.getChildren().get(index).equals(child.getTask())))) 107 { 108 throw new IllegalArgumentException 109 ("the task of the child instance to be added does not belong to the children " + 110 "of the task of the parent instance"); 111 } 112 113 seqInstance.addChild(index, child); 114 } 115 116 /* (non-Javadoc) 117 * @see ITaskBuilder#addChild(IIterationInstance, ITaskInstance) 118 */ 119 @Override 120 public void addChild(IIterationInstance instance, ITaskInstance child) 121 throws IllegalArgumentException 122 { 123 if (!(instance instanceof IterationInstance)) { 124 throw new IllegalArgumentException 125 ("illegal type of iteration instance provided: " + instance.getClass()); 126 } 127 128 if (!(child instanceof TaskInstance)) { 129 throw new IllegalArgumentException 130 ("illegal type of task instance provided: " + child.getClass()); 131 } 132 133 // check if new child instance matches the model, if this can be checked 134 IMarkingTemporalRelationship parentTask = 135 (IMarkingTemporalRelationship) instance.getTask(); 136 137 boolean foundChildTask = parentTask.getMarkedTask() != null ? 138 parentTask.getMarkedTask().equals(child.getTask()) : true; 139 140 if (!foundChildTask) { 141 throw new IllegalArgumentException 142 ("the task of the child instance does not match the model of the task of the " + 143 "iteration instance: " + parentTask.getMarkedTask() + " <> " + child.getTask()); 144 } 145 146 ((IterationInstance) instance).addChild(child); 147 } 148 149 /* (non-Javadoc) 150 * @see ITaskBuilder#addChild(IIterationInstance, int, ITaskInstance) 151 */ 152 public void addChild(IIterationInstance instance, int index, ITaskInstance child) 153 throws IllegalArgumentException 154 { 155 if (!(instance instanceof IterationInstance)) { 156 throw new IllegalArgumentException 157 ("illegal type of iteration instance provided: " + instance.getClass()); 158 } 159 160 if (!(child instanceof TaskInstance)) { 161 throw new IllegalArgumentException 162 ("illegal type of task instance provided: " + child.getClass()); 163 } 164 165 // check if new child instance matches the model, if this can be checked 166 IMarkingTemporalRelationship parentTask = 167 (IMarkingTemporalRelationship) instance.getTask(); 168 169 boolean foundChildTask = parentTask.getMarkedTask() != null ? 170 parentTask.getMarkedTask().equals(child.getTask()) : true; 171 172 if (!foundChildTask) { 173 throw new IllegalArgumentException 174 ("the task of the child instance does not match the model of the task of the " + 175 "iteration instance: " + parentTask.getMarkedTask() + " <> " + child.getTask()); 176 } 177 178 ((IterationInstance) instance).addChild(index, child); 179 } 180 181 /* (non-Javadoc) 182 * @see ITaskBuilder#setChild(ISelectionInstance, ITaskInstance) 183 */ 184 @Override 185 public void setChild(ISelectionInstance instance, ITaskInstance child) 186 throws IllegalArgumentException 187 { 188 if (!(instance instanceof SelectionInstance)) { 189 throw new IllegalArgumentException 190 ("illegal type of selection instance provided: " + instance.getClass()); 191 } 192 193 if (!(child instanceof TaskInstance)) { 194 throw new IllegalArgumentException("illegal type of task instance provided: " + 195 (child == null ? null : child.getClass())); 196 } 197 198 // check if new child instance matches the model, if this can be checked 199 IStructuringTemporalRelationship parentTask = 200 (IStructuringTemporalRelationship) instance.getTask(); 201 202 boolean foundChildTask = false; 203 for (ITask parentTaskChild : parentTask.getChildren()) { 204 if (parentTaskChild.equals(child.getTask())) { 205 foundChildTask = true; 206 break; 207 } 208 } 209 210 if (!foundChildTask) { 211 throw new IllegalArgumentException 212 ("the task of the child instance to be added does not belong to the children " + 213 "of the selection task model of the parent instance"); 214 } 215 216 ((SelectionInstance) instance).setChild(child); 217 } 218 219 /* (non-Javadoc) 220 * @see ITaskBuilder#setChild(IOptionalInstance, ITaskInstance) 221 */ 222 @Override 223 public void setChild(IOptionalInstance instance, ITaskInstance child) 224 throws IllegalArgumentException 225 { 226 if (!(instance instanceof OptionalInstance)) { 227 throw new IllegalArgumentException 228 ("illegal type of optional instance provided: " + instance.getClass()); 229 } 230 231 if (!(child instanceof TaskInstance)) { 232 throw new IllegalArgumentException 233 ("illegal type of task instance provided: " + child.getClass()); 234 } 235 236 // check if new child instance matches the model, if this can be checked 237 IMarkingTemporalRelationship parentTask = 238 (IMarkingTemporalRelationship) instance.getTask(); 239 240 boolean foundChildTask = parentTask.getMarkedTask() != null ? 241 parentTask.getMarkedTask().equals(child.getTask()) : true; 242 243 if (!foundChildTask) { 244 throw new IllegalArgumentException 245 ("the task of the child instance does not match the model of the task of the " + 246 "optional instance: " + parentTask.getMarkedTask() + " <> " + child.getTask()); 247 } 248 249 ((OptionalInstance) instance).setChild(child); 250 } 251 252 /* (non-Javadoc) 253 * @see ITaskBuilder#addExecutedTask(IUserSession, ITaskInstance) 254 */ 255 @Override 256 public void addExecutedTask(IUserSession session, ITaskInstance taskInstance) { 257 if (!(session instanceof UserSession)) { 258 throw new IllegalArgumentException 259 ("illegal type of session provided: " + session.getClass()); 260 } 261 262 if (!(taskInstance instanceof TaskInstance)) { 263 throw new IllegalArgumentException 264 ("illegal type of task instance provided: " + taskInstance.getClass()); 265 } 266 267 ((UserSession) session).addExecutedTask(taskInstance); 268 } 269 270 /* (non-Javadoc) 271 * @see ITaskBuilder#addExecutedTask(IUserSession, int, ITaskInstance) 272 */ 273 public void addExecutedTask(IUserSession session, int index, ITaskInstance taskInstance) { 274 if (!(session instanceof UserSession)) { 275 throw new IllegalArgumentException 276 ("illegal type of session provided: " + session.getClass()); 277 } 278 279 if (!(taskInstance instanceof TaskInstance)) { 280 throw new IllegalArgumentException 281 ("illegal type of task instance provided: " + taskInstance.getClass()); 282 } 283 284 ((UserSession) session).addExecutedTask(index, taskInstance); 285 } 286 287 /* (non-Javadoc) 288 * @see ITaskBuilder#addTaskInstance(ITaskInstanceList, ITaskInstance) 289 */ 290 @Override 291 public void addTaskInstance(ITaskInstanceList taskInstanceList, ITaskInstance taskInstance) { 292 if (taskInstanceList instanceof SequenceInstance) { 293 addChild((SequenceInstance) taskInstanceList, taskInstance); 294 } 295 else if (taskInstanceList instanceof IterationInstance) { 296 addChild((IterationInstance) taskInstanceList, taskInstance); 297 } 298 else if (taskInstanceList instanceof UserSession) { 299 addExecutedTask((UserSession) taskInstanceList, taskInstance); 300 } 301 else { 302 throw new IllegalArgumentException 303 ("illegal type of task instance list provided: " + taskInstanceList.getClass()); 304 } 305 } 306 307 /* (non-Javadoc) 308 * @see ITaskBuilder#addTaskInstance(ITaskInstanceList, int, ITaskInstance) 309 */ 310 @Override 311 public void addTaskInstance(ITaskInstanceList taskInstanceList, 312 int index, 313 ITaskInstance taskInstance) 314 { 315 if (taskInstanceList instanceof SequenceInstance) { 316 addChild((SequenceInstance) taskInstanceList, index, taskInstance); 317 } 318 else if (taskInstanceList instanceof IterationInstance) { 319 addChild((IterationInstance) taskInstanceList, index, taskInstance); 320 } 321 else if (taskInstanceList instanceof UserSession) { 322 addExecutedTask((UserSession) taskInstanceList, index, taskInstance); 323 } 324 else { 325 throw new IllegalArgumentException 326 ("illegal type of task instance list provided: " + taskInstanceList.getClass()); 327 } 328 } 329 330 /* (non-Javadoc) 331 * @see ITaskBuilder#setTaskInstance(ITaskInstanceList, int, ITaskInstance) 332 */ 333 @Override 334 public void setTaskInstance(ITaskInstanceList taskInstanceList, 335 int index, 336 ITaskInstance taskInstance) 337 { 338 removeTaskInstance(taskInstanceList, index); 339 addTaskInstance(taskInstanceList, index, taskInstance); 340 } 341 342 /* (non-Javadoc) 343 * @see ITaskBuilder#setTask(ITaskInstance, ITask) 344 */ 345 @Override 346 public void setTask(ITaskInstance taskInstance, ITask task) { 347 if (!(taskInstance instanceof TaskInstance)) { 348 throw new IllegalArgumentException 349 ("illegal type of task instance provided: " + taskInstance.getClass()); 350 } 351 if (!(task instanceof Task)) { 352 throw new IllegalArgumentException("illegal type of task provided: " + task.getClass()); 353 } 354 355 if (((TaskInstance) taskInstance).getTask() instanceof Task) { 356 ((Task) ((TaskInstance) taskInstance).getTask()).removeInstance(taskInstance); 357 } 358 ((TaskInstance) taskInstance).setTask(task); 359 360 ((Task) task).addInstance(taskInstance); 361 } 362 363 /* (non-Javadoc) 364 * @see ITaskBuilder#addChild(ISequence, ITask) 365 */ 366 @Override 367 public void addChild(ISequence parent, ITask child) { 368 if (!(parent instanceof Sequence)) { 369 throw new IllegalArgumentException 370 ("illegal type of sequence provided: " + parent.getClass()); 371 } 372 373 addChildInternal((Sequence) parent, -1, child); 374 } 375 376 /* (non-Javadoc) 377 * @see ITaskBuilder#addChild(ISequence, int, ITask) 378 */ 379 @Override 380 public void addChild(ISequence parent, int index, ITask child) { 381 if (!(parent instanceof Sequence)) { 382 throw new IllegalArgumentException 383 ("illegal type of sequence provided: " + parent.getClass()); 384 } 385 386 addChildInternal((Sequence) parent, index, child); 387 } 388 389 /* (non-Javadoc) 390 * @see ITaskBuilder#setChild(ISequence, int, ITask) 391 */ 392 @Override 393 public void setChild(ISequence parent, int index, ITask child) { 394 if (!(parent instanceof Sequence)) { 395 throw new IllegalArgumentException 396 ("illegal type of sequence provided: " + parent.getClass()); 397 } 398 399 ((Sequence) parent).removeChild(index); 400 addChildInternal((Sequence) parent, index, child); 401 } 402 403 /* (non-Javadoc) 404 * @see ITaskBuilder#addChild(ISelection, ITask) 405 */ 406 @Override 407 public void addChild(ISelection parent, ITask child) { 408 if (!(parent instanceof Selection)) { 409 throw new IllegalArgumentException 410 ("illegal type of selection provided: " + parent.getClass()); 411 } 412 413 addChildInternal((Selection) parent, -1, child); 414 } 415 416 /* (non-Javadoc) 417 * @see ITaskBuilder#setMarkedTask(IIteration, ITask) 418 */ 419 @Override 420 public void setMarkedTask(IIteration iteration, ITask newChild) { 421 if (!(iteration instanceof Iteration)) { 422 throw new IllegalArgumentException 423 ("illegal type of iteration provided: " + iteration.getClass()); 424 } 425 426 if (!(newChild instanceof Task)) { 427 throw new IllegalArgumentException 428 ("illegal type of task provided: " + newChild.getClass()); 429 } 430 431 ((Iteration) iteration).setMarkedTask(newChild); 432 } 433 434 /* (non-Javadoc) 435 * @see ITaskTreeBuilder#setChild(IOptional, ITaskTreeNode) 436 */ 437 @Override 438 public void setMarkedTask(IOptional optional, ITask newChild) { 439 if (!(optional instanceof Optional)) { 440 throw new IllegalArgumentException 441 ("illegal type of optional provided: " + optional.getClass()); 442 } 443 444 if (!(newChild instanceof Task)) { 445 throw new IllegalArgumentException 446 ("illegal type of task provided: " + newChild.getClass()); 447 } 448 449 ((Optional) optional).setMarkedTask(newChild); 450 } 451 452 /* (non-Javadoc) 453 * @see ITaskBuilder#removeChild(ISequence, int) 454 */ 455 @Override 456 public void removeChild(ISequence parent, int index) { 457 if (!(parent instanceof Sequence)) { 458 throw new IllegalArgumentException 459 ("illegal type of sequence provided: " + parent.getClass()); 460 } 461 462 ((Sequence) parent).removeChild(index); 463 } 464 465 /* (non-Javadoc) 466 * @see ITaskBuilder#removeChild(ISelection, ITask) 467 */ 468 @Override 469 public void removeChild(ISelection parent, ITask child) { 470 if (!(parent instanceof Selection)) { 471 throw new IllegalArgumentException 472 ("illegal type of selection provided: " + parent.getClass()); 473 } 474 475 List<ITask> children = parent.getChildren(); 476 477 for (int i = 0; i < children.size(); i++) { 478 if ((children.get(i) == child) || 479 ((children.get(i) != null) && (children.get(i).equals(child)))) 480 { 481 ((Selection) parent).removeChild(i); 482 break; 483 } 484 } 485 } 486 487 /* (non-Javadoc) 488 * @see ITaskBuilder#removeTaskInstance(ITaskInstanceList, int) 489 */ 490 @Override 491 public void removeTaskInstance(ITaskInstanceList taskInstanceList, int index) { 492 if (taskInstanceList instanceof SequenceInstance) { 493 ((SequenceInstance) taskInstanceList).removeChild(index); 494 } 495 else if (taskInstanceList instanceof IterationInstance) { 496 ((IterationInstance) taskInstanceList).removeChild(index); 497 } 498 else if (taskInstanceList instanceof UserSession) { 499 ((UserSession) taskInstanceList).removeExecutedTask(index); 500 } 501 else { 502 throw new IllegalArgumentException 503 ("illegal type of task instance list provided: " + taskInstanceList.getClass()); 504 } 505 } 506 507 /* (non-Javadoc) 508 * @see ITaskTreeBuilder#replaceChild(ISelection, ITaskTreeNode, ITaskTreeNode) 509 */ 510 @Override 511 public void replaceChild(ISelection parent, ITask oldChild, ITask newChild) { 512 if (!(parent instanceof Selection)) { 513 throw new IllegalArgumentException 514 ("illegal type of selection provided: " + parent.getClass()); 515 } 516 517 List<ITask> children = parent.getChildren(); 518 519 for (int i = 0; i < children.size(); i++) { 520 if ((children.get(i) == oldChild) || 521 ((children.get(i) != null) && (children.get(i).equals(oldChild)))) 522 { 523 ((Selection) parent).removeChild(i); 524 ((Selection) parent).addChild(i, newChild); 525 break; 526 } 527 } 528 } 529 530 /** 531 * <p> 532 * internal convenience method for adding children to a structuring temporal relationship 533 * including a check for the child type. 534 * </p> 535 */ 536 private void addChildInternal(StructuringTemporalRelationship parent, int index, ITask child) { 537 if (!(child instanceof Task)) { 538 throw new IllegalArgumentException 539 ("illegal type of task provided: " + child.getClass()); 540 } 541 542 if (index > -1) { 543 parent.addChild(index, child); 544 } 545 else { 546 parent.addChild(child); 547 } 548 } 48 /* 49 * (non-Javadoc) 50 * 51 * @see ITaskBuilder#addChild(IIterationInstance, int, ITaskInstance) 52 */ 53 public void addChild(IIterationInstance instance, int index, 54 ITaskInstance child) throws IllegalArgumentException { 55 if (!(instance instanceof IterationInstance)) { 56 throw new IllegalArgumentException( 57 "illegal type of iteration instance provided: " 58 + instance.getClass()); 59 } 60 61 if (!(child instanceof TaskInstance)) { 62 throw new IllegalArgumentException( 63 "illegal type of task instance provided: " 64 + child.getClass()); 65 } 66 67 // check if new child instance matches the model, if this can be checked 68 final IMarkingTemporalRelationship parentTask = (IMarkingTemporalRelationship) instance 69 .getTask(); 70 71 final boolean foundChildTask = parentTask.getMarkedTask() != null ? parentTask 72 .getMarkedTask().equals(child.getTask()) : true; 73 74 if (!foundChildTask) { 75 throw new IllegalArgumentException( 76 "the task of the child instance does not match the model of the task of the " 77 + "iteration instance: " 78 + parentTask.getMarkedTask() + " <> " 79 + child.getTask()); 80 } 81 82 ((IterationInstance) instance).addChild(index, child); 83 } 84 85 /* 86 * (non-Javadoc) 87 * 88 * @see ITaskBuilder#addChild(IIterationInstance, ITaskInstance) 89 */ 90 @Override 91 public void addChild(IIterationInstance instance, ITaskInstance child) 92 throws IllegalArgumentException { 93 if (!(instance instanceof IterationInstance)) { 94 throw new IllegalArgumentException( 95 "illegal type of iteration instance provided: " 96 + instance.getClass()); 97 } 98 99 if (!(child instanceof TaskInstance)) { 100 throw new IllegalArgumentException( 101 "illegal type of task instance provided: " 102 + child.getClass()); 103 } 104 105 // check if new child instance matches the model, if this can be checked 106 final IMarkingTemporalRelationship parentTask = (IMarkingTemporalRelationship) instance 107 .getTask(); 108 109 final boolean foundChildTask = parentTask.getMarkedTask() != null ? parentTask 110 .getMarkedTask().equals(child.getTask()) : true; 111 112 if (!foundChildTask) { 113 throw new IllegalArgumentException( 114 "the task of the child instance does not match the model of the task of the " 115 + "iteration instance: " 116 + parentTask.getMarkedTask() + " <> " 117 + child.getTask()); 118 } 119 120 ((IterationInstance) instance).addChild(child); 121 } 122 123 /* 124 * (non-Javadoc) 125 * 126 * @see ITaskBuilder#addChild(ISelection, ITask) 127 */ 128 @Override 129 public void addChild(ISelection parent, ITask child) { 130 if (!(parent instanceof Selection)) { 131 throw new IllegalArgumentException( 132 "illegal type of selection provided: " + parent.getClass()); 133 } 134 135 addChildInternal((Selection) parent, -1, child); 136 } 137 138 /* 139 * (non-Javadoc) 140 * 141 * @see ITaskBuilder#addChild(ISequence, int, ITask) 142 */ 143 @Override 144 public void addChild(ISequence parent, int index, ITask child) { 145 if (!(parent instanceof Sequence)) { 146 throw new IllegalArgumentException( 147 "illegal type of sequence provided: " + parent.getClass()); 148 } 149 150 addChildInternal((Sequence) parent, index, child); 151 } 152 153 /* 154 * (non-Javadoc) 155 * 156 * @see ITaskBuilder#addChild(ISequence, ITask) 157 */ 158 @Override 159 public void addChild(ISequence parent, ITask child) { 160 if (!(parent instanceof Sequence)) { 161 throw new IllegalArgumentException( 162 "illegal type of sequence provided: " + parent.getClass()); 163 } 164 165 addChildInternal((Sequence) parent, -1, child); 166 } 167 168 /* 169 * (non-Javadoc) 170 * 171 * @see ITaskBuilder#addChild(ISequenceInstance, int, ITaskInstance) 172 */ 173 public void addChild(ISequenceInstance instance, int index, 174 ITaskInstance child) throws IllegalArgumentException { 175 if (!(instance instanceof SequenceInstance)) { 176 throw new IllegalArgumentException( 177 "illegal type of sequence instance provided: " 178 + instance.getClass()); 179 } 180 181 if (!(child instanceof TaskInstance)) { 182 throw new IllegalArgumentException( 183 "illegal type of task instance provided: " 184 + child.getClass()); 185 } 186 187 final SequenceInstance seqInstance = (SequenceInstance) instance; 188 189 // check if new child instance matches the model, if this can be checked 190 final IStructuringTemporalRelationship parentTask = (IStructuringTemporalRelationship) instance 191 .getTask(); 192 193 if (((parentTask.getChildren() != null) && (parentTask.getChildren() 194 .size() > 0)) 195 && ((parentTask.getChildren().size() <= index) || (!parentTask 196 .getChildren().get(index).equals(child.getTask())))) { 197 throw new IllegalArgumentException( 198 "the task of the child instance to be added does not belong to the children " 199 + "of the task of the parent instance"); 200 } 201 202 seqInstance.addChild(index, child); 203 } 204 205 /* 206 * (non-Javadoc) 207 * 208 * @see ITaskBuilder#addChild(ISequenceInstance, ITaskInstance) 209 */ 210 @Override 211 public void addChild(ISequenceInstance instance, ITaskInstance child) 212 throws IllegalArgumentException { 213 if (!(instance instanceof SequenceInstance)) { 214 throw new IllegalArgumentException( 215 "illegal type of sequence instance provided: " 216 + instance.getClass()); 217 } 218 219 if (!(child instanceof TaskInstance)) { 220 throw new IllegalArgumentException( 221 "illegal type of task instance provided: " 222 + child.getClass()); 223 } 224 225 final SequenceInstance seqInstance = (SequenceInstance) instance; 226 227 // check if new child instance matches the model, if this can be checked 228 final IStructuringTemporalRelationship parentTask = (IStructuringTemporalRelationship) instance 229 .getTask(); 230 231 if (((parentTask.getChildren() != null) && (parentTask.getChildren() 232 .size() > 0)) 233 && ((parentTask.getChildren().size() <= seqInstance.size()) || (!parentTask 234 .getChildren().get(seqInstance.size()) 235 .equals(child.getTask())))) { 236 throw new IllegalArgumentException( 237 "the task of the child instance to be added does not belong to the children " 238 + "of the task of the parent instance"); 239 } 240 241 seqInstance.addChild(child); 242 } 243 244 /** 245 * <p> 246 * internal convenience method for adding children to a structuring temporal 247 * relationship including a check for the child type. 248 * </p> 249 */ 250 private void addChildInternal(StructuringTemporalRelationship parent, 251 int index, ITask child) { 252 if (!(child instanceof Task)) { 253 throw new IllegalArgumentException( 254 "illegal type of task provided: " + child.getClass()); 255 } 256 257 if (index > -1) { 258 parent.addChild(index, child); 259 } else { 260 parent.addChild(child); 261 } 262 } 263 264 /* 265 * (non-Javadoc) 266 * 267 * @see ITaskBuilder#addExecutedTask(IUserSession, int, ITaskInstance) 268 */ 269 public void addExecutedTask(IUserSession session, int index, 270 ITaskInstance taskInstance) { 271 if (!(session instanceof UserSession)) { 272 throw new IllegalArgumentException( 273 "illegal type of session provided: " + session.getClass()); 274 } 275 276 if (!(taskInstance instanceof TaskInstance)) { 277 throw new IllegalArgumentException( 278 "illegal type of task instance provided: " 279 + taskInstance.getClass()); 280 } 281 282 ((UserSession) session).addExecutedTask(index, taskInstance); 283 } 284 285 /* 286 * (non-Javadoc) 287 * 288 * @see ITaskBuilder#addExecutedTask(IUserSession, ITaskInstance) 289 */ 290 @Override 291 public void addExecutedTask(IUserSession session, ITaskInstance taskInstance) { 292 if (!(session instanceof UserSession)) { 293 throw new IllegalArgumentException( 294 "illegal type of session provided: " + session.getClass()); 295 } 296 297 if (!(taskInstance instanceof TaskInstance)) { 298 throw new IllegalArgumentException( 299 "illegal type of task instance provided: " 300 + taskInstance.getClass()); 301 } 302 303 ((UserSession) session).addExecutedTask(taskInstance); 304 } 305 306 /* 307 * (non-Javadoc) 308 * 309 * @see ITaskBuilder#addTaskInstance(ITaskInstanceList, int, ITaskInstance) 310 */ 311 @Override 312 public void addTaskInstance(ITaskInstanceList taskInstanceList, int index, 313 ITaskInstance taskInstance) { 314 if (taskInstanceList instanceof SequenceInstance) { 315 addChild((SequenceInstance) taskInstanceList, index, taskInstance); 316 } else if (taskInstanceList instanceof IterationInstance) { 317 addChild((IterationInstance) taskInstanceList, index, taskInstance); 318 } else if (taskInstanceList instanceof UserSession) { 319 addExecutedTask((UserSession) taskInstanceList, index, taskInstance); 320 } else { 321 throw new IllegalArgumentException( 322 "illegal type of task instance list provided: " 323 + taskInstanceList.getClass()); 324 } 325 } 326 327 /* 328 * (non-Javadoc) 329 * 330 * @see ITaskBuilder#addTaskInstance(ITaskInstanceList, ITaskInstance) 331 */ 332 @Override 333 public void addTaskInstance(ITaskInstanceList taskInstanceList, 334 ITaskInstance taskInstance) { 335 if (taskInstanceList instanceof SequenceInstance) { 336 addChild((SequenceInstance) taskInstanceList, taskInstance); 337 } else if (taskInstanceList instanceof IterationInstance) { 338 addChild((IterationInstance) taskInstanceList, taskInstance); 339 } else if (taskInstanceList instanceof UserSession) { 340 addExecutedTask((UserSession) taskInstanceList, taskInstance); 341 } else { 342 throw new IllegalArgumentException( 343 "illegal type of task instance list provided: " 344 + taskInstanceList.getClass()); 345 } 346 } 347 348 /* 349 * (non-Javadoc) 350 * 351 * @see ITaskBuilder#removeChild(ISelection, ITask) 352 */ 353 @Override 354 public void removeChild(ISelection parent, ITask child) { 355 if (!(parent instanceof Selection)) { 356 throw new IllegalArgumentException( 357 "illegal type of selection provided: " + parent.getClass()); 358 } 359 360 final List<ITask> children = parent.getChildren(); 361 362 for (int i = 0; i < children.size(); i++) { 363 if ((children.get(i) == child) 364 || ((children.get(i) != null) && (children.get(i) 365 .equals(child)))) { 366 ((Selection) parent).removeChild(i); 367 break; 368 } 369 } 370 } 371 372 /* 373 * (non-Javadoc) 374 * 375 * @see ITaskBuilder#removeChild(ISequence, int) 376 */ 377 @Override 378 public void removeChild(ISequence parent, int index) { 379 if (!(parent instanceof Sequence)) { 380 throw new IllegalArgumentException( 381 "illegal type of sequence provided: " + parent.getClass()); 382 } 383 384 ((Sequence) parent).removeChild(index); 385 } 386 387 /* 388 * (non-Javadoc) 389 * 390 * @see ITaskBuilder#removeTaskInstance(ITaskInstanceList, int) 391 */ 392 @Override 393 public void removeTaskInstance(ITaskInstanceList taskInstanceList, int index) { 394 if (taskInstanceList instanceof SequenceInstance) { 395 ((SequenceInstance) taskInstanceList).removeChild(index); 396 } else if (taskInstanceList instanceof IterationInstance) { 397 ((IterationInstance) taskInstanceList).removeChild(index); 398 } else if (taskInstanceList instanceof UserSession) { 399 ((UserSession) taskInstanceList).removeExecutedTask(index); 400 } else { 401 throw new IllegalArgumentException( 402 "illegal type of task instance list provided: " 403 + taskInstanceList.getClass()); 404 } 405 } 406 407 /* 408 * (non-Javadoc) 409 * 410 * @see ITaskTreeBuilder#replaceChild(ISelection, ITaskTreeNode, 411 * ITaskTreeNode) 412 */ 413 @Override 414 public void replaceChild(ISelection parent, ITask oldChild, ITask newChild) { 415 if (!(parent instanceof Selection)) { 416 throw new IllegalArgumentException( 417 "illegal type of selection provided: " + parent.getClass()); 418 } 419 420 final List<ITask> children = parent.getChildren(); 421 422 for (int i = 0; i < children.size(); i++) { 423 if ((children.get(i) == oldChild) 424 || ((children.get(i) != null) && (children.get(i) 425 .equals(oldChild)))) { 426 ((Selection) parent).removeChild(i); 427 ((Selection) parent).addChild(i, newChild); 428 break; 429 } 430 } 431 } 432 433 /* 434 * (non-Javadoc) 435 * 436 * @see ITaskBuilder#setChild(IOptionalInstance, ITaskInstance) 437 */ 438 @Override 439 public void setChild(IOptionalInstance instance, ITaskInstance child) 440 throws IllegalArgumentException { 441 if (!(instance instanceof OptionalInstance)) { 442 throw new IllegalArgumentException( 443 "illegal type of optional instance provided: " 444 + instance.getClass()); 445 } 446 447 if (!(child instanceof TaskInstance)) { 448 throw new IllegalArgumentException( 449 "illegal type of task instance provided: " 450 + child.getClass()); 451 } 452 453 // check if new child instance matches the model, if this can be checked 454 final IMarkingTemporalRelationship parentTask = (IMarkingTemporalRelationship) instance 455 .getTask(); 456 457 final boolean foundChildTask = parentTask.getMarkedTask() != null ? parentTask 458 .getMarkedTask().equals(child.getTask()) : true; 459 460 if (!foundChildTask) { 461 throw new IllegalArgumentException( 462 "the task of the child instance does not match the model of the task of the " 463 + "optional instance: " 464 + parentTask.getMarkedTask() + " <> " 465 + child.getTask()); 466 } 467 468 ((OptionalInstance) instance).setChild(child); 469 } 470 471 /* 472 * (non-Javadoc) 473 * 474 * @see ITaskBuilder#setChild(ISelectionInstance, ITaskInstance) 475 */ 476 @Override 477 public void setChild(ISelectionInstance instance, ITaskInstance child) 478 throws IllegalArgumentException { 479 if (!(instance instanceof SelectionInstance)) { 480 throw new IllegalArgumentException( 481 "illegal type of selection instance provided: " 482 + instance.getClass()); 483 } 484 485 if (!(child instanceof TaskInstance)) { 486 throw new IllegalArgumentException( 487 "illegal type of task instance provided: " 488 + (child == null ? null : child.getClass())); 489 } 490 491 // check if new child instance matches the model, if this can be checked 492 final IStructuringTemporalRelationship parentTask = (IStructuringTemporalRelationship) instance 493 .getTask(); 494 495 boolean foundChildTask = false; 496 for (final ITask parentTaskChild : parentTask.getChildren()) { 497 if (parentTaskChild.equals(child.getTask())) { 498 foundChildTask = true; 499 break; 500 } 501 } 502 503 if (!foundChildTask) { 504 throw new IllegalArgumentException( 505 "the task of the child instance to be added does not belong to the children " 506 + "of the selection task model of the parent instance"); 507 } 508 509 ((SelectionInstance) instance).setChild(child); 510 } 511 512 /* 513 * (non-Javadoc) 514 * 515 * @see ITaskBuilder#setChild(ISequence, int, ITask) 516 */ 517 @Override 518 public void setChild(ISequence parent, int index, ITask child) { 519 if (!(parent instanceof Sequence)) { 520 throw new IllegalArgumentException( 521 "illegal type of sequence provided: " + parent.getClass()); 522 } 523 524 ((Sequence) parent).removeChild(index); 525 addChildInternal((Sequence) parent, index, child); 526 } 527 528 /* 529 * (non-Javadoc) 530 * 531 * @see ITaskBuilder#setMarkedTask(IIteration, ITask) 532 */ 533 @Override 534 public void setMarkedTask(IIteration iteration, ITask newChild) { 535 if (!(iteration instanceof Iteration)) { 536 throw new IllegalArgumentException( 537 "illegal type of iteration provided: " 538 + iteration.getClass()); 539 } 540 541 if (!(newChild instanceof Task)) { 542 throw new IllegalArgumentException( 543 "illegal type of task provided: " + newChild.getClass()); 544 } 545 546 ((Iteration) iteration).setMarkedTask(newChild); 547 } 548 549 /* 550 * (non-Javadoc) 551 * 552 * @see ITaskTreeBuilder#setChild(IOptional, ITaskTreeNode) 553 */ 554 @Override 555 public void setMarkedTask(IOptional optional, ITask newChild) { 556 if (!(optional instanceof Optional)) { 557 throw new IllegalArgumentException( 558 "illegal type of optional provided: " + optional.getClass()); 559 } 560 561 if (!(newChild instanceof Task)) { 562 throw new IllegalArgumentException( 563 "illegal type of task provided: " + newChild.getClass()); 564 } 565 566 ((Optional) optional).setMarkedTask(newChild); 567 } 568 569 /* 570 * (non-Javadoc) 571 * 572 * @see ITaskBuilder#setTask(ITaskInstance, ITask) 573 */ 574 @Override 575 public void setTask(ITaskInstance taskInstance, ITask task) { 576 if (!(taskInstance instanceof TaskInstance)) { 577 throw new IllegalArgumentException( 578 "illegal type of task instance provided: " 579 + taskInstance.getClass()); 580 } 581 if (!(task instanceof Task)) { 582 throw new IllegalArgumentException( 583 "illegal type of task provided: " + task.getClass()); 584 } 585 586 if (((TaskInstance) taskInstance).getTask() instanceof Task) { 587 ((Task) ((TaskInstance) taskInstance).getTask()) 588 .removeInstance(taskInstance); 589 } 590 ((TaskInstance) taskInstance).setTask(task); 591 592 ((Task) task).addInstance(taskInstance); 593 } 594 595 /* 596 * (non-Javadoc) 597 * 598 * @see ITaskBuilder#setTaskInstance(ITaskInstanceList, int, ITaskInstance) 599 */ 600 @Override 601 public void setTaskInstance(ITaskInstanceList taskInstanceList, int index, 602 ITaskInstance taskInstance) { 603 removeTaskInstance(taskInstanceList, index); 604 addTaskInstance(taskInstanceList, index, taskInstance); 605 } 549 606 550 607 }
Note: See TracChangeset
for help on using the changeset viewer.