source: trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeimpl/TaskTreeBuilder.java @ 691

Last change on this file since 691 was 691, checked in by pharms, 12 years ago
  • moved text input detection from task tree generation to dedicated command to be run on sequences
  • Property svn:executable set to *
File size: 4.6 KB
Line 
1package de.ugoe.cs.quest.tasktrees.treeimpl;
2
3import de.ugoe.cs.quest.tasktrees.treeifc.IIteration;
4import de.ugoe.cs.quest.tasktrees.treeifc.ISelection;
5import de.ugoe.cs.quest.tasktrees.treeifc.ISequence;
6import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder;
7import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode;
8
9/**
10 * TODO comment
11 *
12 * @version $Revision: $ $Date: 21.02.2012$
13 * @author 2012, last modified by $Author: patrick$
14 */
15public class TaskTreeBuilder implements ITaskTreeBuilder {
16
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        }
28
29        addChildInternal(parent, -1, child);
30    }
31
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        }
43
44        addChildInternal(parent, index, child);
45    }
46
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        }
58
59        addChildInternal(parent, -1, child);
60    }
61
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        }
73
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);
80    }
81
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        }
93
94        ((TaskTreeNode) parent).removeChild(index);
95    }
96
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        }
118    }
119
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);
133    }
134
135    /**
136   *
137   */
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        }
143
144        if (index > -1) {
145            ((TaskTreeNode) parent).addChild(index, child);
146        }
147        else {
148            ((TaskTreeNode) parent).addChild(child);
149        }
150    }
151
152}
Note: See TracBrowser for help on using the repository browser.