Changeset 557 for trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeimpl/TaskTreeBuilder.java
- Timestamp:
- 08/17/12 08:33:29 (12 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeimpl/TaskTreeBuilder.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTreeBuilderImpl.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 21.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.treeimpl; 9 8 10 import de.ugoe.cs.quest.tasktrees.treeifc.I teration;11 import de.ugoe.cs.quest.tasktrees.treeifc. Selection;12 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;13 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;14 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;15 import de.ugoe.cs.quest.tasktrees.treeifc. TextInputInteractionTask;9 import de.ugoe.cs.quest.tasktrees.treeifc.IIteration; 10 import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; 11 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 12 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 13 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 14 import de.ugoe.cs.quest.tasktrees.treeifc.ITextInputEventTask; 16 15 17 //-------------------------------------------------------------------------------------------------18 16 /** 19 17 * TODO comment … … 22 20 * @author 2012, last modified by $Author: patrick$ 23 21 */ 24 //------------------------------------------------------------------------------------------------- 25 public class TaskTreeBuilderImpl implements TaskTreeBuilder 26 { 27 //-----------------------------------------------------------------------------------------------28 /* (non-Javadoc)29 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Sequence, TaskTreeNode)30 */31 //-----------------------------------------------------------------------------------------------32 @Override33 public void addChild(Sequence parent, TaskTreeNode child)34 {35 if (!(parent instanceof SequenceImpl))36 {37 throw new IllegalArgumentException 38 ("illegal type of task tree node provided: " + parent.getClass());22 public class TaskTreeBuilder implements ITaskTreeBuilder { 23 24 /* 25 * (non-Javadoc) 26 * 27 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Sequence, TaskTreeNode) 28 */ 29 @Override 30 public void addChild(ISequence parent, ITaskTreeNode child) { 31 if (!(parent instanceof Sequence)) { 32 throw new IllegalArgumentException 33 ("illegal type of task tree node provided: " + parent.getClass()); 34 } 35 36 addChildInternal(parent, -1, child); 39 37 } 40 38 41 addChildInternal(parent, -1, child); 42 } 39 /* 40 * (non-Javadoc) 41 * 42 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Sequence, int, TaskTreeNode) 43 */ 44 @Override 45 public void addChild(ISequence parent, int index, ITaskTreeNode child) { 46 if (!(parent instanceof Sequence)) { 47 throw new IllegalArgumentException 48 ("illegal type of task tree node provided: " + parent.getClass()); 49 } 43 50 44 //----------------------------------------------------------------------------------------------- 45 /* (non-Javadoc) 46 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Sequence, int, TaskTreeNode) 47 */ 48 //----------------------------------------------------------------------------------------------- 49 @Override 50 public void addChild(Sequence parent, int index, TaskTreeNode child) 51 { 52 if (!(parent instanceof SequenceImpl)) 53 { 54 throw new IllegalArgumentException 55 ("illegal type of task tree node provided: " + parent.getClass()); 51 addChildInternal(parent, index, child); 56 52 } 57 53 58 addChildInternal(parent, index, child); 59 } 54 /* 55 * (non-Javadoc) 56 * 57 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Selection, TaskTreeNode) 58 */ 59 @Override 60 public void addChild(ISelection parent, ITaskTreeNode child) { 61 if (!(parent instanceof Selection)) { 62 throw new IllegalArgumentException 63 ("illegal type of task tree node provided: " + parent.getClass()); 64 } 60 65 61 //----------------------------------------------------------------------------------------------- 62 /* (non-Javadoc) 63 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Selection, TaskTreeNode) 64 */ 65 //----------------------------------------------------------------------------------------------- 66 @Override 67 public void addChild(Selection parent, TaskTreeNode child) 68 { 69 if (!(parent instanceof SelectionImpl)) 70 { 71 throw new IllegalArgumentException 72 ("illegal type of task tree node provided: " + parent.getClass()); 66 addChildInternal(parent, -1, child); 73 67 } 74 68 75 addChildInternal(parent, -1, child); 76 } 69 /* 70 * (non-Javadoc) 71 * 72 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(de.ugoe.cs.tasktree.treeifc. 73 * TextInputEventTask, de.ugoe.cs.tasktree.treeifc.TaskTreeNode) 74 */ 75 @Override 76 public void addChild(ITextInputEventTask parent, ITaskTreeNode child) { 77 if (!(parent instanceof TextInputEventTask)) { 78 throw new IllegalArgumentException 79 ("illegal type of task tree node provided: " + parent.getClass()); 80 } 77 81 78 //----------------------------------------------------------------------------------------------- 79 /* (non-Javadoc) 80 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(de.ugoe.cs.tasktree.treeifc.TextInputInteractionTask, de.ugoe.cs.tasktree.treeifc.TaskTreeNode) 81 */ 82 //----------------------------------------------------------------------------------------------- 83 @Override 84 public void addChild(TextInputInteractionTask parent, TaskTreeNode child) 85 { 86 if (!(parent instanceof TextInputInteractionTaskImpl)) 87 { 88 throw new IllegalArgumentException 89 ("illegal type of task tree node provided: " + parent.getClass()); 82 addChildInternal(parent, -1, child); 90 83 } 91 84 92 addChildInternal(parent, -1, child); 93 } 85 /* 86 * (non-Javadoc) 87 * 88 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#setChild(Iteration, TaskTreeNode) 89 */ 90 @Override 91 public void setChild(IIteration iteration, ITaskTreeNode newChild) { 92 if (!(iteration instanceof Iteration)) { 93 throw new IllegalArgumentException 94 ("illegal type of iteration provided: " + iteration.getClass()); 95 } 94 96 95 //----------------------------------------------------------------------------------------------- 96 /* (non-Javadoc) 97 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#setChild(Iteration, TaskTreeNode) 98 */ 99 //----------------------------------------------------------------------------------------------- 100 @Override 101 public void setChild(Iteration iteration, TaskTreeNode newChild) 102 { 103 if (!(iteration instanceof IterationImpl)) 104 { 105 throw new IllegalArgumentException 106 ("illegal type of iteration provided: " + iteration.getClass()); 97 if (!(newChild instanceof TaskTreeNode)) { 98 throw new IllegalArgumentException 99 ("illegal type of task tree node provided: " + newChild.getClass()); 100 } 101 102 ((Iteration) iteration).setChild(newChild); 107 103 } 108 104 109 if (!(newChild instanceof TaskTreeNodeImpl)) 110 { 111 throw new IllegalArgumentException 112 ("illegal type of task tree node provided: " + newChild.getClass()); 113 } 114 115 ((IterationImpl) iteration).setChild(determineNode(newChild)); 116 } 105 /* 106 * (non-Javadoc) 107 * 108 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#removeChild(Sequence, int) 109 */ 110 @Override 111 public void removeChild(ISequence parent, int index) { 112 if (!(parent instanceof TaskTreeNode)) { 113 throw new IllegalArgumentException 114 ("illegal type of task tree node provided: " + parent.getClass()); 115 } 117 116 118 //----------------------------------------------------------------------------------------------- 119 /* (non-Javadoc) 120 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#removeChild(Sequence, int) 121 */ 122 //----------------------------------------------------------------------------------------------- 123 @Override 124 public void removeChild(Sequence parent, int index) 125 { 126 if (!(parent instanceof TaskTreeNodeImpl)) 127 { 128 throw new IllegalArgumentException 129 ("illegal type of task tree node provided: " + parent.getClass()); 117 ((TaskTreeNode) parent).removeChild(index); 130 118 } 131 119 132 ((TaskTreeNodeImpl) parent).removeChild(index); 133 } 120 /* 121 * (non-Javadoc) 122 * 123 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#removeChild(Selection, TaskTreeNode) 124 */ 125 @Override 126 public void removeChild(ISelection parent, ITaskTreeNode child) { 127 if (!(parent instanceof TaskTreeNode)) { 128 throw new IllegalArgumentException 129 ("illegal type of task tree node provided: " + parent.getClass()); 130 } 134 131 135 //----------------------------------------------------------------------------------------------- 136 /* (non-Javadoc) 137 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#removeChild(Selection, TaskTreeNode) 138 */ 139 //----------------------------------------------------------------------------------------------- 140 @Override 141 public void removeChild(Selection parent, TaskTreeNode child) 142 { 143 if (!(parent instanceof TaskTreeNodeImpl)) 144 { 145 throw new IllegalArgumentException 146 ("illegal type of task tree node provided: " + parent.getClass()); 132 for (int i = 0; i < parent.getChildren().size(); i++) { 133 if ((parent.getChildren().get(i) == child) || 134 ((parent.getChildren().get(i) != null) && 135 (parent.getChildren().get(i).equals(child)))) 136 { 137 ((TaskTreeNode) parent).removeChild(i); 138 break; 139 } 140 } 147 141 } 148 142 149 for (int i = 0; i < parent.getChildren().size(); i++) 150 { 151 if ((parent.getChildren().get(i) == child) || 152 ((parent.getChildren().get(i) != null) && (parent.getChildren().get(i).equals(child)))) 153 { 154 ((TaskTreeNodeImpl) parent).removeChild(i); 155 break; 156 } 157 } 158 } 143 /* 144 * (non-Javadoc) 145 * 146 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#setDescription(TaskTreeNode, String) 147 */ 148 @Override 149 public void setDescription(ITaskTreeNode parent, String description) { 150 if (!(parent instanceof TaskTreeNode)) { 151 throw new IllegalArgumentException 152 ("illegal type of task tree node provided: " + parent.getClass()); 153 } 159 154 160 //----------------------------------------------------------------------------------------------- 161 /* (non-Javadoc) 162 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#setDescription(TaskTreeNode, String) 163 */ 164 //----------------------------------------------------------------------------------------------- 165 @Override 166 public void setDescription(TaskTreeNode parent, String description) 167 { 168 if (!(parent instanceof TaskTreeNodeImpl)) 169 { 170 throw new IllegalArgumentException 171 ("illegal type of task tree node provided: " + parent.getClass()); 155 ((TaskTreeNode) parent).setDescription(description); 172 156 } 173 157 174 ((TaskTreeNodeImpl) parent).setDescription(description); 175 } 176 177 //----------------------------------------------------------------------------------------------- 178 /** 158 /** 179 159 * 180 160 */ 181 //----------------------------------------------------------------------------------------------- 182 private void addChildInternal(TaskTreeNode parent, int index, TaskTreeNode child) 183 { 184 if (!(child instanceof TaskTreeNodeImpl)) 185 { 186 throw new IllegalArgumentException 187 ("illegal type of task tree node provided: " + child.getClass()); 161 private void addChildInternal(ITaskTreeNode parent, int index, ITaskTreeNode child) { 162 if (!(child instanceof TaskTreeNode)) { 163 throw new IllegalArgumentException 164 ("illegal type of task tree node provided: " + child.getClass()); 165 } 166 167 if (index > -1) { 168 ((TaskTreeNode) parent).addChild(index, child); 169 } 170 else { 171 ((TaskTreeNode) parent).addChild(child); 172 } 188 173 } 189 190 if (index > -1)191 {192 ((TaskTreeNodeImpl) parent).addChild(index, determineNode(child));193 }194 else195 {196 ((TaskTreeNodeImpl) parent).addChild(determineNode(child));197 }198 }199 200 //-----------------------------------------------------------------------------------------------201 /**202 * TODO: comment203 *204 * @param newChild205 * @return206 */207 //-----------------------------------------------------------------------------------------------208 private TaskTreeNode determineNode(TaskTreeNode newNode)209 {210 return newNode;211 /*TaskTreeNode node = mTaskMap.get(newNode);212 if (node == null)213 {214 node = newNode;215 mTaskMap.put(node, node);216 }217 218 return node;*/219 }220 174 221 175 }
Note: See TracChangeset
for help on using the changeset viewer.