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