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

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