[1113] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
| 2 | // |
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
| 4 | // you may not use this file except in compliance with the License. |
---|
| 5 | // You may obtain a copy of the License at |
---|
| 6 | // |
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 8 | // |
---|
| 9 | // Unless required by applicable law or agreed to in writing, software |
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 12 | // See the License for the specific language governing permissions and |
---|
| 13 | // limitations under the License. |
---|
| 14 | |
---|
[922] | 15 | package de.ugoe.cs.autoquest.tasktrees.treeimpl; |
---|
[439] | 16 | |
---|
[1126] | 17 | import java.util.List; |
---|
| 18 | |
---|
[922] | 19 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; |
---|
[1294] | 20 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; |
---|
[1126] | 21 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; |
---|
[1294] | 22 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance; |
---|
[922] | 23 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; |
---|
[1294] | 24 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; |
---|
[922] | 25 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; |
---|
[1294] | 26 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance; |
---|
[1146] | 27 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; |
---|
| 28 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; |
---|
| 29 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; |
---|
| 30 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; |
---|
| 31 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; |
---|
[439] | 32 | |
---|
| 33 | /** |
---|
[1216] | 34 | * <p> |
---|
| 35 | * this is the default implementation of the interface {@link ITaskBuilder}. It |
---|
| 36 | * does not do anything fancy except implementing the interface. In some situations, it performs |
---|
| 37 | * a check if the model or instances to be created a valid. However, this can not be done |
---|
| 38 | * in any situation of the creation process. |
---|
| 39 | * </p> |
---|
[439] | 40 | * |
---|
[1216] | 41 | * @author Patrick Harms |
---|
[439] | 42 | */ |
---|
[1146] | 43 | public class TaskBuilder implements ITaskBuilder { |
---|
[439] | 44 | |
---|
[1146] | 45 | /* (non-Javadoc) |
---|
[1294] | 46 | * @see ITaskBuilder#addChild(ISequenceInstance, ITaskInstance) |
---|
[1146] | 47 | */ |
---|
| 48 | @Override |
---|
[1294] | 49 | public void addChild(ISequenceInstance instance, ITaskInstance child) |
---|
| 50 | throws IllegalArgumentException |
---|
[1146] | 51 | { |
---|
[1294] | 52 | if (!(instance instanceof SequenceInstance)) { |
---|
[1146] | 53 | throw new IllegalArgumentException |
---|
[1294] | 54 | ("illegal type of sequence instance provided: " + instance.getClass()); |
---|
[1146] | 55 | } |
---|
| 56 | |
---|
| 57 | if (!(child instanceof TaskInstance)) { |
---|
| 58 | throw new IllegalArgumentException |
---|
[1294] | 59 | ("illegal type of task instance provided: " + child.getClass()); |
---|
[1146] | 60 | } |
---|
| 61 | |
---|
[1294] | 62 | /*IStructuringTemporalRelationship parentTask = |
---|
| 63 | (IStructuringTemporalRelationship) parent.getTask(); |
---|
[1146] | 64 | |
---|
[1294] | 65 | for (ITask parentTaskChild : parentTask.getChildren()) { |
---|
| 66 | if (parentTaskChild.equals(child.getTask())) { |
---|
| 67 | foundChildTask = true; |
---|
| 68 | break; |
---|
| 69 | } |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | if (!foundChildTask) { |
---|
[1146] | 73 | throw new IllegalArgumentException |
---|
[1294] | 74 | ("the task of the child instance to be added does not belong to the children " + |
---|
| 75 | "of the task of the parent instance"); |
---|
| 76 | }*/ |
---|
| 77 | |
---|
| 78 | ((SequenceInstance) instance).addChild(child); |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | /* (non-Javadoc) |
---|
| 82 | * @see ITaskBuilder#addChild(ISequenceInstance, int, ITaskInstance) |
---|
| 83 | */ |
---|
| 84 | public void addChild(ISequenceInstance instance, int index, ITaskInstance child) |
---|
| 85 | throws IllegalArgumentException |
---|
| 86 | { |
---|
| 87 | if (!(instance instanceof SequenceInstance)) { |
---|
| 88 | throw new IllegalArgumentException |
---|
| 89 | ("illegal type of sequence instance provided: " + instance.getClass()); |
---|
[1146] | 90 | } |
---|
[1294] | 91 | |
---|
| 92 | if (!(child instanceof TaskInstance)) { |
---|
| 93 | throw new IllegalArgumentException |
---|
| 94 | ("illegal type of task instance provided: " + child.getClass()); |
---|
[1146] | 95 | } |
---|
[1294] | 96 | |
---|
| 97 | /*IStructuringTemporalRelationship parentTask = |
---|
| 98 | (IStructuringTemporalRelationship) parent.getTask(); |
---|
| 99 | |
---|
| 100 | for (ITask parentTaskChild : parentTask.getChildren()) { |
---|
| 101 | if (parentTaskChild.equals(child.getTask())) { |
---|
| 102 | foundChildTask = true; |
---|
| 103 | break; |
---|
[1146] | 104 | } |
---|
| 105 | } |
---|
[1294] | 106 | |
---|
| 107 | if (!foundChildTask) { |
---|
| 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 | ((SequenceInstance) instance).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()); |
---|
[1146] | 126 | } |
---|
[1294] | 127 | |
---|
| 128 | if (!(child instanceof TaskInstance)) { |
---|
| 129 | throw new IllegalArgumentException |
---|
| 130 | ("illegal type of task instance provided: " + child.getClass()); |
---|
| 131 | } |
---|
[1146] | 132 | |
---|
[1294] | 133 | /*IStructuringTemporalRelationship parentTask = |
---|
| 134 | (IStructuringTemporalRelationship) parent.getTask(); |
---|
[1146] | 135 | |
---|
[1294] | 136 | IMarkingTemporalRelationship parentTask = |
---|
| 137 | (IMarkingTemporalRelationship) parent.getTask(); |
---|
| 138 | |
---|
| 139 | foundChildTask = parentTask.getMarkedTask() != null ? |
---|
| 140 | parentTask.getMarkedTask().equals(child.getTask()) : false; |
---|
| 141 | |
---|
| 142 | if (!foundChildTask) { |
---|
| 143 | throw new IllegalArgumentException |
---|
| 144 | ("the task of the child instance to be added does not belong to the children " + |
---|
| 145 | "of the task of the parent instance"); |
---|
| 146 | }*/ |
---|
| 147 | |
---|
| 148 | ((IterationInstance) instance).addChild(child); |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | /* (non-Javadoc) |
---|
| 152 | * @see ITaskBuilder#addChild(IIterationInstance, int, ITaskInstance) |
---|
| 153 | */ |
---|
| 154 | public void addChild(IIterationInstance instance, int index, ITaskInstance child) |
---|
| 155 | throws IllegalArgumentException |
---|
| 156 | { |
---|
| 157 | if (!(instance instanceof IterationInstance)) { |
---|
| 158 | throw new IllegalArgumentException |
---|
| 159 | ("illegal type of iteration instance provided: " + instance.getClass()); |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | if (!(child instanceof TaskInstance)) { |
---|
| 163 | throw new IllegalArgumentException |
---|
| 164 | ("illegal type of task instance provided: " + child.getClass()); |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | /*IStructuringTemporalRelationship parentTask = |
---|
| 168 | (IStructuringTemporalRelationship) parent.getTask(); |
---|
| 169 | |
---|
| 170 | IMarkingTemporalRelationship parentTask = |
---|
| 171 | (IMarkingTemporalRelationship) parent.getTask(); |
---|
| 172 | |
---|
| 173 | foundChildTask = parentTask.getMarkedTask() != null ? |
---|
| 174 | parentTask.getMarkedTask().equals(child.getTask()) : false; |
---|
| 175 | |
---|
| 176 | if (!foundChildTask) { |
---|
| 177 | throw new IllegalArgumentException |
---|
| 178 | ("the task of the child instance to be added does not belong to the children " + |
---|
| 179 | "of the task of the parent instance"); |
---|
| 180 | }*/ |
---|
| 181 | |
---|
| 182 | ((IterationInstance) instance).addChild(index, child); |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | /* (non-Javadoc) |
---|
| 186 | * @see ITaskBuilder#setChild(ISelectionInstance, ITaskInstance) |
---|
| 187 | */ |
---|
| 188 | @Override |
---|
| 189 | public void setChild(ISelectionInstance instance, ITaskInstance child) |
---|
| 190 | throws IllegalArgumentException |
---|
| 191 | { |
---|
| 192 | if (!(instance instanceof SelectionInstance)) { |
---|
| 193 | throw new IllegalArgumentException |
---|
[1362] | 194 | ("illegal type of selection instance provided: " + instance.getClass()); |
---|
[1294] | 195 | } |
---|
| 196 | |
---|
| 197 | if (!(child instanceof TaskInstance)) { |
---|
[1362] | 198 | throw new IllegalArgumentException("illegal type of task instance provided: " + |
---|
| 199 | (child == null ? null : child.getClass())); |
---|
[1294] | 200 | } |
---|
| 201 | |
---|
| 202 | /*IStructuringTemporalRelationship parentTask = |
---|
| 203 | (IStructuringTemporalRelationship) parent.getTask(); |
---|
| 204 | |
---|
| 205 | for (ITask parentTaskChild : parentTask.getChildren()) { |
---|
| 206 | if (parentTaskChild.equals(child.getTask())) { |
---|
| 207 | foundChildTask = true; |
---|
| 208 | break; |
---|
[1146] | 209 | } |
---|
| 210 | } |
---|
| 211 | |
---|
[1294] | 212 | if (!foundChildTask) { |
---|
| 213 | throw new IllegalArgumentException |
---|
| 214 | ("the task of the child instance to be added does not belong to the children " + |
---|
| 215 | "of the task of the parent instance"); |
---|
| 216 | }*/ |
---|
| 217 | |
---|
| 218 | ((SelectionInstance) instance).setChild(child); |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | /* (non-Javadoc) |
---|
| 222 | * @see ITaskBuilder#setChild(IOptionalInstance, ITaskInstance) |
---|
| 223 | */ |
---|
| 224 | @Override |
---|
| 225 | public void setChild(IOptionalInstance instance, ITaskInstance child) |
---|
| 226 | throws IllegalArgumentException |
---|
| 227 | { |
---|
| 228 | if (!(instance instanceof OptionalInstance)) { |
---|
| 229 | throw new IllegalArgumentException |
---|
| 230 | ("illegal type of optional instance provided: " + instance.getClass()); |
---|
[1146] | 231 | } |
---|
[1294] | 232 | |
---|
| 233 | if (!(child instanceof TaskInstance)) { |
---|
| 234 | throw new IllegalArgumentException |
---|
| 235 | ("illegal type of task instance provided: " + child.getClass()); |
---|
| 236 | } |
---|
[1146] | 237 | |
---|
[1294] | 238 | /*IStructuringTemporalRelationship parentTask = |
---|
| 239 | (IStructuringTemporalRelationship) parent.getTask(); |
---|
| 240 | |
---|
| 241 | IMarkingTemporalRelationship parentTask = |
---|
| 242 | (IMarkingTemporalRelationship) parent.getTask(); |
---|
| 243 | |
---|
| 244 | foundChildTask = parentTask.getMarkedTask() != null ? |
---|
| 245 | parentTask.getMarkedTask().equals(child.getTask()) : false; |
---|
| 246 | |
---|
[1146] | 247 | if (!foundChildTask) { |
---|
| 248 | throw new IllegalArgumentException |
---|
| 249 | ("the task of the child instance to be added does not belong to the children " + |
---|
| 250 | "of the task of the parent instance"); |
---|
| 251 | }*/ |
---|
| 252 | |
---|
[1294] | 253 | ((OptionalInstance) instance).setChild(child); |
---|
[1146] | 254 | } |
---|
| 255 | |
---|
| 256 | /* (non-Javadoc) |
---|
| 257 | * @see ITaskBuilder#addExecutedTask(IUserSession, ITaskInstance) |
---|
| 258 | */ |
---|
| 259 | @Override |
---|
| 260 | public void addExecutedTask(IUserSession session, ITaskInstance taskInstance) { |
---|
| 261 | if (!(session instanceof UserSession)) { |
---|
| 262 | throw new IllegalArgumentException |
---|
| 263 | ("illegal type of session provided: " + session.getClass()); |
---|
| 264 | } |
---|
| 265 | |
---|
| 266 | if (!(taskInstance instanceof TaskInstance)) { |
---|
| 267 | throw new IllegalArgumentException |
---|
| 268 | ("illegal type of task instance provided: " + taskInstance.getClass()); |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | ((UserSession) session).addExecutedTask(taskInstance); |
---|
| 272 | } |
---|
| 273 | |
---|
| 274 | /* (non-Javadoc) |
---|
[1294] | 275 | * @see ITaskBuilder#addExecutedTask(IUserSession, int, ITaskInstance) |
---|
| 276 | */ |
---|
| 277 | public void addExecutedTask(IUserSession session, int index, ITaskInstance taskInstance) { |
---|
| 278 | if (!(session instanceof UserSession)) { |
---|
| 279 | throw new IllegalArgumentException |
---|
| 280 | ("illegal type of session provided: " + session.getClass()); |
---|
| 281 | } |
---|
| 282 | |
---|
| 283 | if (!(taskInstance instanceof TaskInstance)) { |
---|
| 284 | throw new IllegalArgumentException |
---|
| 285 | ("illegal type of task instance provided: " + taskInstance.getClass()); |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | ((UserSession) session).addExecutedTask(index, taskInstance); |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | /* (non-Javadoc) |
---|
[1216] | 292 | * @see ITaskBuilder#addTaskInstance(ITaskInstanceList, ITaskInstance) |
---|
[1146] | 293 | */ |
---|
| 294 | @Override |
---|
| 295 | public void addTaskInstance(ITaskInstanceList taskInstanceList, ITaskInstance taskInstance) { |
---|
[1294] | 296 | if (taskInstanceList instanceof SequenceInstance) { |
---|
| 297 | addChild((SequenceInstance) taskInstanceList, taskInstance); |
---|
[1146] | 298 | } |
---|
[1294] | 299 | else if (taskInstanceList instanceof IterationInstance) { |
---|
| 300 | addChild((IterationInstance) taskInstanceList, taskInstance); |
---|
| 301 | } |
---|
[1146] | 302 | else if (taskInstanceList instanceof UserSession) { |
---|
[1294] | 303 | addExecutedTask((UserSession) taskInstanceList, taskInstance); |
---|
[1146] | 304 | } |
---|
| 305 | else { |
---|
| 306 | throw new IllegalArgumentException |
---|
| 307 | ("illegal type of task instance list provided: " + taskInstanceList.getClass()); |
---|
| 308 | } |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | /* (non-Javadoc) |
---|
[1216] | 312 | * @see ITaskBuilder#addTaskInstance(ITaskInstanceList, int, ITaskInstance) |
---|
[1146] | 313 | */ |
---|
| 314 | @Override |
---|
| 315 | public void addTaskInstance(ITaskInstanceList taskInstanceList, |
---|
| 316 | int index, |
---|
| 317 | ITaskInstance taskInstance) |
---|
| 318 | { |
---|
[1294] | 319 | if (taskInstanceList instanceof SequenceInstance) { |
---|
| 320 | addChild((SequenceInstance) taskInstanceList, index, taskInstance); |
---|
[1146] | 321 | } |
---|
[1294] | 322 | else if (taskInstanceList instanceof IterationInstance) { |
---|
| 323 | addChild((IterationInstance) taskInstanceList, index, taskInstance); |
---|
| 324 | } |
---|
[1146] | 325 | else if (taskInstanceList instanceof UserSession) { |
---|
[1294] | 326 | addExecutedTask((UserSession) taskInstanceList, index, taskInstance); |
---|
[1146] | 327 | } |
---|
| 328 | else { |
---|
| 329 | throw new IllegalArgumentException |
---|
| 330 | ("illegal type of task instance list provided: " + taskInstanceList.getClass()); |
---|
| 331 | } |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | /* (non-Javadoc) |
---|
[1216] | 335 | * @see ITaskBuilder#setTaskInstance(ITaskInstanceList, int, ITaskInstance) |
---|
[1146] | 336 | */ |
---|
| 337 | @Override |
---|
| 338 | public void setTaskInstance(ITaskInstanceList taskInstanceList, |
---|
| 339 | int index, |
---|
| 340 | ITaskInstance taskInstance) |
---|
| 341 | { |
---|
[1294] | 342 | removeTaskInstance(taskInstanceList, index); |
---|
| 343 | addTaskInstance(taskInstanceList, index, taskInstance); |
---|
[1146] | 344 | } |
---|
| 345 | |
---|
| 346 | /* (non-Javadoc) |
---|
[1216] | 347 | * @see ITaskBuilder#setTask(ITaskInstance, ITask) |
---|
[1146] | 348 | */ |
---|
| 349 | @Override |
---|
| 350 | public void setTask(ITaskInstance taskInstance, ITask task) { |
---|
| 351 | if (!(taskInstance instanceof TaskInstance)) { |
---|
| 352 | throw new IllegalArgumentException |
---|
| 353 | ("illegal type of task instance provided: " + taskInstance.getClass()); |
---|
| 354 | } |
---|
[1362] | 355 | if (!(task instanceof Task)) { |
---|
| 356 | throw new IllegalArgumentException("illegal type of task provided: " + task.getClass()); |
---|
| 357 | } |
---|
[1146] | 358 | |
---|
[1362] | 359 | if (((TaskInstance) taskInstance).getTask() instanceof Task) { |
---|
| 360 | ((Task) ((TaskInstance) taskInstance).getTask()).removeInstance(taskInstance); |
---|
| 361 | } |
---|
[1146] | 362 | ((TaskInstance) taskInstance).setTask(task); |
---|
[1362] | 363 | |
---|
| 364 | ((Task) task).addInstance(taskInstance); |
---|
[1146] | 365 | } |
---|
| 366 | |
---|
[1216] | 367 | /* (non-Javadoc) |
---|
| 368 | * @see ITaskBuilder#addChild(ISequence, ITask) |
---|
[557] | 369 | */ |
---|
| 370 | @Override |
---|
[1146] | 371 | public void addChild(ISequence parent, ITask child) { |
---|
[557] | 372 | if (!(parent instanceof Sequence)) { |
---|
| 373 | throw new IllegalArgumentException |
---|
[1146] | 374 | ("illegal type of sequence provided: " + parent.getClass()); |
---|
[557] | 375 | } |
---|
[439] | 376 | |
---|
[1146] | 377 | addChildInternal((Sequence) parent, -1, child); |
---|
[439] | 378 | } |
---|
| 379 | |
---|
[1216] | 380 | /* (non-Javadoc) |
---|
| 381 | * @see ITaskBuilder#addChild(ISequence, int, ITask) |
---|
[557] | 382 | */ |
---|
| 383 | @Override |
---|
[1146] | 384 | public void addChild(ISequence parent, int index, ITask child) { |
---|
[557] | 385 | if (!(parent instanceof Sequence)) { |
---|
| 386 | throw new IllegalArgumentException |
---|
[1146] | 387 | ("illegal type of sequence provided: " + parent.getClass()); |
---|
[557] | 388 | } |
---|
[439] | 389 | |
---|
[1146] | 390 | addChildInternal((Sequence) parent, index, child); |
---|
[439] | 391 | } |
---|
| 392 | |
---|
[1126] | 393 | /* (non-Javadoc) |
---|
[1216] | 394 | * @see ITaskBuilder#setChild(ISequence, int, ITask) |
---|
[1126] | 395 | */ |
---|
| 396 | @Override |
---|
[1146] | 397 | public void setChild(ISequence parent, int index, ITask child) { |
---|
[1126] | 398 | if (!(parent instanceof Sequence)) { |
---|
| 399 | throw new IllegalArgumentException |
---|
[1146] | 400 | ("illegal type of sequence provided: " + parent.getClass()); |
---|
[1126] | 401 | } |
---|
| 402 | |
---|
[1146] | 403 | ((Sequence) parent).removeChild(index); |
---|
| 404 | addChildInternal((Sequence) parent, index, child); |
---|
[1126] | 405 | } |
---|
| 406 | |
---|
[1216] | 407 | /* (non-Javadoc) |
---|
| 408 | * @see ITaskBuilder#addChild(ISelection, ITask) |
---|
[557] | 409 | */ |
---|
| 410 | @Override |
---|
[1146] | 411 | public void addChild(ISelection parent, ITask child) { |
---|
[557] | 412 | if (!(parent instanceof Selection)) { |
---|
| 413 | throw new IllegalArgumentException |
---|
[1146] | 414 | ("illegal type of selection provided: " + parent.getClass()); |
---|
[557] | 415 | } |
---|
[439] | 416 | |
---|
[1146] | 417 | addChildInternal((Selection) parent, -1, child); |
---|
[439] | 418 | } |
---|
| 419 | |
---|
[1216] | 420 | /* (non-Javadoc) |
---|
| 421 | * @see ITaskBuilder#setMarkedTask(IIteration, ITask) |
---|
[557] | 422 | */ |
---|
| 423 | @Override |
---|
[1146] | 424 | public void setMarkedTask(IIteration iteration, ITask newChild) { |
---|
[557] | 425 | if (!(iteration instanceof Iteration)) { |
---|
| 426 | throw new IllegalArgumentException |
---|
| 427 | ("illegal type of iteration provided: " + iteration.getClass()); |
---|
| 428 | } |
---|
[439] | 429 | |
---|
[1146] | 430 | if (!(newChild instanceof Task)) { |
---|
[557] | 431 | throw new IllegalArgumentException |
---|
[1146] | 432 | ("illegal type of task provided: " + newChild.getClass()); |
---|
[557] | 433 | } |
---|
| 434 | |
---|
[1146] | 435 | ((Iteration) iteration).setMarkedTask(newChild); |
---|
[439] | 436 | } |
---|
| 437 | |
---|
[1126] | 438 | /* (non-Javadoc) |
---|
[1216] | 439 | * @see ITaskTreeBuilder#setChild(IOptional, ITaskTreeNode) |
---|
[1126] | 440 | */ |
---|
| 441 | @Override |
---|
[1146] | 442 | public void setMarkedTask(IOptional optional, ITask newChild) { |
---|
[1126] | 443 | if (!(optional instanceof Optional)) { |
---|
| 444 | throw new IllegalArgumentException |
---|
| 445 | ("illegal type of optional provided: " + optional.getClass()); |
---|
| 446 | } |
---|
| 447 | |
---|
[1146] | 448 | if (!(newChild instanceof Task)) { |
---|
[1126] | 449 | throw new IllegalArgumentException |
---|
[1146] | 450 | ("illegal type of task provided: " + newChild.getClass()); |
---|
[1126] | 451 | } |
---|
| 452 | |
---|
[1146] | 453 | ((Optional) optional).setMarkedTask(newChild); |
---|
[1126] | 454 | } |
---|
| 455 | |
---|
[1216] | 456 | /* (non-Javadoc) |
---|
| 457 | * @see ITaskBuilder#removeChild(ISequence, int) |
---|
[557] | 458 | */ |
---|
| 459 | @Override |
---|
| 460 | public void removeChild(ISequence parent, int index) { |
---|
[1146] | 461 | if (!(parent instanceof Sequence)) { |
---|
[557] | 462 | throw new IllegalArgumentException |
---|
[1146] | 463 | ("illegal type of sequence provided: " + parent.getClass()); |
---|
[557] | 464 | } |
---|
[439] | 465 | |
---|
[1146] | 466 | ((Sequence) parent).removeChild(index); |
---|
[439] | 467 | } |
---|
| 468 | |
---|
[1216] | 469 | /* (non-Javadoc) |
---|
| 470 | * @see ITaskBuilder#removeChild(ISelection, ITask) |
---|
[557] | 471 | */ |
---|
| 472 | @Override |
---|
[1146] | 473 | public void removeChild(ISelection parent, ITask child) { |
---|
| 474 | if (!(parent instanceof Selection)) { |
---|
[557] | 475 | throw new IllegalArgumentException |
---|
[1146] | 476 | ("illegal type of selection provided: " + parent.getClass()); |
---|
[557] | 477 | } |
---|
| 478 | |
---|
[1146] | 479 | List<ITask> children = parent.getChildren(); |
---|
[1126] | 480 | |
---|
| 481 | for (int i = 0; i < children.size(); i++) { |
---|
| 482 | if ((children.get(i) == child) || |
---|
| 483 | ((children.get(i) != null) && (children.get(i).equals(child)))) |
---|
[557] | 484 | { |
---|
[1146] | 485 | ((Selection) parent).removeChild(i); |
---|
[557] | 486 | break; |
---|
| 487 | } |
---|
| 488 | } |
---|
[439] | 489 | } |
---|
| 490 | |
---|
[1126] | 491 | /* (non-Javadoc) |
---|
[1216] | 492 | * @see ITaskBuilder#removeTaskInstance(ITaskInstanceList, int) |
---|
[1146] | 493 | */ |
---|
| 494 | @Override |
---|
| 495 | public void removeTaskInstance(ITaskInstanceList taskInstanceList, int index) { |
---|
[1294] | 496 | if (taskInstanceList instanceof SequenceInstance) { |
---|
| 497 | ((SequenceInstance) taskInstanceList).removeChild(index); |
---|
[1146] | 498 | } |
---|
[1294] | 499 | else if (taskInstanceList instanceof IterationInstance) { |
---|
| 500 | ((IterationInstance) taskInstanceList).removeChild(index); |
---|
| 501 | } |
---|
[1146] | 502 | else if (taskInstanceList instanceof UserSession) { |
---|
| 503 | ((UserSession) taskInstanceList).removeExecutedTask(index); |
---|
| 504 | } |
---|
| 505 | else { |
---|
| 506 | throw new IllegalArgumentException |
---|
| 507 | ("illegal type of task instance list provided: " + taskInstanceList.getClass()); |
---|
| 508 | } |
---|
| 509 | } |
---|
| 510 | |
---|
| 511 | /* (non-Javadoc) |
---|
[1216] | 512 | * @see ITaskTreeBuilder#replaceChild(ISelection, ITaskTreeNode, ITaskTreeNode) |
---|
[1126] | 513 | */ |
---|
| 514 | @Override |
---|
[1146] | 515 | public void replaceChild(ISelection parent, ITask oldChild, ITask newChild) { |
---|
| 516 | if (!(parent instanceof Selection)) { |
---|
[1126] | 517 | throw new IllegalArgumentException |
---|
[1146] | 518 | ("illegal type of selection provided: " + parent.getClass()); |
---|
[1126] | 519 | } |
---|
| 520 | |
---|
[1146] | 521 | List<ITask> children = parent.getChildren(); |
---|
[1126] | 522 | |
---|
| 523 | for (int i = 0; i < children.size(); i++) { |
---|
| 524 | if ((children.get(i) == oldChild) || |
---|
| 525 | ((children.get(i) != null) && (children.get(i).equals(oldChild)))) |
---|
| 526 | { |
---|
[1146] | 527 | ((Selection) parent).removeChild(i); |
---|
| 528 | ((Selection) parent).addChild(i, newChild); |
---|
[1126] | 529 | break; |
---|
| 530 | } |
---|
| 531 | } |
---|
| 532 | } |
---|
| 533 | |
---|
[557] | 534 | /** |
---|
[1216] | 535 | * <p> |
---|
| 536 | * internal convenience method for adding children to a structuring temporal relationship |
---|
| 537 | * including a check for the child type. |
---|
| 538 | * </p> |
---|
[988] | 539 | */ |
---|
[1146] | 540 | private void addChildInternal(StructuringTemporalRelationship parent, int index, ITask child) { |
---|
| 541 | if (!(child instanceof Task)) { |
---|
[557] | 542 | throw new IllegalArgumentException |
---|
[1146] | 543 | ("illegal type of task provided: " + child.getClass()); |
---|
[557] | 544 | } |
---|
[439] | 545 | |
---|
[557] | 546 | if (index > -1) { |
---|
[1146] | 547 | parent.addChild(index, child); |
---|
[557] | 548 | } |
---|
| 549 | else { |
---|
[1146] | 550 | parent.addChild(child); |
---|
[557] | 551 | } |
---|
[439] | 552 | } |
---|
| 553 | |
---|
| 554 | } |
---|