source: branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/SequenceInstance.java

Last change on this file was 1734, checked in by rkrimmel, 10 years ago

Added automatically created javadoc, still needs to be commented properly though

File size: 4.5 KB
Line 
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
15package de.ugoe.cs.autoquest.tasktrees.treeimpl;
16
17import java.util.Collections;
18import java.util.Iterator;
19import java.util.LinkedList;
20import java.util.List;
21
22import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance;
23import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence;
24import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance;
25import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
26
27// TODO: Auto-generated Javadoc
28/**
29 * <p>
30 * Default implementation of {@link IIterationInstance}.
31 * </p>
32 *
33 * @author Patrick Harms
34 */
35class SequenceInstance extends TaskInstance implements ISequenceInstance {
36
37        /** <p> default serial version UID </p>. */
38        private static final long serialVersionUID = 1L;
39
40        /** <p> the children of this task instance which are task instances, as well </p>. */
41        private List<ITaskInstance> children;
42
43        /**
44         * <p>
45         * initializes this instance with the respective task model
46         * </p>.
47         *
48         * @param task            the task of which this is an instance
49         */
50        SequenceInstance(ISequence task) {
51                super(task);
52        }
53
54        /**
55         * <p>
56         * used to add a child to this task instance at a specific position
57         * </p>.
58         *
59         * @param index            the position of the new child in the list of children
60         * @param child            the new child of this instance
61         */
62        synchronized void addChild(int index, ITaskInstance child) {
63                if (children == null) {
64                        children = new LinkedList<ITaskInstance>();
65                }
66
67                children.add(index, child);
68        }
69
70        /**
71         * <p>
72         * used to add a child to this task instance
73         * </p>.
74         *
75         * @param child            the new child of this instance
76         */
77        synchronized void addChild(ITaskInstance child) {
78                if (children == null) {
79                        children = new LinkedList<ITaskInstance>();
80                }
81
82                children.add(child);
83        }
84
85        /*
86         * (non-Javadoc)
87         *
88         * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.ISequenceInstance#clone()
89         */
90        @Override
91        public synchronized ISequenceInstance clone() {
92                final SequenceInstance clone = (SequenceInstance) super.clone();
93
94                if (children != null) {
95                        clone.children = new LinkedList<ITaskInstance>();
96
97                        for (final ITaskInstance child : children) {
98                                clone.children.add(child.clone());
99                        }
100                }
101
102                return clone;
103        }
104
105        /*
106         * (non-Javadoc)
107         *
108         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#get(int)
109         */
110        @Override
111        public ITaskInstance get(int index) {
112                if (children == null) {
113                        throw new IndexOutOfBoundsException(Integer.toString(index));
114                } else {
115                        return children.get(index);
116                }
117        }
118
119        /*
120         * (non-Javadoc)
121         *
122         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance#getChildren()
123         */
124        /**
125         * Gets the children.
126         *
127         * @return the children
128         */
129        public synchronized List<ITaskInstance> getChildren() {
130                if (children == null) {
131                        children = new LinkedList<ITaskInstance>();
132                }
133
134                return Collections.unmodifiableList(children);
135        }
136
137        /*
138         * (non-Javadoc)
139         *
140         * @see
141         * de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance#getSequence()
142         */
143        @Override
144        public ISequence getSequence() {
145                return (ISequence) super.getTask();
146        }
147
148        /*
149         * (non-Javadoc)
150         *
151         * @see java.lang.Iterable#iterator()
152         */
153        @Override
154        public Iterator<ITaskInstance> iterator() {
155                return getChildren().iterator();
156        }
157
158        /**
159         * <p>
160         * removes a child from this task instance at a specific position
161         * </p>.
162         *
163         * @param index            the position of the child to be removed
164         * @return the child removed from the children of this instance
165         */
166        synchronized ITaskInstance removeChild(int index) {
167                if (children != null) {
168                        return children.remove(index);
169                } else {
170                        throw new IllegalArgumentException(
171                                        "this task instance does not have children that can be removed");
172                }
173        }
174
175        /*
176         * (non-Javadoc)
177         *
178         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#size()
179         */
180        @Override
181        public int size() {
182                if (children == null) {
183                        return 0;
184                } else {
185                        return children.size();
186                }
187        }
188
189}
Note: See TracBrowser for help on using the repository browser.