Changeset 1400 for trunk/autoquest-core-tasktrees
- Timestamp:
- 02/26/14 17:11:14 (11 years ago)
- Location:
- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeifc/ITask.java
r1357 r1400 71 71 /** 72 72 * <p> 73 * returns a collection of collections of all different execution variants of this task. This 74 * is a grouping of all instances where each group contains structurally identical instances. 75 * </p> 76 * 77 * @return as described 78 */ 79 public Collection<Collection<ITaskInstance>> getExecutionVariants(); 80 81 /** 82 * <p> 73 83 * checks whether this task is equal to another one. Task equality is only given, if two 74 84 * tasks have the same id. This means, that this method must only return true if the other -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/Task.java
r1357 r1400 18 18 import java.util.Collections; 19 19 import java.util.HashSet; 20 20 import java.util.LinkedList; 21 22 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; 23 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; 24 import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance; 25 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; 26 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance; 21 27 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 22 28 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 29 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; 23 30 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskVisitor; 24 31 … … 31 38 * @author Patrick Harms 32 39 */ 33 class Task implements ITask {40 abstract class Task implements ITask { 34 41 35 42 /** … … 75 82 */ 76 83 private Collection<ITaskInstance> instances = new HashSet<ITaskInstance>(); 84 85 /** 86 * <p> 87 * the execution variants of this task 88 * </p> 89 */ 90 private Collection<Collection<ITaskInstance>> executionVariants; 77 91 78 92 /** … … 141 155 public Collection<ITaskInstance> getInstances() { 142 156 return Collections.unmodifiableCollection(instances); 157 } 158 159 /* (non-Javadoc) 160 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#getExecutionVariants() 161 */ 162 @Override 163 public synchronized Collection<Collection<ITaskInstance>> getExecutionVariants() { 164 if (executionVariants == null) { 165 executionVariants = new LinkedList<Collection<ITaskInstance>>(); 166 determineExecutionVariants(executionVariants); 167 } 168 169 return executionVariants; 143 170 } 144 171 … … 215 242 * @param instance the instance to be removed from this task 216 243 */ 217 void removeInstance(ITaskInstance instance) {244 synchronized void removeInstance(ITaskInstance instance) { 218 245 this.instances.remove(instance); 246 this.executionVariants = null; 219 247 } 220 248 … … 226 254 * @param instance the instance belonging to this task 227 255 */ 228 void addInstance(ITaskInstance instance) {256 synchronized void addInstance(ITaskInstance instance) { 229 257 this.instances.add(instance); 258 this.executionVariants = null; 230 259 } 231 260 … … 238 267 } 239 268 269 /** 270 * 271 */ 272 private void determineExecutionVariants(Collection<Collection<ITaskInstance>> executionVariants) 273 { 274 for (ITaskInstance instance : instances) { 275 boolean added = false; 276 for (Collection<ITaskInstance> variant : executionVariants) { 277 if (!variant.isEmpty() && (isSameExecution(variant.iterator().next(), instance))) { 278 variant.add(instance); 279 added = true; 280 } 281 } 282 283 if (!added) { 284 Collection<ITaskInstance> variant = new HashSet<ITaskInstance>(); 285 variant.add(instance); 286 executionVariants.add(variant); 287 } 288 } 289 } 290 291 /** 292 * 293 */ 294 private boolean isSameExecution(ITaskInstance instance1, ITaskInstance instance2) { 295 if (instance1 instanceof IIterationInstance) { 296 if (!(instance2 instanceof IIterationInstance)) { 297 return false; 298 } 299 300 ITaskInstanceList iteration1 = (ITaskInstanceList) instance1; 301 ITaskInstanceList iteration2 = (ITaskInstanceList) instance2; 302 303 return isSameExecutionList(iteration1, iteration2); 304 } 305 else if (instance1 instanceof ISequenceInstance) { 306 if (!(instance2 instanceof ISequenceInstance)) { 307 return false; 308 } 309 310 ITaskInstanceList selection1 = (ITaskInstanceList) instance1; 311 ITaskInstanceList selection2 = (ITaskInstanceList) instance2; 312 313 return isSameExecutionList(selection1, selection2); 314 } 315 else if (instance1 instanceof ISelectionInstance) { 316 if (!(instance2 instanceof ISelectionInstance)) { 317 return false; 318 } 319 else { 320 return isSameExecution(((ISelectionInstance) instance1).getChild(), 321 ((ISelectionInstance) instance2).getChild()); 322 } 323 } 324 else if (instance1 instanceof IOptionalInstance) { 325 if (!(instance2 instanceof IOptionalInstance)) { 326 return false; 327 } 328 else { 329 return isSameExecution(((IOptionalInstance) instance1).getChild(), 330 ((IOptionalInstance) instance2).getChild()); 331 } 332 } 333 else if (instance1 instanceof IEventTaskInstance) { 334 if (!(instance2 instanceof IEventTaskInstance)) { 335 return false; 336 } 337 else { 338 return ((IEventTaskInstance) instance1).getTask().equals 339 (((IEventTaskInstance) instance2).getTask()); 340 } 341 } 342 else if (instance1 == null) { 343 return instance2 == null; 344 } 345 else { 346 throw new IllegalArgumentException("unknown type of task instance: " + instance1); 347 } 348 } 349 350 /** 351 * 352 */ 353 private boolean isSameExecutionList(ITaskInstanceList list1, ITaskInstanceList list2) { 354 if (list1.size() == list2.size()) { 355 for (int i = 0; i < list1.size(); i++) { 356 if (!isSameExecution(list1.get(i), list2.get(i))) { 357 return false; 358 } 359 } 360 361 return true; 362 } 363 else { 364 return false; 365 } 366 } 240 367 }
Note: See TracChangeset
for help on using the changeset viewer.