[922] | 1 | package de.ugoe.cs.autoquest.tasktrees.treeimpl; |
---|
[439] | 2 | |
---|
[922] | 3 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; |
---|
| 4 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; |
---|
| 5 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; |
---|
| 6 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder; |
---|
| 7 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; |
---|
[439] | 8 | |
---|
| 9 | /** |
---|
| 10 | * TODO comment |
---|
| 11 | * |
---|
| 12 | * @version $Revision: $ $Date: 21.02.2012$ |
---|
| 13 | * @author 2012, last modified by $Author: patrick$ |
---|
| 14 | */ |
---|
[557] | 15 | public class TaskTreeBuilder implements ITaskTreeBuilder { |
---|
[439] | 16 | |
---|
[557] | 17 | /* |
---|
| 18 | * (non-Javadoc) |
---|
| 19 | * |
---|
| 20 | * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Sequence, TaskTreeNode) |
---|
| 21 | */ |
---|
| 22 | @Override |
---|
| 23 | public void addChild(ISequence parent, ITaskTreeNode child) { |
---|
| 24 | if (!(parent instanceof Sequence)) { |
---|
| 25 | throw new IllegalArgumentException |
---|
| 26 | ("illegal type of task tree node provided: " + parent.getClass()); |
---|
| 27 | } |
---|
[439] | 28 | |
---|
[557] | 29 | addChildInternal(parent, -1, child); |
---|
[439] | 30 | } |
---|
| 31 | |
---|
[557] | 32 | /* |
---|
| 33 | * (non-Javadoc) |
---|
| 34 | * |
---|
| 35 | * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Sequence, int, TaskTreeNode) |
---|
| 36 | */ |
---|
| 37 | @Override |
---|
| 38 | public void addChild(ISequence parent, int index, ITaskTreeNode child) { |
---|
| 39 | if (!(parent instanceof Sequence)) { |
---|
| 40 | throw new IllegalArgumentException |
---|
| 41 | ("illegal type of task tree node provided: " + parent.getClass()); |
---|
| 42 | } |
---|
[439] | 43 | |
---|
[557] | 44 | addChildInternal(parent, index, child); |
---|
[439] | 45 | } |
---|
| 46 | |
---|
[557] | 47 | /* |
---|
| 48 | * (non-Javadoc) |
---|
| 49 | * |
---|
| 50 | * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Selection, TaskTreeNode) |
---|
| 51 | */ |
---|
| 52 | @Override |
---|
| 53 | public void addChild(ISelection parent, ITaskTreeNode child) { |
---|
| 54 | if (!(parent instanceof Selection)) { |
---|
| 55 | throw new IllegalArgumentException |
---|
| 56 | ("illegal type of task tree node provided: " + parent.getClass()); |
---|
| 57 | } |
---|
[439] | 58 | |
---|
[557] | 59 | addChildInternal(parent, -1, child); |
---|
[439] | 60 | } |
---|
| 61 | |
---|
[557] | 62 | /* |
---|
| 63 | * (non-Javadoc) |
---|
| 64 | * |
---|
| 65 | * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#setChild(Iteration, TaskTreeNode) |
---|
| 66 | */ |
---|
| 67 | @Override |
---|
| 68 | public void setChild(IIteration iteration, ITaskTreeNode newChild) { |
---|
| 69 | if (!(iteration instanceof Iteration)) { |
---|
| 70 | throw new IllegalArgumentException |
---|
| 71 | ("illegal type of iteration provided: " + iteration.getClass()); |
---|
| 72 | } |
---|
[439] | 73 | |
---|
[557] | 74 | if (!(newChild instanceof TaskTreeNode)) { |
---|
| 75 | throw new IllegalArgumentException |
---|
| 76 | ("illegal type of task tree node provided: " + newChild.getClass()); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | ((Iteration) iteration).setChild(newChild); |
---|
[439] | 80 | } |
---|
| 81 | |
---|
[557] | 82 | /* |
---|
| 83 | * (non-Javadoc) |
---|
| 84 | * |
---|
| 85 | * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#removeChild(Sequence, int) |
---|
| 86 | */ |
---|
| 87 | @Override |
---|
| 88 | public void removeChild(ISequence parent, int index) { |
---|
| 89 | if (!(parent instanceof TaskTreeNode)) { |
---|
| 90 | throw new IllegalArgumentException |
---|
| 91 | ("illegal type of task tree node provided: " + parent.getClass()); |
---|
| 92 | } |
---|
[439] | 93 | |
---|
[557] | 94 | ((TaskTreeNode) parent).removeChild(index); |
---|
[439] | 95 | } |
---|
| 96 | |
---|
[557] | 97 | /* |
---|
| 98 | * (non-Javadoc) |
---|
| 99 | * |
---|
| 100 | * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#removeChild(Selection, TaskTreeNode) |
---|
| 101 | */ |
---|
| 102 | @Override |
---|
| 103 | public void removeChild(ISelection parent, ITaskTreeNode child) { |
---|
| 104 | if (!(parent instanceof TaskTreeNode)) { |
---|
| 105 | throw new IllegalArgumentException |
---|
| 106 | ("illegal type of task tree node provided: " + parent.getClass()); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | for (int i = 0; i < parent.getChildren().size(); i++) { |
---|
| 110 | if ((parent.getChildren().get(i) == child) || |
---|
| 111 | ((parent.getChildren().get(i) != null) && |
---|
| 112 | (parent.getChildren().get(i).equals(child)))) |
---|
| 113 | { |
---|
| 114 | ((TaskTreeNode) parent).removeChild(i); |
---|
| 115 | break; |
---|
| 116 | } |
---|
| 117 | } |
---|
[439] | 118 | } |
---|
| 119 | |
---|
[557] | 120 | /* |
---|
| 121 | * (non-Javadoc) |
---|
| 122 | * |
---|
| 123 | * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#setDescription(TaskTreeNode, String) |
---|
| 124 | */ |
---|
| 125 | @Override |
---|
| 126 | public void setDescription(ITaskTreeNode parent, String description) { |
---|
| 127 | if (!(parent instanceof TaskTreeNode)) { |
---|
| 128 | throw new IllegalArgumentException |
---|
| 129 | ("illegal type of task tree node provided: " + parent.getClass()); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | ((TaskTreeNode) parent).setDescription(description); |
---|
[439] | 133 | } |
---|
| 134 | |
---|
[557] | 135 | /** |
---|
[988] | 136 | * |
---|
| 137 | */ |
---|
[557] | 138 | private void addChildInternal(ITaskTreeNode parent, int index, ITaskTreeNode child) { |
---|
| 139 | if (!(child instanceof TaskTreeNode)) { |
---|
| 140 | throw new IllegalArgumentException |
---|
| 141 | ("illegal type of task tree node provided: " + child.getClass()); |
---|
| 142 | } |
---|
[439] | 143 | |
---|
[557] | 144 | if (index > -1) { |
---|
| 145 | ((TaskTreeNode) parent).addChild(index, child); |
---|
| 146 | } |
---|
| 147 | else { |
---|
| 148 | ((TaskTreeNode) parent).addChild(child); |
---|
| 149 | } |
---|
[439] | 150 | } |
---|
| 151 | |
---|
| 152 | } |
---|