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 java.util.LinkedList; |
---|
18 | import java.util.List; |
---|
19 | |
---|
20 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IStructuringTemporalRelationship; |
---|
21 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; |
---|
22 | |
---|
23 | // TODO: Auto-generated Javadoc |
---|
24 | /** |
---|
25 | * <p> |
---|
26 | * this is the default implementation of the interface |
---|
27 | * {@link IStructuringTemporalRelationship}. It does not do anything fancy |
---|
28 | * except implementing the interface. |
---|
29 | * </p> |
---|
30 | * |
---|
31 | * @author Patrick Harms |
---|
32 | */ |
---|
33 | abstract class StructuringTemporalRelationship extends Task implements |
---|
34 | IStructuringTemporalRelationship { |
---|
35 | |
---|
36 | /** <p> default serial version UID </p>. */ |
---|
37 | private static final long serialVersionUID = 1L; |
---|
38 | |
---|
39 | /** <p> the list of children of this temporal relationship </p>. */ |
---|
40 | private List<ITask> children = new LinkedList<ITask>(); |
---|
41 | |
---|
42 | /** |
---|
43 | * <p> |
---|
44 | * initializes this temporal relationship with a human readable name |
---|
45 | * </p>. |
---|
46 | * |
---|
47 | * @param relationshipType the human readable name of this temporal relationship |
---|
48 | */ |
---|
49 | StructuringTemporalRelationship(String relationshipType) { |
---|
50 | super(relationshipType); |
---|
51 | |
---|
52 | if ((relationshipType == null) || ("".equals(relationshipType))) { |
---|
53 | throw new IllegalArgumentException( |
---|
54 | "the relationship type must be something meaningful"); |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | /** |
---|
59 | * <p> |
---|
60 | * used to add a new child to this temporal relationship at a specific |
---|
61 | * position. |
---|
62 | * </p> |
---|
63 | * |
---|
64 | * @param index |
---|
65 | * the index of the new child to be added. |
---|
66 | * @param newChild |
---|
67 | * the new child to be added |
---|
68 | */ |
---|
69 | void addChild(int index, ITask newChild) { |
---|
70 | children.add(index, newChild); |
---|
71 | } |
---|
72 | |
---|
73 | /** |
---|
74 | * <p> |
---|
75 | * used to add a new child to this temporal relationship. |
---|
76 | * </p> |
---|
77 | * |
---|
78 | * @param newChild |
---|
79 | * the new child to be added |
---|
80 | */ |
---|
81 | void addChild(ITask newChild) { |
---|
82 | children.add(newChild); |
---|
83 | } |
---|
84 | |
---|
85 | /* |
---|
86 | * (non-Javadoc) |
---|
87 | * |
---|
88 | * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.Task#clone() |
---|
89 | */ |
---|
90 | @Override |
---|
91 | public synchronized StructuringTemporalRelationship clone() { |
---|
92 | StructuringTemporalRelationship clone = null; |
---|
93 | clone = (StructuringTemporalRelationship) super.clone(); |
---|
94 | |
---|
95 | clone.children = new LinkedList<ITask>(); |
---|
96 | |
---|
97 | for (final ITask child : this.children) { |
---|
98 | clone.children.add(child.clone()); |
---|
99 | } |
---|
100 | |
---|
101 | return clone; |
---|
102 | } |
---|
103 | |
---|
104 | /* |
---|
105 | * (non-Javadoc) |
---|
106 | * |
---|
107 | * @see |
---|
108 | * de.ugoe.cs.autoquest.tasktrees.treeifc.IStructuringTemporalRelationship |
---|
109 | * #getChildren() |
---|
110 | */ |
---|
111 | @Override |
---|
112 | public List<ITask> getChildren() { |
---|
113 | return children; |
---|
114 | } |
---|
115 | |
---|
116 | /** |
---|
117 | * <p> |
---|
118 | * removes a child from this temporal relationship at a specific position. |
---|
119 | * </p> |
---|
120 | * |
---|
121 | * @param index |
---|
122 | * the index of the child to be removed. |
---|
123 | */ |
---|
124 | void removeChild(int index) { |
---|
125 | children.remove(index); |
---|
126 | } |
---|
127 | } |
---|