Changeset 1733 for branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/SequenceInstance.java
- Timestamp:
- 09/05/14 19:33:12 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/SequenceInstance.java
r1414 r1733 34 34 class SequenceInstance extends TaskInstance implements ISequenceInstance { 35 35 36 37 38 39 40 41 36 /** 37 * <p> 38 * default serial version UID 39 * </p> 40 */ 41 private static final long serialVersionUID = 1L; 42 42 43 44 45 46 47 48 43 /** 44 * <p> 45 * the children of this task instance which are task instances, as well 46 * </p> 47 */ 48 private List<ITaskInstance> children; 49 49 50 /** 51 * <p> 52 * initializes this instance with the respective task model 53 * </p> 54 * 55 * @param task the task of which this is an instance 56 */ 57 SequenceInstance(ISequence task) { 58 super(task); 59 } 50 /** 51 * <p> 52 * initializes this instance with the respective task model 53 * </p> 54 * 55 * @param task 56 * the task of which this is an instance 57 */ 58 SequenceInstance(ISequence task) { 59 super(task); 60 } 60 61 61 /* (non-Javadoc) 62 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance#getChildren() 63 */ 64 public synchronized List<ITaskInstance> getChildren() { 65 if (children == null) { 66 children = new LinkedList<ITaskInstance>(); 67 } 62 /** 63 * <p> 64 * used to add a child to this task instance at a specific position 65 * </p> 66 * 67 * @param index 68 * the position of the new child in the list of children 69 * @param child 70 * the new child of this instance 71 */ 72 synchronized void addChild(int index, ITaskInstance child) { 73 if (children == null) { 74 children = new LinkedList<ITaskInstance>(); 75 } 68 76 69 return Collections.unmodifiableList(children);70 77 children.add(index, child); 78 } 71 79 72 /* (non-Javadoc) 73 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#get(int) 74 */ 75 @Override 76 public ITaskInstance get(int index) { 77 if (children == null) { 78 throw new IndexOutOfBoundsException(Integer.toString(index)); 79 } 80 else{81 return children.get(index); 82 } 83 80 /** 81 * <p> 82 * used to add a child to this task instance 83 * </p> 84 * 85 * @param child 86 * the new child of this instance 87 */ 88 synchronized void addChild(ITaskInstance child) { 89 if (children == null) { 90 children = new LinkedList<ITaskInstance>(); 91 } 84 92 85 /* (non-Javadoc) 86 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#size() 87 */ 88 @Override 89 public int size() { 90 if (children == null) { 91 return 0; 92 } 93 else { 94 return children.size(); 95 } 96 } 93 children.add(child); 94 } 97 95 98 /* (non-Javadoc) 99 * @see java.lang.Iterable#iterator() 100 */ 101 @Override 102 public Iterator<ITaskInstance> iterator() { 103 return getChildren().iterator(); 104 } 96 /* 97 * (non-Javadoc) 98 * 99 * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.ISequenceInstance#clone() 100 */ 101 @Override 102 public synchronized ISequenceInstance clone() { 103 final SequenceInstance clone = (SequenceInstance) super.clone(); 105 104 106 /* (non-Javadoc) 107 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance#getSequence() 108 */ 109 @Override 110 public ISequence getSequence() { 111 return (ISequence) super.getTask(); 112 } 105 if (children != null) { 106 clone.children = new LinkedList<ITaskInstance>(); 113 107 114 /* (non-Javadoc) 115 * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.ISequenceInstance#clone() 116 */ 117 @Override 118 public synchronized ISequenceInstance clone() { 119 SequenceInstance clone = (SequenceInstance) super.clone(); 108 for (final ITaskInstance child : children) { 109 clone.children.add(child.clone()); 110 } 111 } 120 112 121 if (children != null) { 122 clone.children = new LinkedList<ITaskInstance>(); 113 return clone; 114 } 123 115 124 for (ITaskInstance child : children) { 125 clone.children.add(child.clone()); 126 } 127 } 116 /* 117 * (non-Javadoc) 118 * 119 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#get(int) 120 */ 121 @Override 122 public ITaskInstance get(int index) { 123 if (children == null) { 124 throw new IndexOutOfBoundsException(Integer.toString(index)); 125 } else { 126 return children.get(index); 127 } 128 } 128 129 129 return clone; 130 } 130 /* 131 * (non-Javadoc) 132 * 133 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance#getChildren() 134 */ 135 public synchronized List<ITaskInstance> getChildren() { 136 if (children == null) { 137 children = new LinkedList<ITaskInstance>(); 138 } 131 139 132 /** 133 * <p> 134 * used to add a child to this task instance 135 * </p> 136 * 137 * @param child the new child of this instance 138 */ 139 synchronized void addChild(ITaskInstance child) { 140 if (children == null) { 141 children = new LinkedList<ITaskInstance>(); 142 } 140 return Collections.unmodifiableList(children); 141 } 143 142 144 children.add(child); 145 } 143 /* 144 * (non-Javadoc) 145 * 146 * @see 147 * de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance#getSequence() 148 */ 149 @Override 150 public ISequence getSequence() { 151 return (ISequence) super.getTask(); 152 } 146 153 147 /** 148 * <p> 149 * used to add a child to this task instance at a specific position 150 * </p> 151 * 152 * @param index the position of the new child in the list of children 153 * @param child the new child of this instance 154 */ 155 synchronized void addChild(int index, ITaskInstance child) { 156 if (children == null) { 157 children = new LinkedList<ITaskInstance>(); 158 } 154 /* 155 * (non-Javadoc) 156 * 157 * @see java.lang.Iterable#iterator() 158 */ 159 @Override 160 public Iterator<ITaskInstance> iterator() { 161 return getChildren().iterator(); 162 } 159 163 160 children.add(index, child); 161 } 164 /** 165 * <p> 166 * removes a child from this task instance at a specific position 167 * </p> 168 * 169 * @param index 170 * the position of the child to be removed 171 * 172 * @return the child removed from the children of this instance 173 */ 174 synchronized ITaskInstance removeChild(int index) { 175 if (children != null) { 176 return children.remove(index); 177 } else { 178 throw new IllegalArgumentException( 179 "this task instance does not have children that can be removed"); 180 } 181 } 162 182 163 /** 164 * <p> 165 * removes a child from this task instance at a specific position 166 * </p> 167 * 168 * @param index the position of the child to be removed 169 * 170 * @return the child removed from the children of this instance 171 */ 172 synchronized ITaskInstance removeChild(int index) { 173 if (children != null) { 174 return children.remove(index); 175 } 176 else { 177 throw new IllegalArgumentException 178 ("this task instance does not have children that can be removed"); 179 } 180 } 183 /* 184 * (non-Javadoc) 185 * 186 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#size() 187 */ 188 @Override 189 public int size() { 190 if (children == null) { 191 return 0; 192 } else { 193 return children.size(); 194 } 195 } 181 196 182 197 }
Note: See TracChangeset
for help on using the changeset viewer.