Changeset 1146 for trunk/autoquest-core-tasktrees/src/main/java
- Timestamp:
- 04/04/13 16:06:07 (12 years ago)
- Location:
- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees
- Files:
-
- 13 added
- 16 deleted
- 18 edited
- 12 copied
- 10 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/manager/ComponentManager.java
r1113 r1146 15 15 package de.ugoe.cs.autoquest.tasktrees.manager; 16 16 17 import de.ugoe.cs.autoquest.tasktrees. nodeequality.NodeEqualityRuleManager;17 import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEqualityRuleManager; 18 18 import de.ugoe.cs.autoquest.tasktrees.temporalrelation.TemporalRelationshipRuleManager; 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask TreeBuilder;20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask TreeNodeFactory;21 import de.ugoe.cs.autoquest.tasktrees.treeimpl.Task TreeBuilder;22 import de.ugoe.cs.autoquest.tasktrees.treeimpl.Task TreeNodeFactory;19 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; 21 import de.ugoe.cs.autoquest.tasktrees.treeimpl.TaskBuilder; 22 import de.ugoe.cs.autoquest.tasktrees.treeimpl.TaskFactory; 23 23 24 24 /** … … 37 37 38 38 /** */ 39 private NodeEqualityRuleManager nodeEqualityRuleManager;39 private TaskEqualityRuleManager taskEqualityRuleManager; 40 40 41 41 /** */ 42 private ITask TreeBuilder taskTreeBuilder;42 private ITaskBuilder taskBuilder; 43 43 44 44 /** */ 45 private ITask TreeNodeFactory taskTreeNodeFactory;45 private ITaskFactory taskFactory; 46 46 47 47 /** … … 55 55 * 56 56 */ 57 public static NodeEqualityRuleManager getNodeEqualityRuleManager() {58 return getInstance(). nodeEqualityRuleManager;57 public static TaskEqualityRuleManager getTaskEqualityRuleManager() { 58 return getInstance().taskEqualityRuleManager; 59 59 } 60 60 … … 62 62 * 63 63 */ 64 public static ITask TreeBuilder getDefaultTaskTreeBuilder() {65 return getInstance().task TreeBuilder;64 public static ITaskBuilder getDefaultTaskBuilder() { 65 return getInstance().taskBuilder; 66 66 } 67 67 … … 69 69 * 70 70 */ 71 public static ITask TreeNodeFactory getDefaultTaskTreeNodeFactory() {72 return getInstance().task TreeNodeFactory;71 public static ITaskFactory getDefaultTaskFactory() { 72 return getInstance().taskFactory; 73 73 } 74 74 … … 95 95 */ 96 96 private void init() { 97 nodeEqualityRuleManager = new NodeEqualityRuleManager();98 nodeEqualityRuleManager.init();97 taskEqualityRuleManager = new TaskEqualityRuleManager(); 98 taskEqualityRuleManager.init(); 99 99 100 task TreeBuilder = new TaskTreeBuilder();101 task TreeNodeFactory = new TaskTreeNodeFactory();100 taskBuilder = new TaskBuilder(); 101 taskFactory = new TaskFactory(); 102 102 103 103 temporalRelationshipRuleManager = new TemporalRelationshipRuleManager 104 ( nodeEqualityRuleManager, taskTreeNodeFactory, taskTreeBuilder);104 (taskEqualityRuleManager, taskFactory, taskBuilder); 105 105 temporalRelationshipRuleManager.init(); 106 106 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/manager/TaskTreeManager.java
r1113 r1146 21 21 22 22 import de.ugoe.cs.autoquest.eventcore.Event; 23 import de.ugoe.cs.autoquest.tasktrees.treeifc.I EventTask;24 import de.ugoe.cs.autoquest.tasktrees.treeifc.I Sequence;25 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask Tree;26 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask TreeBuilder;27 import de.ugoe.cs.autoquest.tasktrees.treeifc.I TaskTreeNodeFactory;23 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 24 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; 25 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; 26 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; 27 import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 28 28 import de.ugoe.cs.util.console.Console; 29 29 … … 37 37 38 38 /** */ 39 private ITask TreeBuilder taskTreeBuilder = ComponentManager.getDefaultTaskTreeBuilder();39 private ITaskBuilder taskBuilder = ComponentManager.getDefaultTaskBuilder(); 40 40 41 41 /** */ 42 private ITaskTreeNodeFactory taskTreeNodeFactory = 43 ComponentManager.getDefaultTaskTreeNodeFactory(); 42 private ITaskFactory taskFactory = ComponentManager.getDefaultTaskFactory(); 44 43 45 44 /** */ 46 private List< List<IEventTask>> sessions = null;45 private List<IUserSession> sessions = null; 47 46 48 47 /** */ 49 private List<IEventTask>currentSession = null;48 private IUserSession currentSession = null; 50 49 51 50 /** … … 53 52 */ 54 53 public TaskTreeManager() { 55 sessions = new LinkedList< List<IEventTask>>();54 sessions = new LinkedList<IUserSession>(); 56 55 } 57 56 … … 59 58 * 60 59 */ 61 public synchronized ITask Tree createTaskTree(Collection<List<Event>> newSessions) {60 public synchronized ITaskModel createTaskModel(Collection<List<Event>> newSessions) { 62 61 if ((currentSession != null) || (sessions.size() > 0)) { 63 62 throw new IllegalStateException("do not mix calls to this method with calls to the " + … … 75 74 } 76 75 77 return getTask Tree();76 return getTaskModel(); 78 77 } 79 78 … … 83 82 public void handleNewEvent(Event event) { 84 83 assertSessionSequence(); 85 currentSession.add86 (taskTreeNodeFactory.createNewEventTask(event.getType(), event.getTarget()));84 ITask eventTask = taskFactory.createNewEventTask(event.getType(), event.getTarget()); 85 taskBuilder.addExecutedTask(currentSession, taskFactory.createNewTaskInstance(eventTask)); 87 86 } 88 87 … … 91 90 */ 92 91 public void finishSession() { 93 if ((currentSession != null) && (currentSession. size() > 0)) {92 if ((currentSession != null) && (currentSession.getExecutedTasks().size() > 0)) { 94 93 sessions.add(currentSession); 95 94 currentSession = null; … … 100 99 * 101 100 */ 102 public synchronized ITask Tree getTaskTree() {101 public synchronized ITaskModel getTaskModel() { 103 102 finishSession(); 104 103 105 104 Console.traceln(Level.INFO, "applying temporal relationship generation rules"); 106 105 107 ISequence rootSequence = taskTreeNodeFactory.createNewSequence(); 108 taskTreeBuilder.setDescription(rootSequence, "root"); 109 110 for (List<IEventTask> session : sessions) { 111 ISequence sequence = taskTreeNodeFactory.createNewSequence(); 112 taskTreeBuilder.setDescription(sequence, "session"); 113 114 for (IEventTask eventTask : session) { 115 taskTreeBuilder.addChild(sequence, eventTask); 116 } 117 118 taskTreeBuilder.addChild(rootSequence, sequence); 119 } 120 121 122 ComponentManager.getTemporalRelationshipRuleManager().applyRules(rootSequence); 106 ComponentManager.getTemporalRelationshipRuleManager().applyRules(sessions); 123 107 124 return task TreeNodeFactory.createTaskTree(rootSequence);108 return taskFactory.createTaskModel(sessions); 125 109 } 126 110 … … 130 114 private void assertSessionSequence() { 131 115 if (currentSession == null) { 132 currentSession = new LinkedList<IEventTask>();116 currentSession = taskFactory.createUserSession(); 133 117 } 134 118 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/EventTaskComparisonRule.java
r1125 r1146 13 13 // limitations under the License. 14 14 15 package de.ugoe.cs.autoquest.tasktrees. nodeequality;15 package de.ugoe.cs.autoquest.tasktrees.taskequality; 16 16 17 17 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 18 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask TreeNode;18 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 19 19 20 20 /** 21 21 * <p> 22 * This rule identifies two task tree nodes as lexically equal, if they are both event tasks and22 * This rule identifies two tasks as lexically equal, if they are both event tasks and 23 23 * if their respective event types and targets equal. 24 24 * </p> … … 26 26 * @author Patrick Harms 27 27 */ 28 public class EventTaskComparisonRule implements NodeComparisonRule {28 public class EventTaskComparisonRule implements TaskComparisonRule { 29 29 30 30 /* (non-Javadoc) 31 * @see NodeComparisonRule#isApplicable(ITask TreeNode, ITaskTreeNode)31 * @see NodeComparisonRule#isApplicable(ITask, ITask) 32 32 */ 33 33 @Override 34 public boolean isApplicable(ITask TreeNode node1, ITaskTreeNode node2) {35 return ( node1 instanceof IEventTask) && (node2 instanceof IEventTask);34 public boolean isApplicable(ITask task1, ITask task2) { 35 return (task1 instanceof IEventTask) && (task2 instanceof IEventTask); 36 36 } 37 37 38 38 /* (non-Javadoc) 39 * @see NodeComparisonRule#areLexicallyEqual(ITask TreeNode, ITaskTreeNode)39 * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask) 40 40 */ 41 41 @Override 42 public boolean areLexicallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {43 IEventTask task1 = (IEventTask) node1;44 IEventTask task2 = (IEventTask) node2;42 public boolean areLexicallyEqual(ITask task1, ITask task2) { 43 IEventTask eventTask1 = (IEventTask) task1; 44 IEventTask eventTask2 = (IEventTask) task2; 45 45 46 return ( task1.getEventType().equals(task2.getEventType()) &&47 task1.getEventTarget().equals(task2.getEventTarget()));46 return (eventTask1.getEventType().equals(eventTask2.getEventType()) && 47 eventTask1.getEventTarget().equals(eventTask2.getEventTarget())); 48 48 } 49 49 50 50 /* (non-Javadoc) 51 * @see NodeComparisonRule#areSyntacticallyEqual(ITask TreeNode, ITaskTreeNode)51 * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask) 52 52 */ 53 53 @Override 54 public boolean areSyntacticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {55 return areLexicallyEqual( node1, node2);54 public boolean areSyntacticallyEqual(ITask task1, ITask task2) { 55 return areLexicallyEqual(task1, task2); 56 56 } 57 57 58 58 /* (non-Javadoc) 59 * @see NodeComparisonRule#areSemanticallyEqual(ITask TreeNode, ITaskTreeNode)59 * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) 60 60 */ 61 61 @Override 62 public boolean areSemanticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {63 return areLexicallyEqual( node1, node2);62 public boolean areSemanticallyEqual(ITask task1, ITask task2) { 63 return areLexicallyEqual(task1, task2); 64 64 } 65 65 66 66 @Override 67 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) {68 if (areLexicallyEqual( node1, node2)) {69 return NodeEquality.LEXICALLY_EQUAL;67 public TaskEquality compare(ITask task1, ITask task2) { 68 if (areLexicallyEqual(task1, task2)) { 69 return TaskEquality.LEXICALLY_EQUAL; 70 70 } 71 71 else { 72 return NodeEquality.UNEQUAL;72 return TaskEquality.UNEQUAL; 73 73 } 74 74 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/GUIEventTaskComparisonRule.java
r1125 r1146 13 13 // limitations under the License. 14 14 15 package de.ugoe.cs.autoquest.tasktrees. nodeequality;15 package de.ugoe.cs.autoquest.tasktrees.taskequality; 16 16 17 17 import de.ugoe.cs.autoquest.eventcore.IEventTarget; … … 42 42 import de.ugoe.cs.autoquest.eventcore.guimodel.IToolTip; 43 43 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 44 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask TreeNode;44 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 45 45 46 46 /** … … 58 58 * @author Patrick Harms 59 59 */ 60 public class GUIEventTaskComparisonRule implements NodeComparisonRule {60 public class GUIEventTaskComparisonRule implements TaskComparisonRule { 61 61 62 62 /* (non-Javadoc) 63 * @see NodeComparisonRule#isApplicable(ITask TreeNode, ITaskTreeNode)63 * @see NodeComparisonRule#isApplicable(ITask, ITask) 64 64 */ 65 65 @Override 66 public boolean isApplicable(ITask TreeNode node1, ITaskTreeNode node2) {66 public boolean isApplicable(ITask task1, ITask task2) { 67 67 return 68 (( node1 instanceof IEventTask) && (node2 instanceof IEventTask) &&69 (((IEventTask) node1).getEventType() instanceof IInteraction) &&70 (((IEventTask) node2).getEventType() instanceof IInteraction));68 ((task1 instanceof IEventTask) && (task2 instanceof IEventTask) && 69 (((IEventTask) task1).getEventType() instanceof IInteraction) && 70 (((IEventTask) task2).getEventType() instanceof IInteraction)); 71 71 } 72 72 73 73 /* (non-Javadoc) 74 * @see NodeComparisonRule#areLexicallyEqual(ITask TreeNode, ITaskTreeNode)74 * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask) 75 75 */ 76 76 @Override 77 public boolean areLexicallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {78 NodeEquality equality = getEquality(node1, node2, NodeEquality.LEXICALLY_EQUAL);79 return (equality != null) && (equality.isAtLeast( NodeEquality.LEXICALLY_EQUAL));77 public boolean areLexicallyEqual(ITask task1, ITask task2) { 78 TaskEquality equality = getEquality(task1, task2, TaskEquality.LEXICALLY_EQUAL); 79 return (equality != null) && (equality.isAtLeast(TaskEquality.LEXICALLY_EQUAL)); 80 80 } 81 81 82 82 /* (non-Javadoc) 83 * @see NodeComparisonRule#areSyntacticallyEqual(ITask TreeNode, ITaskTreeNode)83 * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask) 84 84 */ 85 85 @Override 86 public boolean areSyntacticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {87 NodeEquality equality = getEquality(node1, node2, NodeEquality.SYNTACTICALLY_EQUAL);88 return (equality != null) && (equality.isAtLeast( NodeEquality.SYNTACTICALLY_EQUAL));86 public boolean areSyntacticallyEqual(ITask task1, ITask task2) { 87 TaskEquality equality = getEquality(task1, task2, TaskEquality.SYNTACTICALLY_EQUAL); 88 return (equality != null) && (equality.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)); 89 89 } 90 90 91 91 /* (non-Javadoc) 92 * @see NodeComparisonRule#areSemanticallyEqual(ITask TreeNode, ITaskTreeNode)92 * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) 93 93 */ 94 94 @Override 95 public boolean areSemanticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {96 NodeEquality equality = getEquality(node1, node2, NodeEquality.SEMANTICALLY_EQUAL);97 return (equality != null) && (equality.isAtLeast( NodeEquality.SEMANTICALLY_EQUAL));95 public boolean areSemanticallyEqual(ITask task1, ITask task2) { 96 TaskEquality equality = getEquality(task1, task2, TaskEquality.SEMANTICALLY_EQUAL); 97 return (equality != null) && (equality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL)); 98 98 } 99 99 100 100 /* (non-Javadoc) 101 * @see NodeComparisonRule#compare(ITask TreeNode, ITaskTreeNode)101 * @see NodeComparisonRule#compare(ITask, ITask) 102 102 */ 103 103 @Override 104 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 105 return getEquality(node1, node2, null); 106 } 107 108 /** 109 * 110 */ 111 private NodeEquality getEquality(ITaskTreeNode node1, 112 ITaskTreeNode node2, 113 NodeEquality requiredEqualityLevel) 114 { 115 IEventTask task1 = (IEventTask) node1; 116 IEventTask task2 = (IEventTask) node2; 117 118 if (!task1.getEventTarget().equals(task2.getEventTarget())) { 119 return NodeEquality.UNEQUAL; 120 } 121 122 IInteraction interaction1 = (IInteraction) task1.getEventType(); 123 IInteraction interaction2 = (IInteraction) task2.getEventType(); 104 public TaskEquality compare(ITask task1, ITask task2) { 105 return getEquality(task1, task2, null); 106 } 107 108 /** 109 * 110 */ 111 private TaskEquality getEquality(ITask task1, ITask task2, TaskEquality requiredEqualityLevel) { 112 IEventTask eventTask1 = (IEventTask) task1; 113 IEventTask eventTask2 = (IEventTask) task2; 114 115 if (!eventTask1.getEventTarget().equals(eventTask2.getEventTarget())) { 116 return TaskEquality.UNEQUAL; 117 } 118 119 IInteraction interaction1 = (IInteraction) eventTask1.getEventType(); 120 IInteraction interaction2 = (IInteraction) eventTask2.getEventType(); 124 121 125 122 return compareInteractions 126 (interaction1, interaction2, task1.getEventTarget(), requiredEqualityLevel);123 (interaction1, interaction2, eventTask1.getEventTarget(), requiredEqualityLevel); 127 124 } 128 125 … … 145 142 * @return as described 146 143 */ 147 private NodeEquality compareInteractions(IInteraction interaction1,144 private TaskEquality compareInteractions(IInteraction interaction1, 148 145 IInteraction interaction2, 149 146 IEventTarget eventTarget, 150 NodeEquality equalityLevel)151 { 152 NodeEquality level = equalityLevel;147 TaskEquality equalityLevel) 148 { 149 TaskEquality level = equalityLevel; 153 150 154 151 if (level == null) { 155 level = NodeEquality.LEXICALLY_EQUAL;152 level = TaskEquality.LEXICALLY_EQUAL; 156 153 } 157 154 158 155 if (interaction1 == interaction2) { 159 return NodeEquality.LEXICALLY_EQUAL;156 return TaskEquality.LEXICALLY_EQUAL; 160 157 } 161 158 else if ((interaction1 instanceof KeyInteraction) && … … 186 183 } 187 184 else if (interaction1.equals(interaction2)) { 188 return NodeEquality.LEXICALLY_EQUAL;185 return TaskEquality.LEXICALLY_EQUAL; 189 186 } 190 187 else { 191 return NodeEquality.UNEQUAL;188 return TaskEquality.UNEQUAL; 192 189 } 193 190 } … … 204 201 * @return 205 202 */ 206 private NodeEquality compareKeyInteractions(KeyInteraction interaction1,203 private TaskEquality compareKeyInteractions(KeyInteraction interaction1, 207 204 KeyInteraction interaction2, 208 NodeEquality equalityLevel)205 TaskEquality equalityLevel) 209 206 { 210 207 if (((interaction1 instanceof KeyPressed) && (interaction2 instanceof KeyPressed)) || … … 212 209 ((interaction1 instanceof KeyTyped) && (interaction2 instanceof KeyTyped))) 213 210 { 214 if ((equalityLevel.isAtLeast( NodeEquality.SYNTACTICALLY_EQUAL)) &&211 if ((equalityLevel.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)) && 215 212 (interaction1.getKey() == interaction2.getKey())) 216 213 { 217 return NodeEquality.LEXICALLY_EQUAL;214 return TaskEquality.LEXICALLY_EQUAL; 218 215 } 219 216 else { 220 return NodeEquality.SEMANTICALLY_EQUAL;221 } 222 } 223 224 return NodeEquality.UNEQUAL;217 return TaskEquality.SEMANTICALLY_EQUAL; 218 } 219 } 220 221 return TaskEquality.UNEQUAL; 225 222 } 226 223 … … 236 233 * @return as described 237 234 */ 238 private NodeEquality compareMouseDragAndDrops(MouseDragAndDrop interaction1,235 private TaskEquality compareMouseDragAndDrops(MouseDragAndDrop interaction1, 239 236 MouseDragAndDrop interaction2, 240 NodeEquality equalityLevel)237 TaskEquality equalityLevel) 241 238 { 242 239 if (interaction1.getButton() != interaction2.getButton()) { 243 return NodeEquality.UNEQUAL;244 } 245 246 if (equalityLevel.isAtLeast( NodeEquality.SYNTACTICALLY_EQUAL)) {240 return TaskEquality.UNEQUAL; 241 } 242 243 if (equalityLevel.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)) { 247 244 int x1 = interaction1.getX(); 248 245 int x1Start = interaction1.getXStart(); … … 255 252 256 253 if ((x1Start == x2Start) && (x1 == x2) && (y1Start == y2Start) && (y1 == y2)) { 257 return NodeEquality.LEXICALLY_EQUAL;258 } 259 } 260 261 return NodeEquality.SEMANTICALLY_EQUAL;254 return TaskEquality.LEXICALLY_EQUAL; 255 } 256 } 257 258 return TaskEquality.SEMANTICALLY_EQUAL; 262 259 } 263 260 … … 279 276 * @return as described 280 277 */ 281 private NodeEquality compareMouseButtonInteractions(MouseButtonInteraction interaction1,278 private TaskEquality compareMouseButtonInteractions(MouseButtonInteraction interaction1, 282 279 MouseButtonInteraction interaction2, 283 280 IEventTarget eventTarget, 284 NodeEquality equalityLevel)281 TaskEquality equalityLevel) 285 282 { 286 283 boolean coordinatesMatch = true; … … 293 290 } 294 291 else if (interaction1.getButton() != interaction2.getButton()) { 295 return NodeEquality.UNEQUAL;296 } 297 else if (equalityLevel.isAtLeast( NodeEquality.SYNTACTICALLY_EQUAL) &&292 return TaskEquality.UNEQUAL; 293 } 294 else if (equalityLevel.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL) && 298 295 clickCoordinatesMakeLexicalDifference(eventTarget)) 299 296 { … … 319 316 { 320 317 if (coordinatesMatch) { 321 return NodeEquality.LEXICALLY_EQUAL;318 return TaskEquality.LEXICALLY_EQUAL; 322 319 } 323 320 else { 324 return NodeEquality.SEMANTICALLY_EQUAL;325 } 326 } 327 328 return NodeEquality.UNEQUAL;321 return TaskEquality.SEMANTICALLY_EQUAL; 322 } 323 } 324 325 return TaskEquality.UNEQUAL; 329 326 } 330 327 … … 346 343 * @return as described 347 344 */ 348 private NodeEquality compareScrolls(Scroll interaction1,345 private TaskEquality compareScrolls(Scroll interaction1, 349 346 Scroll interaction2, 350 NodeEquality equalityLevel)351 { 352 if (equalityLevel.isAtLeast( NodeEquality.SYNTACTICALLY_EQUAL)) {347 TaskEquality equalityLevel) 348 { 349 if (equalityLevel.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)) { 353 350 int x1 = interaction1.getXPosition(); 354 351 int x2 = interaction2.getXPosition(); … … 357 354 358 355 if ((x1 == x2) && (y1 == y2)) { 359 return NodeEquality.LEXICALLY_EQUAL;360 } 361 } 362 363 return NodeEquality.SEMANTICALLY_EQUAL;356 return TaskEquality.LEXICALLY_EQUAL; 357 } 358 } 359 360 return TaskEquality.SEMANTICALLY_EQUAL; 364 361 } 365 362 … … 377 374 * @return as described 378 375 */ 379 private NodeEquality compareTextInputs(TextInput interaction1,376 private TaskEquality compareTextInputs(TextInput interaction1, 380 377 TextInput interaction2, 381 NodeEquality equalityLevel)378 TaskEquality equalityLevel) 382 379 { 383 380 switch (equalityLevel) { 384 381 case LEXICALLY_EQUAL: 385 382 if (interaction1.getTextInputEvents().equals(interaction2.getTextInputEvents())) { 386 return NodeEquality.LEXICALLY_EQUAL;383 return TaskEquality.LEXICALLY_EQUAL; 387 384 } 388 385 // fall through 389 386 case SYNTACTICALLY_EQUAL: 390 387 if (interaction1.getEnteredText().equals(interaction2.getEnteredText())) { 391 return NodeEquality.SYNTACTICALLY_EQUAL;388 return TaskEquality.SYNTACTICALLY_EQUAL; 392 389 } 393 390 // fall through 394 391 case SEMANTICALLY_EQUAL: 395 return NodeEquality.SEMANTICALLY_EQUAL;392 return TaskEquality.SEMANTICALLY_EQUAL; 396 393 default: 397 return NodeEquality.UNEQUAL;394 return TaskEquality.UNEQUAL; 398 395 } 399 396 } … … 411 408 * @return as described 412 409 */ 413 private NodeEquality compareValueSelections(ValueSelection<?> interaction1,410 private TaskEquality compareValueSelections(ValueSelection<?> interaction1, 414 411 ValueSelection<?> interaction2, 415 NodeEquality equalityLevel)416 { 417 if (equalityLevel.isAtLeast( NodeEquality.SYNTACTICALLY_EQUAL)) {412 TaskEquality equalityLevel) 413 { 414 if (equalityLevel.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)) { 418 415 Object value1 = interaction1.getSelectedValue(); 419 416 Object value2 = interaction2.getSelectedValue(); 420 417 421 418 if ((value1 == value2) || ((value1 != null) && (value1.equals(value2)))) { 422 return NodeEquality.LEXICALLY_EQUAL;423 } 424 } 425 426 return NodeEquality.SEMANTICALLY_EQUAL;419 return TaskEquality.LEXICALLY_EQUAL; 420 } 421 } 422 423 return TaskEquality.SEMANTICALLY_EQUAL; 427 424 } 428 425 -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/IterationComparisonRule.java
r1125 r1146 13 13 // limitations under the License. 14 14 15 package de.ugoe.cs.autoquest.tasktrees.nodeequality; 16 17 import java.util.List; 15 package de.ugoe.cs.autoquest.tasktrees.taskequality; 18 16 19 17 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; … … 21 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 22 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 23 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask TreeNode;21 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 24 22 25 23 /** … … 81 79 * @author 2012, last modified by $Author: patrick$ 82 80 */ 83 public class IterationComparisonRule implements NodeComparisonRule {81 public class IterationComparisonRule implements TaskComparisonRule { 84 82 85 /** the rule manager for internally comparing task tree nodes */86 private NodeEqualityRuleManager mRuleManager;83 /** the rule manager for internally comparing tasks */ 84 private TaskEqualityRuleManager mRuleManager; 87 85 88 86 /** 89 87 * <p> 90 * simple constructor to provide the rule with the nodeequality rule manager to be able91 * to perform comparisons of the children of provided task tree nodes88 * simple constructor to provide the rule with the task equality rule manager to be able 89 * to perform comparisons of the children of provided tasks 92 90 * </p> 93 91 * 94 * @param ruleManager the rule manager for comparing task tree nodes95 */ 96 IterationComparisonRule( NodeEqualityRuleManager ruleManager) {92 * @param ruleManager the rule manager for comparing tasks 93 */ 94 IterationComparisonRule(TaskEqualityRuleManager ruleManager) { 97 95 super(); 98 96 mRuleManager = ruleManager; … … 100 98 101 99 /* (non-Javadoc) 102 * @see NodeComparisonRule#isApplicable(ITask TreeNode, ITaskTreeNode)103 */ 104 @Override 105 public boolean isApplicable(ITask TreeNode node1, ITaskTreeNode node2) {106 return ( node1 instanceof IIteration) && (node2 instanceof IIteration);107 } 108 109 /* (non-Javadoc) 110 * @see NodeComparisonRule#areLexicallyEqual(ITask TreeNode, ITaskTreeNode)111 */ 112 @Override 113 public boolean areLexicallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {114 List<ITaskTreeNode> children1 = node1.getChildren();115 List<ITaskTreeNode> children2 = node2.getChildren();116 117 if (child ren1.size() == children2.size()) {118 if (child ren1.size() == 0) {119 return true;100 * @see NodeComparisonRule#isApplicable(ITask, ITask) 101 */ 102 @Override 103 public boolean isApplicable(ITask task1, ITask task2) { 104 return (task1 instanceof IIteration) && (task2 instanceof IIteration); 105 } 106 107 /* (non-Javadoc) 108 * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask) 109 */ 110 @Override 111 public boolean areLexicallyEqual(ITask task1, ITask task2) { 112 ITask child1 = ((IIteration) task1).getMarkedTask(); 113 ITask child2 = ((IIteration) task2).getMarkedTask(); 114 115 if (child1 != null) { 116 if (child2 == null) { 117 return false; 120 118 } 121 119 else { 122 ITaskTreeNode child1 = children1.get(0);123 ITaskTreeNode child2 = children2.get(0);124 125 120 // iterations may have 3 different structures. 126 121 // 1. they have one child, which is the iterated one … … 136 131 { 137 132 return getNodeEquality 138 (child1, child2).isAtLeast( NodeEquality.LEXICALLY_EQUAL);133 (child1, child2).isAtLeast(TaskEquality.LEXICALLY_EQUAL); 139 134 } 140 135 } 141 136 } 137 else if (child2 == null) { 138 return true; 139 } 142 140 143 141 return false; … … 145 143 146 144 /* (non-Javadoc) 147 * @see NodeComparisonRule#areSyntacticallyEqual(ITask TreeNode, ITaskTreeNode)148 */ 149 @Override 150 public boolean areSyntacticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {151 List<ITaskTreeNode> children1 = node1.getChildren();152 List<ITaskTreeNode> children2 = node2.getChildren();153 154 if (child ren1.size() == children2.size()) {155 if (child ren1.size() == 0) {156 return true;145 * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask) 146 */ 147 @Override 148 public boolean areSyntacticallyEqual(ITask task1, ITask task2) { 149 ITask child1 = ((IIteration) task1).getMarkedTask(); 150 ITask child2 = ((IIteration) task2).getMarkedTask(); 151 152 if (child1 != null) { 153 if (child2 == null) { 154 return false; 157 155 } 158 156 else { 159 ITaskTreeNode child1 = children1.get(0);160 ITaskTreeNode child2 = children2.get(0);161 162 157 // iterations may have 3 different structures. 163 158 // 1. they have one child, which is the iterated one … … 167 162 // ignore the type of the children but check them for equality. 168 163 169 return getNodeEquality(child1, child2).isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL); 170 } 164 return getNodeEquality(child1, child2).isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL); 165 } 166 } 167 else if (child2 == null) { 168 return true; 171 169 } 172 170 … … 175 173 176 174 /* (non-Javadoc) 177 * @see NodeComparisonRule#areSemanticallyEqual(ITask TreeNode, ITaskTreeNode)178 */ 179 @Override 180 public boolean areSemanticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {181 return compare( node1, node2).isAtLeast(NodeEquality.SEMANTICALLY_EQUAL);182 } 183 184 /* (non-Javadoc) 185 * @see NodeComparisonRule#compare(ITask TreeNode, ITaskTreeNode)186 */ 187 @Override 188 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) {189 List<ITaskTreeNode> children1 = node1.getChildren();190 List<ITaskTreeNode> children2 = node2.getChildren();175 * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) 176 */ 177 @Override 178 public boolean areSemanticallyEqual(ITask task1, ITask task2) { 179 return compare(task1, task2).isAtLeast(TaskEquality.SEMANTICALLY_EQUAL); 180 } 181 182 /* (non-Javadoc) 183 * @see NodeComparisonRule#compare(ITask, ITask) 184 */ 185 @Override 186 public TaskEquality compare(ITask task1, ITask task2) { 187 ITask child1 = ((IIteration) task1).getMarkedTask(); 188 ITask child2 = ((IIteration) task2).getMarkedTask(); 191 189 192 190 // if both iterations do not have children, they are equal although this doesn't make sense 193 if ((children1.size() == 0) && (children2.size() == 0)) { 194 return NodeEquality.LEXICALLY_EQUAL; 195 } 196 else if ((children1.size() == 0) || (children2.size() == 0)) { 197 return NodeEquality.UNEQUAL; 198 } 199 200 ITaskTreeNode child1 = children1.get(0); 201 ITaskTreeNode child2 = children2.get(0); 191 if ((child1 == null) && (child2 == null)) { 192 return TaskEquality.LEXICALLY_EQUAL; 193 } 194 else if ((child1 == null) || (child2 == null)) { 195 return TaskEquality.UNEQUAL; 196 } 202 197 203 198 // iterations may have 3 different structures. … … 209 204 // the permutations of the three variants in combination must be checked 210 205 211 // check if both nodes are the same variants of iterations and if their children are equal.206 // check if both tasks are the same variants of iterations and if their children are equal. 212 207 // This condition matches, if both iterations are the same variants of iteration. I.e. three 213 208 // combinations of the permutation are handled herewith. 214 NodeEquality nodeEquality = getNodeEquality(child1, child2);215 216 if ( nodeEquality != null) {217 return nodeEquality;218 } 219 220 // compare one iteration with a single nodeas a child and another one with a selection of221 // semantically equal nodes209 TaskEquality taskEquality = getNodeEquality(child1, child2); 210 211 if (taskEquality != null) { 212 return taskEquality; 213 } 214 215 // compare one iteration with a single task as a child and another one with a selection of 216 // semantically equal tasks 222 217 return selectionChildrenSemanticallyEqualNode(child1, child2); 223 218 … … 229 224 * TODO update comment 230 225 */ 231 private NodeEquality getNodeEquality(ITaskTreeNode child1, ITaskTreeNodechild2) {232 NodeEquality nodeEquality = callRuleManager(child1, child2, null);233 234 if ( nodeEquality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)) {226 private TaskEquality getNodeEquality(ITask child1, ITask child2) { 227 TaskEquality taskEquality = callRuleManager(child1, child2, null); 228 229 if (taskEquality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL)) { 235 230 // prevent, that identical is returned, because the iterations itself are not identical 236 231 // although the iterated tasks are 237 if ( nodeEquality == NodeEquality.IDENTICAL) {238 return NodeEquality.LEXICALLY_EQUAL;232 if (taskEquality == TaskEquality.IDENTICAL) { 233 return TaskEquality.LEXICALLY_EQUAL; 239 234 } 240 235 else { 241 return nodeEquality;242 } 243 } 244 245 return NodeEquality.UNEQUAL;236 return taskEquality; 237 } 238 } 239 240 return TaskEquality.UNEQUAL; 246 241 } 247 242 248 243 /** 249 244 * <p> 250 * compares two task tree nodes. One of them must be a selection, the other one can be any task251 * tree node. The method returns a nodeequality that is not <code>NodeEquality.UNEQUAL</code>252 * if the other nodeis at least semantically equal to the children of the selection. It253 * returns more concrete equalities, if the equality between the other nodeand the children245 * compares two tasks. One of them must be a selection, the other one can be any task 246 * tree task. The method returns a task equality that is not <code>NodeEquality.UNEQUAL</code> 247 * if the other task is at least semantically equal to the children of the selection. It 248 * returns more concrete equalities, if the equality between the other task and the children 254 249 * of the selection is more concrete. 255 250 * </p> 256 251 * 257 * @param taskTreeNode the first task t ree node to compare258 * @param taskTreeNode2 the second task t ree node to compare252 * @param taskTreeNode the first task to compare 253 * @param taskTreeNode2 the second task to compare 259 254 * 260 255 * @return as described 261 256 */ 262 private NodeEquality selectionChildrenSemanticallyEqualNode(ITaskTreeNode taskTreeNode, 263 ITaskTreeNode taskTreeNode2) 264 { 257 private TaskEquality selectionChildrenSemanticallyEqualNode(ITask task1, ITask task2) { 265 258 ISelection selection = null; 266 ITask TreeNode node= null;267 if (task TreeNodeinstanceof ISelection) {268 selection = (ISelection) task TreeNode;269 node = taskTreeNode2;270 } 271 else if (task TreeNode2 instanceof ISelection) {272 selection = (ISelection) task TreeNode2;273 node = taskTreeNode;259 ITask task = null; 260 if (task1 instanceof ISelection) { 261 selection = (ISelection) task1; 262 task = task2; 263 } 264 else if (task2 instanceof ISelection) { 265 selection = (ISelection) task2; 266 task = task1; 274 267 } 275 268 else { 276 return NodeEquality.UNEQUAL;269 return TaskEquality.UNEQUAL; 277 270 } 278 271 279 272 // Iterations, where one has a selection and the other one not can at most be syntactically 280 273 // equal but not identical 281 NodeEquality commonDenominatorForAllComparisons = NodeEquality.SYNTACTICALLY_EQUAL;282 283 for (ITask TreeNodechild : selection.getChildren()) {284 NodeEquality nodeEquality =285 callRuleManager( node, child, commonDenominatorForAllComparisons);286 287 if (( nodeEquality == null) || (nodeEquality == NodeEquality.UNEQUAL))274 TaskEquality commonDenominatorForAllComparisons = TaskEquality.SYNTACTICALLY_EQUAL; 275 276 for (ITask child : selection.getChildren()) { 277 TaskEquality taskEquality = 278 callRuleManager(task, child, commonDenominatorForAllComparisons); 279 280 if ((taskEquality == null) || (taskEquality == TaskEquality.UNEQUAL)) 288 281 { 289 return NodeEquality.UNEQUAL;282 return TaskEquality.UNEQUAL; 290 283 } 291 284 292 285 commonDenominatorForAllComparisons = 293 commonDenominatorForAllComparisons.getCommonDenominator( nodeEquality);286 commonDenominatorForAllComparisons.getCommonDenominator(taskEquality); 294 287 } 295 288 … … 307 300 * @return 308 301 */ 309 private NodeEquality callRuleManager(ITaskTreeNodechild1,310 ITask TreeNodechild2,311 NodeEqualityrequiredEqualityLevel)302 private TaskEquality callRuleManager(ITask child1, 303 ITask child2, 304 TaskEquality requiredEqualityLevel) 312 305 { 313 306 if (requiredEqualityLevel == null) { … … 318 311 } 319 312 else { 320 return NodeEquality.UNEQUAL;313 return TaskEquality.UNEQUAL; 321 314 } 322 315 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/SelectionComparisonRule.java
r1125 r1146 13 13 // limitations under the License. 14 14 15 package de.ugoe.cs.autoquest.tasktrees. nodeequality;15 package de.ugoe.cs.autoquest.tasktrees.taskequality; 16 16 17 17 import java.util.List; 18 18 19 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask TreeNode;20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 21 21 22 22 /** 23 23 * <p> 24 * this nodecomparison rule is capable of comparing selections. If both selections do not have25 * children, they are treated as identical. If they have children, each child of both selections26 * is compared to each child of the respective other selection. The resulting equality is the most27 * concrete one of all these comparisons. I.e. if all children are at least lexically equal, then28 * the selections are lexically equal. If all children are at least syntactically equal, then the29 * selections are syntactically equal. If all children are at least semantically equal, then the30 * selections are semantically equal. If only one of the selections has children, then the31 * selections are unequal.24 * this task comparison rule is capable of comparing selections. If both selections do not have 25 * children, they are treated as lexically equal. If they have children, each child of both 26 * selections is compared to each child of the respective other selection. The resulting equality 27 * is the most concrete one of all these comparisons. I.e. if all children are at least lexically 28 * equal, then the selections are lexically equal. If all children are at least syntactically 29 * equal, then the selections are syntactically equal. If all children are at least semantically 30 * equal, then the selections are semantically equal. If only one of the selections has children, 31 * then the selections are unequal. 32 32 * </p> 33 33 * … … 35 35 * @author 2012, last modified by $Author: patrick$ 36 36 */ 37 public class SelectionComparisonRule implements NodeComparisonRule {38 39 /** the rule manager for internally comparing task tree nodes */40 private NodeEqualityRuleManager mRuleManager;41 42 /** 43 * <p> 44 * simple constructor to provide the rule with the nodeequality rule manager to be able45 * to perform comparisons of the children of provided task tree nodes37 public class SelectionComparisonRule implements TaskComparisonRule { 38 39 /** the rule manager for internally comparing tasks */ 40 private TaskEqualityRuleManager mRuleManager; 41 42 /** 43 * <p> 44 * simple constructor to provide the rule with the task equality rule manager to be able 45 * to perform comparisons of the children of provided tasks 46 46 * </p> 47 47 * 48 * @param ruleManager the rule manager for comparing task tree nodes49 */ 50 SelectionComparisonRule( NodeEqualityRuleManager ruleManager) {48 * @param ruleManager the rule manager for comparing tasks 49 */ 50 SelectionComparisonRule(TaskEqualityRuleManager ruleManager) { 51 51 super(); 52 52 mRuleManager = ruleManager; … … 54 54 55 55 /* (non-Javadoc) 56 * @see NodeComparisonRule#isApplicable(ITask TreeNode, ITaskTreeNode)57 */ 58 @Override 59 public boolean isApplicable(ITask TreeNode node1, ITaskTreeNode node2) {60 return ( node1 instanceof ISelection) && (node2 instanceof ISelection);61 } 62 63 /* (non-Javadoc) 64 * @see NodeComparisonRule#areLexicallyEqual(ITask TreeNode, ITaskTreeNode)65 */ 66 @Override 67 public boolean areLexicallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {68 NodeEquality equality = getEquality(node1, node2, NodeEquality.LEXICALLY_EQUAL);69 return (equality != null) && (equality.isAtLeast( NodeEquality.LEXICALLY_EQUAL));70 } 71 72 /* (non-Javadoc) 73 * @see NodeComparisonRule#areSyntacticallyEqual(ITask TreeNode, ITaskTreeNode)74 */ 75 @Override 76 public boolean areSyntacticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {77 NodeEquality equality = getEquality(node1, node2, NodeEquality.SYNTACTICALLY_EQUAL);78 return (equality != null) && (equality.isAtLeast( NodeEquality.SYNTACTICALLY_EQUAL));79 } 80 81 /* (non-Javadoc) 82 * @see NodeComparisonRule#areSemanticallyEqual(ITask TreeNode, ITaskTreeNode)83 */ 84 @Override 85 public boolean areSemanticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {86 NodeEquality equality = getEquality(node1, node2, NodeEquality.SEMANTICALLY_EQUAL);87 return (equality != null) && (equality.isAtLeast( NodeEquality.SEMANTICALLY_EQUAL));88 } 89 90 /* (non-Javadoc) 91 * @see NodeComparisonRule#compare(ITask TreeNode, ITaskTreeNode)92 */ 93 @Override 94 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) {95 return getEquality( node1, node2, null);56 * @see NodeComparisonRule#isApplicable(ITask, ITask) 57 */ 58 @Override 59 public boolean isApplicable(ITask task1, ITask task2) { 60 return (task1 instanceof ISelection) && (task2 instanceof ISelection); 61 } 62 63 /* (non-Javadoc) 64 * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask) 65 */ 66 @Override 67 public boolean areLexicallyEqual(ITask task1, ITask task2) { 68 TaskEquality equality = getEquality(task1, task2, TaskEquality.LEXICALLY_EQUAL); 69 return (equality != null) && (equality.isAtLeast(TaskEquality.LEXICALLY_EQUAL)); 70 } 71 72 /* (non-Javadoc) 73 * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask) 74 */ 75 @Override 76 public boolean areSyntacticallyEqual(ITask task1, ITask task2) { 77 TaskEquality equality = getEquality(task1, task2, TaskEquality.SYNTACTICALLY_EQUAL); 78 return (equality != null) && (equality.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)); 79 } 80 81 /* (non-Javadoc) 82 * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) 83 */ 84 @Override 85 public boolean areSemanticallyEqual(ITask task1, ITask task2) { 86 TaskEquality equality = getEquality(task1, task2, TaskEquality.SEMANTICALLY_EQUAL); 87 return (equality != null) && (equality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL)); 88 } 89 90 /* (non-Javadoc) 91 * @see NodeComparisonRule#compare(ITask, ITask) 92 */ 93 @Override 94 public TaskEquality compare(ITask task1, ITask task2) { 95 return getEquality(task1, task2, null); 96 96 } 97 97 … … 99 99 * 100 100 */ 101 private NodeEquality getEquality(ITaskTreeNode node1, 102 ITaskTreeNode node2, 103 NodeEquality requiredEqualityLevel) 104 { 105 List<ITaskTreeNode> children1 = node1.getChildren(); 106 List<ITaskTreeNode> children2 = node2.getChildren(); 101 private TaskEquality getEquality(ITask task1, ITask task2, TaskEquality requiredEqualityLevel) { 102 List<ITask> children1 = ((ISelection) task1).getChildren(); 103 List<ITask> children2 = ((ISelection) task2).getChildren(); 107 104 108 105 // if both selections do not have children, they are lexically equal. If only one of them 109 106 // has children, they are unequal. 110 107 if ((children1.size() == 0) && (children2.size() == 0)) { 111 return NodeEquality.LEXICALLY_EQUAL;108 return TaskEquality.LEXICALLY_EQUAL; 112 109 } 113 110 else if ((children1.size() == 0) || (children2.size() == 0)) { 114 return NodeEquality.UNEQUAL;115 } 116 117 NodeEquality selectionEquality;111 return TaskEquality.UNEQUAL; 112 } 113 114 TaskEquality selectionEquality; 118 115 119 116 if (requiredEqualityLevel == null) { … … 121 118 // do it in both directions to ensure commutative comparison 122 119 selectionEquality = getCommonEqualityLevel(children1, children2); 123 if (selectionEquality != NodeEquality.UNEQUAL) {120 if (selectionEquality != TaskEquality.UNEQUAL) { 124 121 return selectionEquality.getCommonDenominator 125 122 (getCommonEqualityLevel(children2, children1)); 126 123 } 127 124 else { 128 return NodeEquality.UNEQUAL;125 return TaskEquality.UNEQUAL; 129 126 } 130 127 } … … 137 134 } 138 135 else { 139 return NodeEquality.UNEQUAL;136 return TaskEquality.UNEQUAL; 140 137 } 141 138 } … … 151 148 * @param requiredEqualityLevel 152 149 */ 153 private NodeEquality getCommonEqualityLevel(List<ITaskTreeNode> children1, 154 List<ITaskTreeNode> children2) 155 { 156 NodeEquality listEquality = NodeEquality.LEXICALLY_EQUAL; 150 private TaskEquality getCommonEqualityLevel(List<ITask> children1, List<ITask> children2) { 151 TaskEquality listEquality = TaskEquality.LEXICALLY_EQUAL; 157 152 158 NodeEquality childEquality;159 NodeEquality currentEquality;160 for (ITask TreeNodechild1 : children1) {153 TaskEquality childEquality; 154 TaskEquality currentEquality; 155 for (ITask child1 : children1) { 161 156 childEquality = null; 162 for (ITask TreeNodechild2 : children2) {157 for (ITask child2 : children2) { 163 158 currentEquality = callRuleManager(child1, child2, null); 164 if ((currentEquality != null) && (currentEquality != NodeEquality.UNEQUAL)) {159 if ((currentEquality != null) && (currentEquality != TaskEquality.UNEQUAL)) { 165 160 if (childEquality == null) { 166 161 childEquality = currentEquality; … … 170 165 } 171 166 172 if (childEquality == NodeEquality.SEMANTICALLY_EQUAL) {167 if (childEquality == TaskEquality.SEMANTICALLY_EQUAL) { 173 168 // as we calculate only the common denominator, we can break up here for 174 169 // the current child. We will not improve the denominator anymore … … 181 176 // we did not find any child in the second list, that is equal to the searched 182 177 // child 183 return NodeEquality.UNEQUAL;178 return TaskEquality.UNEQUAL; 184 179 } 185 180 else { … … 200 195 * @param requiredEqualityLevel 201 196 */ 202 private boolean checkEqualityLevel(List<ITask TreeNode>children1,203 List<ITask TreeNode>children2,204 NodeEqualityrequiredEqualityLevel)197 private boolean checkEqualityLevel(List<ITask> children1, 198 List<ITask> children2, 199 TaskEquality requiredEqualityLevel) 205 200 { 206 NodeEquality childEquality;207 NodeEquality currentEquality;208 for (ITask TreeNodechild1 : children1) {201 TaskEquality childEquality; 202 TaskEquality currentEquality; 203 for (ITask child1 : children1) { 209 204 childEquality = null; 210 for (ITask TreeNodechild2 : children2) {205 for (ITask child2 : children2) { 211 206 currentEquality = callRuleManager(child1, child2, requiredEqualityLevel); 212 207 if ((currentEquality != null) && (currentEquality.isAtLeast(requiredEqualityLevel))) … … 240 235 * @return 241 236 */ 242 private NodeEquality callRuleManager(ITaskTreeNodechild1,243 ITask TreeNodechild2,244 NodeEqualityrequiredEqualityLevel)237 private TaskEquality callRuleManager(ITask child1, 238 ITask child2, 239 TaskEquality requiredEqualityLevel) 245 240 { 246 241 if (requiredEqualityLevel == null) { … … 251 246 } 252 247 else { 253 return NodeEquality.UNEQUAL;248 return TaskEquality.UNEQUAL; 254 249 } 255 250 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/SequenceComparisonRule.java
r1125 r1146 13 13 // limitations under the License. 14 14 15 package de.ugoe.cs.autoquest.tasktrees. nodeequality;15 package de.ugoe.cs.autoquest.tasktrees.taskequality; 16 16 17 17 import java.util.List; 18 18 19 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask TreeNode;20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 21 21 22 22 /** … … 31 31 * @author 2012, last modified by $Author: patrick$ 32 32 */ 33 public class SequenceComparisonRule implements NodeComparisonRule {33 public class SequenceComparisonRule implements TaskComparisonRule { 34 34 35 /** the rule manager for internally comparing task tree nodes */36 private NodeEqualityRuleManager mRuleManager;35 /** the rule manager for internally comparing tasks */ 36 private TaskEqualityRuleManager mRuleManager; 37 37 38 38 /** 39 39 * <p> 40 * simple constructor to provide the rule with the nodeequality rule manager to be able41 * to perform comparisons of the children of provided task tree nodes40 * simple constructor to provide the rule with the task equality rule manager to be able 41 * to perform comparisons of the children of provided tasks 42 42 * </p> 43 43 * 44 * @param ruleManager the rule manager for comparing task tree nodes44 * @param ruleManager the rule manager for comparing tasks 45 45 */ 46 SequenceComparisonRule( NodeEqualityRuleManager ruleManager) {46 SequenceComparisonRule(TaskEqualityRuleManager ruleManager) { 47 47 super(); 48 48 mRuleManager = ruleManager; … … 50 50 51 51 /* (non-Javadoc) 52 * @see NodeComparisonRule#isApplicable(ITask TreeNode, ITaskTreeNode)52 * @see NodeComparisonRule#isApplicable(ITask, ITask) 53 53 */ 54 54 @Override 55 public boolean isApplicable(ITask TreeNode node1, ITaskTreeNode node2) {56 return ( node1 instanceof ISequence) && (node2 instanceof ISequence);55 public boolean isApplicable(ITask task1, ITask task2) { 56 return (task1 instanceof ISequence) && (task2 instanceof ISequence); 57 57 } 58 58 59 59 /* (non-Javadoc) 60 * @see NodeComparisonRule#areLexicallyEqual(ITask TreeNode, ITaskTreeNode)60 * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask) 61 61 */ 62 62 @Override 63 public boolean areLexicallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {64 NodeEquality equality = getEquality(node1, node2, NodeEquality.LEXICALLY_EQUAL);65 return (equality != null) && (equality.isAtLeast( NodeEquality.LEXICALLY_EQUAL));63 public boolean areLexicallyEqual(ITask task1, ITask task2) { 64 TaskEquality equality = getEquality(task1, task2, TaskEquality.LEXICALLY_EQUAL); 65 return (equality != null) && (equality.isAtLeast(TaskEquality.LEXICALLY_EQUAL)); 66 66 } 67 67 68 68 /* (non-Javadoc) 69 * @see NodeComparisonRule#areSyntacticallyEqual(ITask TreeNode, ITaskTreeNode)69 * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask) 70 70 */ 71 71 @Override 72 public boolean areSyntacticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {73 NodeEquality equality = getEquality(node1, node2, NodeEquality.SYNTACTICALLY_EQUAL);74 return (equality != null) && (equality.isAtLeast( NodeEquality.SYNTACTICALLY_EQUAL));72 public boolean areSyntacticallyEqual(ITask task1, ITask task2) { 73 TaskEquality equality = getEquality(task1, task2, TaskEquality.SYNTACTICALLY_EQUAL); 74 return (equality != null) && (equality.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)); 75 75 } 76 76 77 77 /* (non-Javadoc) 78 * @see NodeComparisonRule#areSemanticallyEqual(ITask TreeNode, ITaskTreeNode)78 * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) 79 79 */ 80 80 @Override 81 public boolean areSemanticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {82 NodeEquality equality = getEquality(node1, node2, NodeEquality.SEMANTICALLY_EQUAL);83 return (equality != null) && (equality.isAtLeast( NodeEquality.SEMANTICALLY_EQUAL));81 public boolean areSemanticallyEqual(ITask task1, ITask task2) { 82 TaskEquality equality = getEquality(task1, task2, TaskEquality.SEMANTICALLY_EQUAL); 83 return (equality != null) && (equality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL)); 84 84 } 85 85 86 86 /* (non-Javadoc) 87 * @see NodeComparisonRule#compare(ITask TreeNode, ITaskTreeNode)87 * @see NodeComparisonRule#compare(ITask, ITask) 88 88 */ 89 89 @Override 90 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) {91 return getEquality( node1, node2, null);90 public TaskEquality compare(ITask task1, ITask task2) { 91 return getEquality(task1, task2, null); 92 92 } 93 93 … … 95 95 * 96 96 */ 97 private NodeEquality getEquality(ITaskTreeNode node1, 98 ITaskTreeNode node2, 99 NodeEquality requiredEqualityLevel) 100 { 101 List<ITaskTreeNode> children1 = node1.getChildren(); 102 List<ITaskTreeNode> children2 = node2.getChildren(); 97 private TaskEquality getEquality(ITask task1, ITask task2, TaskEquality requiredEqualityLevel) { 98 List<ITask> children1 = ((ISequence) task1).getChildren(); 99 List<ITask> children2 = ((ISequence) task2).getChildren(); 103 100 104 101 // if both sequences do not have children, they are equal although this doesn't make sense 105 102 if ((children1.size() == 0) && (children2.size() == 0)) { 106 return NodeEquality.LEXICALLY_EQUAL;103 return TaskEquality.LEXICALLY_EQUAL; 107 104 } 108 105 109 106 if (children1.size() != children2.size()) { 110 return NodeEquality.UNEQUAL;107 return TaskEquality.UNEQUAL; 111 108 } 112 109 113 NodeEquality resultingEquality = NodeEquality.LEXICALLY_EQUAL;110 TaskEquality resultingEquality = TaskEquality.LEXICALLY_EQUAL; 114 111 for (int i = 0; i < children1.size(); i++) { 115 ITask TreeNodechild1 = children1.get(i);116 ITask TreeNodechild2 = children2.get(i);112 ITask child1 = children1.get(i); 113 ITask child2 = children2.get(i); 117 114 118 NodeEquality nodeEquality = callRuleManager(child1, child2, requiredEqualityLevel);115 TaskEquality taskEquality = callRuleManager(child1, child2, requiredEqualityLevel); 119 116 120 if (( nodeEquality == null) || (nodeEquality == NodeEquality.UNEQUAL)) {121 return NodeEquality.UNEQUAL;117 if ((taskEquality == null) || (taskEquality == TaskEquality.UNEQUAL)) { 118 return TaskEquality.UNEQUAL; 122 119 } 123 120 124 resultingEquality = resultingEquality.getCommonDenominator( nodeEquality);121 resultingEquality = resultingEquality.getCommonDenominator(taskEquality); 125 122 } 126 123 … … 138 135 * @return 139 136 */ 140 private NodeEquality callRuleManager(ITaskTreeNodechild1,141 ITask TreeNodechild2,142 NodeEqualityrequiredEqualityLevel)137 private TaskEquality callRuleManager(ITask child1, 138 ITask child2, 139 TaskEquality requiredEqualityLevel) 143 140 { 144 141 if (requiredEqualityLevel == null) { … … 149 146 } 150 147 else { 151 return NodeEquality.UNEQUAL;148 return TaskEquality.UNEQUAL; 152 149 } 153 150 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/TaskAndIterationComparisonRule.java
r1125 r1146 13 13 // limitations under the License. 14 14 15 package de.ugoe.cs.autoquest.tasktrees.nodeequality; 16 17 import java.util.List; 15 package de.ugoe.cs.autoquest.tasktrees.taskequality; 18 16 19 17 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask TreeNode;18 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 21 19 22 20 /** 23 21 * <p> 24 * This class is capable of comparing any task tree nodewhich is not an iteration with an25 * iteration. This is needed, because iterations may iterate exactly that node. In this26 * case, the iteration would be equal to that nodeif it was executed exactly once. The rule27 * returns lexically equal, it the child of the iteration is lexically equal to the node22 * This class is capable of comparing any task which is not an iteration with an 23 * iteration. This is needed, because iterations may iterate exactly that task. In this 24 * case, the iteration would be equal to that task if it was executed exactly once. The rule 25 * returns lexically equal, it the child of the iteration is lexically equal to the task 28 26 * or if the child of the iteration is a selection and this selections contains a lexically equal 29 * node. The same applies for syntactical and semantical equality.27 * task. The same applies for syntactical and semantical equality. 30 28 * </p> 31 29 32 30 * @author Patrick Harms 33 31 */ 34 public class NodeAndIterationComparisonRule implements NodeComparisonRule {32 public class TaskAndIterationComparisonRule implements TaskComparisonRule { 35 33 36 /** the rule manager for internally comparing task tree nodes */37 private NodeEqualityRuleManager mRuleManager;34 /** the rule manager for internally comparing tasks */ 35 private TaskEqualityRuleManager mRuleManager; 38 36 39 37 /** 40 38 * <p> 41 * simple constructor to provide the rule with the nodeequality rule manager to be able42 * to perform comparisons of the children of provided task tree nodes39 * simple constructor to provide the rule with the task equality rule manager to be able 40 * to perform comparisons of the children of provided tasks 43 41 * </p> 44 42 * 45 * @param ruleManager the rule manager for comparing task tree nodes43 * @param ruleManager the rule manager for comparing tasks 46 44 */ 47 NodeAndIterationComparisonRule(NodeEqualityRuleManager ruleManager) {45 TaskAndIterationComparisonRule(TaskEqualityRuleManager ruleManager) { 48 46 super(); 49 47 mRuleManager = ruleManager; … … 51 49 52 50 /* (non-Javadoc) 53 * @see NodeComparisonRule#isApplicable(ITask TreeNode, ITaskTreeNode)51 * @see NodeComparisonRule#isApplicable(ITask, ITask) 54 52 */ 55 53 @Override 56 public boolean isApplicable(ITask TreeNode node1, ITaskTreeNode node2) {57 return (( node1 instanceof IIteration) && (!(node2 instanceof IIteration))) ||58 (( node2 instanceof IIteration) && (!(node1 instanceof IIteration)));54 public boolean isApplicable(ITask task1, ITask task2) { 55 return ((task1 instanceof IIteration) && (!(task2 instanceof IIteration))) || 56 ((task2 instanceof IIteration) && (!(task1 instanceof IIteration))); 59 57 } 60 58 61 59 /* (non-Javadoc) 62 * @see NodeComparisonRule#areLexicallyEqual(ITask TreeNode, ITaskTreeNode)60 * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask) 63 61 */ 64 62 @Override 65 public boolean areLexicallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {66 NodeEquality equality = getEquality(node1, node2, NodeEquality.LEXICALLY_EQUAL);67 return (equality != null) && (equality.isAtLeast( NodeEquality.LEXICALLY_EQUAL));63 public boolean areLexicallyEqual(ITask task1, ITask task2) { 64 TaskEquality equality = getEquality(task1, task2, TaskEquality.LEXICALLY_EQUAL); 65 return (equality != null) && (equality.isAtLeast(TaskEquality.LEXICALLY_EQUAL)); 68 66 } 69 67 70 68 /* (non-Javadoc) 71 * @see NodeComparisonRule#areSyntacticallyEqual(ITask TreeNode, ITaskTreeNode)69 * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask) 72 70 */ 73 71 @Override 74 public boolean areSyntacticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {75 NodeEquality equality = getEquality(node1, node2, NodeEquality.SYNTACTICALLY_EQUAL);76 return (equality != null) && (equality.isAtLeast( NodeEquality.SYNTACTICALLY_EQUAL));72 public boolean areSyntacticallyEqual(ITask task1, ITask task2) { 73 TaskEquality equality = getEquality(task1, task2, TaskEquality.SYNTACTICALLY_EQUAL); 74 return (equality != null) && (equality.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)); 77 75 } 78 76 79 77 /* (non-Javadoc) 80 * @see NodeComparisonRule#areSemanticallyEqual(ITask TreeNode, ITaskTreeNode)78 * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) 81 79 */ 82 80 @Override 83 public boolean areSemanticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {84 NodeEquality equality = getEquality(node1, node2, NodeEquality.SEMANTICALLY_EQUAL);85 return (equality != null) && (equality.isAtLeast( NodeEquality.SEMANTICALLY_EQUAL));81 public boolean areSemanticallyEqual(ITask task1, ITask task2) { 82 TaskEquality equality = getEquality(task1, task2, TaskEquality.SEMANTICALLY_EQUAL); 83 return (equality != null) && (equality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL)); 86 84 } 87 85 88 86 /* (non-Javadoc) 89 * @see NodeComparisonRule#compare(ITask TreeNode, ITaskTreeNode)87 * @see NodeComparisonRule#compare(ITask, ITask) 90 88 */ 91 89 @Override 92 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) {93 return getEquality( node1, node2, null);90 public TaskEquality compare(ITask task1, ITask task2) { 91 return getEquality(task1, task2, null); 94 92 } 95 93 … … 97 95 * 98 96 */ 99 private NodeEquality getEquality(ITaskTreeNode node1, 100 ITaskTreeNode node2, 101 NodeEquality requiredEqualityLevel) 102 { 97 private TaskEquality getEquality(ITask task1, ITask task2, TaskEquality requiredEqualityLevel) { 103 98 IIteration iteration = null; 104 ITask TreeNode node= null;99 ITask task = null; 105 100 106 if ( node1 instanceof IIteration) {107 if ( node2 instanceof IIteration) {101 if (task1 instanceof IIteration) { 102 if (task2 instanceof IIteration) { 108 103 // the rule is not responsible for two iterations 109 104 return null; 110 105 } 111 106 112 iteration = (IIteration) node1;113 node = node2;107 iteration = (IIteration) task1; 108 task = task2; 114 109 } 115 else if ( node2 instanceof IIteration) {116 if ( node1 instanceof IIteration) {110 else if (task2 instanceof IIteration) { 111 if (task1 instanceof IIteration) { 117 112 // the rule is not responsible for two iterations 118 113 return null; 119 114 } 120 115 121 iteration = (IIteration) node2;122 node = node1;116 iteration = (IIteration) task2; 117 task = task1; 123 118 } 124 119 else { … … 126 121 } 127 122 128 List<ITaskTreeNode> children = iteration.getChildren();123 ITask child = iteration.getMarkedTask(); 129 124 130 // now, that we found the iteration and the node, lets compare the child of the iteration131 // with the node.132 if (child ren.size() < 1) {125 // now, that we found the iteration and the task, lets compare the child of the iteration 126 // with the task. 127 if (child == null) { 133 128 return null; 134 129 } 135 130 136 NodeEquality nodeEquality = callRuleManager(children.get(0), node, requiredEqualityLevel);131 TaskEquality taskEquality = callRuleManager(child, task, requiredEqualityLevel); 137 132 138 // although the subtask may be identical to the node, we can not return identical, as139 // the iteration is not identical to the node, but at most lexically equal140 if ( nodeEquality == NodeEquality.IDENTICAL) {141 return NodeEquality.LEXICALLY_EQUAL;133 // although the subtask may be identical to the task, we can not return identical, as 134 // the iteration is not identical to the task, but at most lexically equal 135 if (taskEquality == TaskEquality.IDENTICAL) { 136 return TaskEquality.LEXICALLY_EQUAL; 142 137 } 143 138 else { 144 return nodeEquality;139 return taskEquality; 145 140 } 146 141 … … 157 152 * @return 158 153 */ 159 private NodeEquality callRuleManager(ITaskTreeNodechild1,160 ITask TreeNodechild2,161 NodeEqualityrequiredEqualityLevel)154 private TaskEquality callRuleManager(ITask child1, 155 ITask child2, 156 TaskEquality requiredEqualityLevel) 162 157 { 163 158 if (requiredEqualityLevel == null) { … … 168 163 } 169 164 else { 170 return NodeEquality.UNEQUAL;165 return TaskEquality.UNEQUAL; 171 166 } 172 167 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/TaskAndSelectionComparisonRule.java
r1125 r1146 13 13 // limitations under the License. 14 14 15 package de.ugoe.cs.autoquest.tasktrees. nodeequality;15 package de.ugoe.cs.autoquest.tasktrees.taskequality; 16 16 17 17 import java.util.List; 18 18 19 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask TreeNode;20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 21 21 22 22 /** 23 23 * <p> 24 * This class is capable of comparing any task tree nodewhich is not a selection with a25 * selection. This is needed, because selections may contain exactly that node. Therefore, if26 * this node is selected out of a selection the selection is equal to the nodeitself.27 * The rule returns lexically equal, i t the selection contains a lexically equal node. The same24 * This class is capable of comparing any task which is not a selection with a 25 * selection. This is needed, because selections may contain exactly that task. Therefore, if 26 * this task is selected out of a selection the selection is equal to the task itself. 27 * The rule returns lexically equal, if the selection contains a lexically equal task. The same 28 28 * applies for syntactical and semantical equality. 29 29 * </p> … … 31 31 * @author Patrick Harms 32 32 */ 33 public class NodeAndSelectionComparisonRule implements NodeComparisonRule {33 public class TaskAndSelectionComparisonRule implements TaskComparisonRule { 34 34 35 /** the rule manager for internally comparing task tree nodes */36 private NodeEqualityRuleManager mRuleManager;35 /** the rule manager for internally comparing tasks */ 36 private TaskEqualityRuleManager mRuleManager; 37 37 38 38 /** 39 39 * <p> 40 * simple constructor to provide the rule with the nodeequality rule manager to be able41 * to perform comparisons of the children of provided task tree nodes40 * simple constructor to provide the rule with the task equality rule manager to be able 41 * to perform comparisons of the children of provided tasks 42 42 * </p> 43 43 * 44 * @param ruleManager the rule manager for comparing task tree nodes44 * @param ruleManager the rule manager for comparing tasks 45 45 */ 46 NodeAndSelectionComparisonRule(NodeEqualityRuleManager ruleManager) {46 TaskAndSelectionComparisonRule(TaskEqualityRuleManager ruleManager) { 47 47 super(); 48 48 mRuleManager = ruleManager; … … 50 50 51 51 /* (non-Javadoc) 52 * @see NodeComparisonRule#isApplicable(ITask TreeNode, ITaskTreeNode)52 * @see NodeComparisonRule#isApplicable(ITask, ITask) 53 53 */ 54 54 @Override 55 public boolean isApplicable(ITask TreeNode node1, ITaskTreeNode node2) {56 return (( node1 instanceof ISelection) && (!(node2 instanceof ISelection))) ||57 (( node2 instanceof ISelection) && (!(node1 instanceof ISelection)));55 public boolean isApplicable(ITask task1, ITask task2) { 56 return ((task1 instanceof ISelection) && (!(task2 instanceof ISelection))) || 57 ((task2 instanceof ISelection) && (!(task1 instanceof ISelection))); 58 58 } 59 59 60 60 /* (non-Javadoc) 61 * @see NodeComparisonRule#areLexicallyEqual(ITask TreeNode, ITaskTreeNode)61 * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask) 62 62 */ 63 63 @Override 64 public boolean areLexicallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {65 NodeEquality equality = getEquality(node1, node2, NodeEquality.LEXICALLY_EQUAL);66 return (equality != null) && (equality.isAtLeast( NodeEquality.LEXICALLY_EQUAL));64 public boolean areLexicallyEqual(ITask task1, ITask task2) { 65 TaskEquality equality = getEquality(task1, task2, TaskEquality.LEXICALLY_EQUAL); 66 return (equality != null) && (equality.isAtLeast(TaskEquality.LEXICALLY_EQUAL)); 67 67 } 68 68 69 69 /* (non-Javadoc) 70 * @see NodeComparisonRule#areSyntacticallyEqual(ITask TreeNode, ITaskTreeNode)70 * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask) 71 71 */ 72 72 @Override 73 public boolean areSyntacticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {74 NodeEquality equality = getEquality(node1, node2, NodeEquality.SYNTACTICALLY_EQUAL);75 return (equality != null) && (equality.isAtLeast( NodeEquality.SYNTACTICALLY_EQUAL));73 public boolean areSyntacticallyEqual(ITask task1, ITask task2) { 74 TaskEquality equality = getEquality(task1, task2, TaskEquality.SYNTACTICALLY_EQUAL); 75 return (equality != null) && (equality.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)); 76 76 } 77 77 78 78 /* (non-Javadoc) 79 * @see NodeComparisonRule#areSemanticallyEqual(ITask TreeNode, ITaskTreeNode)79 * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) 80 80 */ 81 81 @Override 82 public boolean areSemanticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {83 NodeEquality equality = getEquality(node1, node2, NodeEquality.SEMANTICALLY_EQUAL);84 return (equality != null) && (equality.isAtLeast( NodeEquality.SEMANTICALLY_EQUAL));82 public boolean areSemanticallyEqual(ITask task1, ITask task2) { 83 TaskEquality equality = getEquality(task1, task2, TaskEquality.SEMANTICALLY_EQUAL); 84 return (equality != null) && (equality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL)); 85 85 } 86 86 87 87 /* (non-Javadoc) 88 * @see NodeComparisonRule#compare(ITask TreeNode, ITaskTreeNode)88 * @see NodeComparisonRule#compare(ITask, ITask) 89 89 */ 90 90 @Override 91 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) {92 return getEquality( node1, node2, null);91 public TaskEquality compare(ITask task1, ITask task2) { 92 return getEquality(task1, task2, null); 93 93 } 94 94 … … 96 96 * 97 97 */ 98 private NodeEquality getEquality(ITaskTreeNode node1, 99 ITaskTreeNode node2, 100 NodeEquality requiredEqualityLevel) 101 { 98 private TaskEquality getEquality(ITask task1, ITask task2, TaskEquality requiredEqualityLevel) { 102 99 ISelection selection = null; 103 ITask TreeNode node= null;100 ITask task = null; 104 101 105 if ( node1 instanceof ISelection) {106 if ( node2 instanceof ISelection) {102 if (task1 instanceof ISelection) { 103 if (task2 instanceof ISelection) { 107 104 // the rule is not responsible for two selections 108 105 return null; 109 106 } 110 107 111 selection = (ISelection) node1;112 node = node2;108 selection = (ISelection) task1; 109 task = task2; 113 110 } 114 else if ( node2 instanceof ISelection) {115 if ( node1 instanceof ISelection) {111 else if (task2 instanceof ISelection) { 112 if (task1 instanceof ISelection) { 116 113 // the rule is not responsible for two selections 117 114 return null; 118 115 } 119 116 120 selection = (ISelection) node2;121 node = node1;117 selection = (ISelection) task2; 118 task = task1; 122 119 } 123 120 else { … … 125 122 } 126 123 127 // now, that we found the selection and the node, lets compare the children of the selection128 // with the node.129 List<ITask TreeNode> children = selection.getChildren();124 // now, that we found the selection and the task, lets compare the children of the selection 125 // with the task. 126 List<ITask> children = selection.getChildren(); 130 127 131 128 if (children.size() < 1) { … … 133 130 } 134 131 135 NodeEquality mostConcreteNodeEquality = null;132 TaskEquality mostConcreteNodeEquality = null; 136 133 137 for (ITask TreeNodechild : children) {138 NodeEquality nodeEquality = callRuleManager(child, node, requiredEqualityLevel);134 for (ITask child : children) { 135 TaskEquality taskEquality = callRuleManager(child, task, requiredEqualityLevel); 139 136 140 if ( nodeEquality != NodeEquality.UNEQUAL) {137 if (taskEquality != TaskEquality.UNEQUAL) { 141 138 if (mostConcreteNodeEquality == null) { 142 mostConcreteNodeEquality = nodeEquality;139 mostConcreteNodeEquality = taskEquality; 143 140 } 144 else if (mostConcreteNodeEquality.isAtLeast( nodeEquality)) {145 mostConcreteNodeEquality = nodeEquality;141 else if (mostConcreteNodeEquality.isAtLeast(taskEquality)) { 142 mostConcreteNodeEquality = taskEquality; 146 143 147 144 } … … 151 148 { 152 149 // if we found one child of the selection that is as equal as required, then 153 // we can consider the selection to be sufficiently equal to the other node.150 // we can consider the selection to be sufficiently equal to the other task. 154 151 // So we break up checking further children. 155 152 break; … … 158 155 } 159 156 160 // although the subtask may be identical to the node, we can not return identical, as161 // the selection is not identical to the node, but at most lexically equal162 if (mostConcreteNodeEquality == NodeEquality.IDENTICAL) {163 return NodeEquality.LEXICALLY_EQUAL;157 // although the subtask may be identical to the task, we can not return identical, as 158 // the selection is not identical to the task, but at most lexically equal 159 if (mostConcreteNodeEquality == TaskEquality.IDENTICAL) { 160 return TaskEquality.LEXICALLY_EQUAL; 164 161 } 165 162 else { … … 179 176 * @return 180 177 */ 181 private NodeEquality callRuleManager(ITaskTreeNodechild1,182 ITask TreeNodechild2,183 NodeEqualityrequiredEqualityLevel)178 private TaskEquality callRuleManager(ITask child1, 179 ITask child2, 180 TaskEquality requiredEqualityLevel) 184 181 { 185 182 if (requiredEqualityLevel == null) { … … 190 187 } 191 188 else { 192 return NodeEquality.UNEQUAL;189 return TaskEquality.UNEQUAL; 193 190 } 194 191 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/TaskComparator.java
r1129 r1146 13 13 // limitations under the License. 14 14 15 package de.ugoe.cs.autoquest.tasktrees.t emporalrelation;15 package de.ugoe.cs.autoquest.tasktrees.taskequality; 16 16 17 17 import java.util.HashMap; 18 18 19 import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEquality; 20 import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEqualityRuleManager; 21 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 22 21 import de.ugoe.cs.autoquest.usageprofiles.SymbolComparator; 23 22 import de.ugoe.cs.util.StopWatch; … … 30 29 * @author Patrick Harms 31 30 */ 32 public class Task TreeNodeComparator implements SymbolComparator<ITaskTreeNode> {31 public class TaskComparator implements SymbolComparator<ITaskInstance> { 33 32 34 33 /** 35 34 * <p> 36 * the node equality manager needed for comparing task tree nodes with each other35 * the task equality manager needed for comparing tasks with each other 37 36 * </p> 38 37 */ 39 private NodeEqualityRuleManager nodeEqualityRuleManager;38 private TaskEqualityRuleManager taskEqualityRuleManager; 40 39 41 40 /** 42 41 * <p> 43 * the minimal node equality two identified sublists need to have to consider them as equal 44 * and to create an iteration for 42 * the minimal task equality two identified sublists need to have to consider them as equal 45 43 * </p> 46 44 */ 47 private NodeEquality minimalNodeEquality; 48 45 private TaskEquality minimalNodeEquality; 46 47 /** */ 49 48 private Comparer comparer; 50 49 50 /** */ 51 51 private Comparer lexicalComparer; 52 52 53 /** */ 53 54 private StopWatch stopWatch = new StopWatch(); 54 55 56 /** */ 55 57 private HashMap<Long, Boolean> equalityBuffer = new HashMap<Long, Boolean>(); 56 58 59 /** */ 57 60 private HashMap<Long, Boolean> lexicalEqualityBuffer; 58 61 59 62 /** 60 * <p> 61 * TODO: comment 62 * </p> 63 * 64 * @param nodeEqualityRuleManager 65 * @param minimalNodeEquality 66 */ 67 public TaskTreeNodeComparator(NodeEqualityRuleManager nodeEqualityRuleManager, 68 NodeEquality minimalNodeEquality) 63 * 64 */ 65 public TaskComparator(TaskEqualityRuleManager taskEqualityRuleManager, 66 TaskEquality minimalNodeEquality) 69 67 { 70 68 super(); 71 this. nodeEqualityRuleManager = nodeEqualityRuleManager;69 this.taskEqualityRuleManager = taskEqualityRuleManager; 72 70 this.minimalNodeEquality = minimalNodeEquality; 73 71 74 if (minimalNodeEquality == NodeEquality.LEXICALLY_EQUAL) {72 if (minimalNodeEquality == TaskEquality.LEXICALLY_EQUAL) { 75 73 comparer = new LexicalComparer(); 76 74 } 77 else if (minimalNodeEquality == NodeEquality.SYNTACTICALLY_EQUAL) {75 else if (minimalNodeEquality == TaskEquality.SYNTACTICALLY_EQUAL) { 78 76 comparer = new SyntacticalComparer(); 79 77 } 80 else if (minimalNodeEquality == NodeEquality.SEMANTICALLY_EQUAL) {78 else if (minimalNodeEquality == TaskEquality.SEMANTICALLY_EQUAL) { 81 79 comparer = new SemanticalComparer(); 82 80 } … … 85 83 } 86 84 87 if (minimalNodeEquality == NodeEquality.LEXICALLY_EQUAL) {85 if (minimalNodeEquality == TaskEquality.LEXICALLY_EQUAL) { 88 86 lexicalComparer = comparer; 89 87 lexicalEqualityBuffer = equalityBuffer; … … 99 97 */ 100 98 @Override 101 public boolean equals(ITaskTreeNode symbol1, ITaskTreeNode symbol2) { 102 //String id = "compare " + symbol1.getClass().getSimpleName() + " " + 103 // symbol2.getClass().getSimpleName(); 99 public boolean equals(ITaskInstance taskInstance1, ITaskInstance taskInstance2) { 100 return equals(taskInstance1.getTask(), taskInstance2.getTask()); 101 } 102 103 /** 104 * 105 */ 106 public boolean equals(ITask task1, ITask task2) { 107 //String id = "compare " + taskInstance1.getClass().getSimpleName() + " " + 108 // taskInstance2.getClass().getSimpleName(); 104 109 //String id = "compare"; 105 110 //stopWatch.start(id); … … 107 112 Boolean result; 108 113 109 if ( symbol1 != symbol2) {110 long key = ((long) System.identityHashCode( symbol1)) << 32;111 key += System.identityHashCode( symbol2);114 if (task1 != task2) { 115 long key = ((long) System.identityHashCode(task1)) << 32; 116 key += System.identityHashCode(task2); 112 117 113 118 result = equalityBuffer.get(key); 114 119 115 120 if (result == null) { 116 result = comparer.compare( symbol1, symbol2);121 result = comparer.compare(task1, task2); 117 122 equalityBuffer.put(key, result); 118 123 } … … 123 128 //stopWatch.stop(id); 124 129 125 /*boolean result2 = nodeEqualityRuleManager.areAtLeastEqual(symbol1, symbol2, minimalNodeEquality);130 /*boolean result2 = taskEqualityRuleManager.areAtLeastEqual(symbol1, symbol2, minimalNodeEquality); 126 131 if (result != result2) { 127 132 throw new IllegalStateException("implementation error"); … … 132 137 133 138 /** 134 * <p> 135 * TODO: comment 136 * </p> 137 * 138 * @return 139 * 140 */ 141 public boolean haveLexicallyEqualTasks(ITaskInstance taskInstance1, 142 ITaskInstance taskInstance2) 143 { 144 return areLexicallyEqual(taskInstance1.getTask(), taskInstance2.getTask()); 145 } 146 147 148 /** 149 * 150 */ 151 public boolean areLexicallyEqual(ITask task1, ITask task2) { 152 Boolean result; 153 154 if (task1 != task2) { 155 long key = ((long) System.identityHashCode(task1)) << 32; 156 key += System.identityHashCode(task2); 157 158 result = lexicalEqualityBuffer.get(key); 159 160 if (result == null) { 161 result = lexicalComparer.compare(task1, task2); 162 lexicalEqualityBuffer.put(key, result); 163 } 164 } 165 else { 166 result = true; 167 } 168 169 return result; 170 } 171 172 /** 173 * 139 174 */ 140 175 StopWatch getStopWatch() { … … 143 178 144 179 /** 145 * <p> 146 * TODO: comment 147 * </p> 148 * 149 * @param node1 150 * @param node2 151 * @return 152 */ 153 boolean areLexicallyEqual(ITaskTreeNode symbol1, ITaskTreeNode symbol2) { 154 Boolean result; 155 156 if (symbol1 != symbol2) { 157 long key = ((long) System.identityHashCode(symbol1)) << 32; 158 key += System.identityHashCode(symbol2); 159 160 result = lexicalEqualityBuffer.get(key); 161 162 if (result == null) { 163 result = lexicalComparer.compare(symbol1, symbol2); 164 lexicalEqualityBuffer.put(key, result); 165 } 166 } 167 else { 168 result = true; 169 } 170 171 return result; 172 } 173 174 /** 175 * <p> 176 * TODO: comment 177 * </p> 178 * 179 * @return 180 */ 181 NodeEquality getConsideredNodeEquality() { 180 * 181 */ 182 TaskEquality getConsideredNodeEquality() { 182 183 return minimalNodeEquality; 183 184 } … … 190 191 * 191 192 */ 192 boolean compare(ITask TreeNode node1, ITaskTreeNode node2);193 boolean compare(ITask task1, ITask task2); 193 194 } 194 195 … … 201 202 * 202 203 */ 203 public boolean compare(ITask TreeNode node1, ITaskTreeNode node2) {204 return nodeEqualityRuleManager.areLexicallyEqual(node1, node2);204 public boolean compare(ITask task1, ITask task2) { 205 return taskEqualityRuleManager.areLexicallyEqual(task1, task2); 205 206 } 206 207 } … … 214 215 * 215 216 */ 216 public boolean compare(ITask TreeNode node1, ITaskTreeNode node2) {217 return nodeEqualityRuleManager.areSyntacticallyEqual(node1, node2);217 public boolean compare(ITask task1, ITask task2) { 218 return taskEqualityRuleManager.areSyntacticallyEqual(task1, task2); 218 219 } 219 220 } … … 227 228 * 228 229 */ 229 public boolean compare(ITask TreeNode node1, ITaskTreeNode node2) {230 return nodeEqualityRuleManager.areSemanticallyEqual(node1, node2);230 public boolean compare(ITask task1, ITask task2) { 231 return taskEqualityRuleManager.areSemanticallyEqual(task1, task2); 231 232 } 232 233 } … … 240 241 * 241 242 */ 242 public boolean compare(ITask TreeNode node1, ITaskTreeNode node2) {243 return nodeEqualityRuleManager.areAtLeastEqual(node1, node2, minimalNodeEquality);243 public boolean compare(ITask task1, ITask task2) { 244 return taskEqualityRuleManager.areAtLeastEqual(task1, task2, minimalNodeEquality); 244 245 } 245 246 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/TaskComparisonRule.java
r1125 r1146 13 13 // limitations under the License. 14 14 15 package de.ugoe.cs.autoquest.tasktrees. nodeequality;15 package de.ugoe.cs.autoquest.tasktrees.taskequality; 16 16 17 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask TreeNode;17 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 18 18 19 19 /** 20 20 * <p> 21 * A node comparison rule is used by the {@link NodeEqualityRuleManager} to compare task tree22 * nodes with each other. It provides one methodto be called for a comparison.21 * A task comparison rule is used by the {@link TaskEqualityRuleManager} to compare tasks with 22 * each other. It provides several methods to be called for a comparison. 23 23 * </p> 24 24 * … … 26 26 * @author 2012, last modified by $Author: patrick$ 27 27 */ 28 public interface NodeComparisonRule {28 public interface TaskComparisonRule { 29 29 30 30 /** 31 31 * <p> 32 * checks if the rule is applicable for comparing the two provided nodes32 * checks if the rule is applicable for comparing the two provided tasks 33 33 * </p> 34 34 * 35 * @param node1 the first task tree nodeto compare36 * @param node2 the second task tree nodeto compare35 * @param task1 the first task to compare 36 * @param task2 the second task to compare 37 37 * 38 38 * @return true, if the rule is applicable, false else 39 39 */ 40 public boolean isApplicable(ITask TreeNode node1, ITaskTreeNode node2);40 public boolean isApplicable(ITask task1, ITask task2); 41 41 42 42 /** 43 43 * <p> 44 * checks, if the provided nodes are lexically equal44 * checks, if the provided tasks are lexically equal 45 45 * </p> 46 46 * 47 * @param node1 the first task tree nodeto compare48 * @param node2 the second task tree nodeto compare47 * @param task1 the first task to compare 48 * @param task2 the second task to compare 49 49 * 50 * @return true, if the nodes are equal, false else50 * @return true, if the tasks are equal, false else 51 51 */ 52 public boolean areLexicallyEqual(ITask TreeNode node1, ITaskTreeNode node2);52 public boolean areLexicallyEqual(ITask task1, ITask task2); 53 53 54 54 /** 55 55 * <p> 56 * checks, if the provided nodes are syntactically equal56 * checks, if the provided tasks are syntactically equal 57 57 * </p> 58 58 * 59 * @param node1 the first task tree nodeto compare60 * @param node2 the second task tree nodeto compare59 * @param task1 the first task to compare 60 * @param task2 the second task to compare 61 61 * 62 * @return true, if the nodes are equal, false else62 * @return true, if the tasks are equal, false else 63 63 */ 64 public boolean areSyntacticallyEqual(ITask TreeNode node1, ITaskTreeNode node2);64 public boolean areSyntacticallyEqual(ITask task1, ITask task2); 65 65 66 66 /** 67 67 * <p> 68 * checks, if the provided nodes are semantically equal68 * checks, if the provided tasks are semantically equal 69 69 * </p> 70 70 * 71 * @param node1 the first task tree nodeto compare72 * @param node2 the second task tree nodeto compare71 * @param task1 the first task to compare 72 * @param task2 the second task to compare 73 73 * 74 * @return true, if the nodes are equal, false else74 * @return true, if the tasks are equal, false else 75 75 */ 76 public boolean areSemanticallyEqual(ITask TreeNode node1, ITaskTreeNode node2);76 public boolean areSemanticallyEqual(ITask task1, ITask task2); 77 77 78 78 /** 79 79 * <p> 80 * compares two nodes with each other. The result of the method is either a nodeequality or80 * compares two tasks with each other. The result of the method is either a task equality or 81 81 * null. If it is null, it means, that the rule is not able to correctly compare the two given 82 * nodes82 * tasks 83 83 * </p> 84 84 * 85 * @param node1 the first task tree nodeto compare86 * @param node2 the second task tree nodeto compare85 * @param task1 the first task to compare 86 * @param task2 the second task to compare 87 87 * 88 88 * @return as described 89 89 */ 90 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2);90 public TaskEquality compare(ITask task1, ITask task2); 91 91 92 92 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/TaskEquality.java
r1113 r1146 13 13 // limitations under the License. 14 14 15 package de.ugoe.cs.autoquest.tasktrees. nodeequality;15 package de.ugoe.cs.autoquest.tasktrees.taskequality; 16 16 17 17 /** 18 18 * <p> 19 * A node equality denotes, how equal two task tree nodes are. There are different equality levels19 * A task equality denotes, how equal two tasks are. There are different equality levels 20 20 * which are similar to the usual design levels of GUI design. These levels are 21 21 * <ul> … … 26 26 * can be performed</li> 27 27 * </ul> 28 * It is not possible to compare two task nodes conceptually. But the other design levels can be28 * It is not possible to compare two tasks conceptually. But the other design levels can be 29 29 * identified and compared. 30 30 * </p> 31 31 * <p> 32 * Nodes can be identical. This is the case if in the java virtual machine, their comparison32 * Tasks can be identical. This is the case if in the java virtual machine, their comparison 33 33 * using the <code>==</code> operator or the equals method return true. 34 34 * </p> 35 35 * <p> 36 * Nodes are lexically equal, if they represent the same events on a key stroke level to be37 * carried out to execute the task. Identical nodes are also syntactically equal.36 * Tasks are lexically equal, if they represent the same events on a key stroke level to be 37 * carried out to execute the task. Identical tasks are also syntactically equal. 38 38 * </p> 39 39 * <p> … … 41 41 * syntactical result is the same. For example, entering the text "hello" into a text field can 42 42 * be done by entering the letters in their correct order, but also by copying the text into the 43 * text field. The syntactical result is the same: The text hellowas entered. But the tasks43 * text field. The syntactical result is the same: The text "hello" was entered. But the tasks 44 44 * lexically differ because the events on key stroke level are different. On the other hand, 45 * lexically equal nodes are also syntactically equal.45 * lexically equal tasks are also syntactically equal. 46 46 * </p> 47 47 * <p> 48 * Task tree nodes are semantically equal, if they execute the same function for editing the49 * concepts. An example are a click on a button and a short cut, both executing the same function.50 * These task tree nodes are syntactically and, therefore, also lexically different, but51 * semantically equal. Syntactically equal task tree nodes are always also semantically equal.48 * Tasks are semantically equal, if they execute the same function for editing the concepts. An 49 * example are a click on a button and a short cut, both executing the same function. These tasks 50 * are syntactically and, therefore, also lexically different, but semantically equal. 51 * Syntactically equal tasks are always also semantically equal. 52 52 * </p> 53 53 * … … 55 55 * @author 2012, last modified by $Author: patrick$ 56 56 */ 57 public enum NodeEquality {57 public enum TaskEquality { 58 58 IDENTICAL, 59 59 LEXICALLY_EQUAL, … … 64 64 /** 65 65 * <p> 66 * Checks for the current nodeequality, if it is at least identical to the67 * provided one or even more concrete. As an example, the nodeequality identical also68 * indicates, that the nodes are e.g. lexically, syntactically and semantically equal.66 * Checks for the current task equality, if it is at least identical to the 67 * provided one or even more concrete. As an example, the task equality identical also 68 * indicates, that the tasks are e.g. lexically, syntactically and semantically equal. 69 69 * Therefore, the method called on <code>IDENTICAL</code> with <code>SEMANTICALLY_EQUAL</code> 70 70 * as parameter will return true. If this method is called on <code>SYNTACTICALLY_EQUAL</code> … … 72 72 * </p> 73 73 * 74 * @param nodeEquality the nodeequality to compare with.74 * @param taskEquality the task equality to compare with. 75 75 * 76 76 * @return as described 77 77 */ 78 public boolean isAtLeast( NodeEquality nodeEquality)78 public boolean isAtLeast(TaskEquality taskEquality) 79 79 { 80 switch ( nodeEquality) {80 switch (taskEquality) { 81 81 case IDENTICAL: 82 82 return … … 107 107 /** 108 108 * <p> 109 * returns the common denominator of this nodeequality and the provided one. I.e. if one109 * returns the common denominator of this task equality and the provided one. I.e. if one 110 110 * equality is e.g. syntactical and the other one only semantical, then semantical is returned. 111 111 * </p> 112 112 * 113 113 * @param equality the equality, to compare this with 114 * @return 114 * 115 * @return as described 115 116 */ 116 public NodeEquality getCommonDenominator(NodeEquality otherEquality) {117 public TaskEquality getCommonDenominator(TaskEquality otherEquality) { 117 118 if (this.isAtLeast(otherEquality)) { 118 119 return otherEquality; … … 122 123 } 123 124 else { 124 return NodeEquality.UNEQUAL;125 return TaskEquality.UNEQUAL; 125 126 } 126 127 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/TaskEqualityRuleManager.java
r1125 r1146 13 13 // limitations under the License. 14 14 15 package de.ugoe.cs.autoquest.tasktrees. nodeequality;15 package de.ugoe.cs.autoquest.tasktrees.taskequality; 16 16 17 17 import java.util.ArrayList; 18 18 import java.util.List; 19 19 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask TreeNode;20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 21 21 22 22 /** 23 23 * <p> 24 * The node equality rule manager is capable of comparing task tree nodes based on its internal list25 * of comparison rules. The current list of rules contains the {@link NodeIdentityRule}, the24 * The task equality rule manager is capable of comparing tasks based on its internal list 25 * of comparison rules. The current list of rules contains the {@link TaskIdentityRule}, the 26 26 * {@link IterationComparisonRule}, the {@link SequenceComparisonRule}, and 27 * {@link SelectionComparisonRule}. These rules are asked for comparing the two provided task tree28 * nodes in the mentioned order. If a rule returns a nodeequality other than null, this equality is27 * {@link SelectionComparisonRule}. These rules are asked for comparing the two provided tasks 28 * in the mentioned order. If a rule returns a task equality other than null, this equality is 29 29 * returned. Otherwise the next rule is asked. 30 30 * </p> … … 33 33 * @author 2012, last modified by $Author: patrick$ 34 34 */ 35 public class NodeEqualityRuleManager {35 public class TaskEqualityRuleManager { 36 36 37 37 /** */ 38 private List< NodeComparisonRule> mRuleIndex = null;39 40 /** 41 * <p> 42 * initializes the nodeequality rule manager by filling the internal list of comparison rules.38 private List<TaskComparisonRule> mRuleIndex = null; 39 40 /** 41 * <p> 42 * initializes the task equality rule manager by filling the internal list of comparison rules. 43 43 * This method must be called before any other method is called on the rule manager. 44 44 * </p> 45 45 */ 46 46 public void init() { 47 mRuleIndex = new ArrayList< NodeComparisonRule>();48 mRuleIndex.add(new NodeIdentityRule());47 mRuleIndex = new ArrayList<TaskComparisonRule>(); 48 mRuleIndex.add(new TaskIdentityRule()); 49 49 mRuleIndex.add(new GUIEventTaskComparisonRule()); 50 50 mRuleIndex.add(new EventTaskComparisonRule()); … … 52 52 mRuleIndex.add(new SequenceComparisonRule(this)); 53 53 mRuleIndex.add(new SelectionComparisonRule(this)); 54 mRuleIndex.add(new NodeAndIterationComparisonRule(this));55 mRuleIndex.add(new NodeAndSelectionComparisonRule(this));56 } 57 58 /** 59 * <p> 60 * this method performs a comparison of the two provided task tree nodes. It iterates its61 * internal comparison rules. If the first rule returns a nodeequality other than null,54 mRuleIndex.add(new TaskAndIterationComparisonRule(this)); 55 mRuleIndex.add(new TaskAndSelectionComparisonRule(this)); 56 } 57 58 /** 59 * <p> 60 * this method performs a comparison of the two provided tasks. It iterates its internal 61 * comparison rules. If the first rule returns a task equality other than null, 62 62 * this equality is returned. Otherwise the next rule is tried. If no rule returns an equality 63 63 * <code>NodeEquality.UNEQUAL</code> is returned. 64 64 * </p> 65 65 * 66 * @param node1 the first task tree nodeto be compared67 * @param node2 the second task tree nodeto be compared66 * @param task1 the first task to be compared 67 * @param task2 the second task to be compared 68 68 * 69 69 * @return as described … … 72 72 * manager before a call to this method. 73 73 */ 74 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2)74 public TaskEquality compare(ITask task1, ITask task2) 75 75 throws IllegalStateException 76 76 { … … 79 79 } 80 80 81 // LOG.info("checking for equality of " + node1 + " and " + node2);82 NodeEquality nodeEquality = null;83 84 for ( NodeComparisonRule rule : mRuleIndex) {85 if (rule.isApplicable( node1, node2)) {86 nodeEquality = rule.compare(node1, node2);87 if ( nodeEquality != null) {81 // LOG.info("checking for equality of " + task1 + " and " + task2); 82 TaskEquality taskEquality = null; 83 84 for (TaskComparisonRule rule : mRuleIndex) { 85 if (rule.isApplicable(task1, task2)) { 86 taskEquality = rule.compare(task1, task2); 87 if (taskEquality != null) { 88 88 // LOG.warning("used rule " + rule + " for equality check"); 89 return nodeEquality;89 return taskEquality; 90 90 } 91 91 } 92 92 } 93 93 94 // LOG.warning("no rule could be applied --> handling nodes as unequal");95 96 return NodeEquality.UNEQUAL;94 // LOG.warning("no rule could be applied --> handling tasks as unequal"); 95 96 return TaskEquality.UNEQUAL; 97 97 } 98 98 … … 107 107 * @return 108 108 */ 109 public boolean areAtLeastEqual(ITaskTreeNode node1, 110 ITaskTreeNode node2, 111 NodeEquality equalityLevel) 112 { 109 public boolean areAtLeastEqual(ITask task1, ITask task2, TaskEquality equalityLevel) { 113 110 if (equalityLevel == null) { 114 111 throw new IllegalArgumentException("required equality level must not be null"); … … 117 114 switch (equalityLevel) { 118 115 case IDENTICAL: 119 return areIdentical( node1, node2);116 return areIdentical(task1, task2); 120 117 case LEXICALLY_EQUAL: 121 return areLexicallyEqual( node1, node2);118 return areLexicallyEqual(task1, task2); 122 119 case SYNTACTICALLY_EQUAL: 123 return areSyntacticallyEqual( node1, node2);120 return areSyntacticallyEqual(task1, task2); 124 121 case SEMANTICALLY_EQUAL: 125 return areSemanticallyEqual( node1, node2);122 return areSemanticallyEqual(task1, task2); 126 123 case UNEQUAL: 127 return !areSemanticallyEqual( node1, node2);124 return !areSemanticallyEqual(task1, task2); 128 125 default: 129 126 throw new IllegalArgumentException("unknown required equality: " + equalityLevel); … … 140 137 * @return 141 138 */ 142 public boolean areIdentical(ITask TreeNode node1, ITaskTreeNode node2) {143 if (mRuleIndex == null) { 144 throw new IllegalStateException("not initialized"); 145 } 146 147 for ( NodeComparisonRule rule : mRuleIndex) {148 if (rule.isApplicable( node1, node2) && rule.areLexicallyEqual(node1, node2)) {149 return true; 150 } 151 } 152 153 return false; 154 } 155 156 /** 157 * <p> 158 * TODO: comment 159 * </p> 160 * 161 * @param child1 162 * @param child2 163 * @return 164 */ 165 public boolean areLexicallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {166 if (mRuleIndex == null) { 167 throw new IllegalStateException("not initialized"); 168 } 169 170 for ( NodeComparisonRule rule : mRuleIndex) {171 if (rule.isApplicable( node1, node2) && rule.areLexicallyEqual(node1, node2)) {172 return true; 173 } 174 } 175 176 return false; 177 } 178 179 /** 180 * <p> 181 * TODO: comment 182 * </p> 183 * 184 * @param child1 185 * @param child2 186 * @return 187 */ 188 public boolean areSyntacticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {189 if (mRuleIndex == null) { 190 throw new IllegalStateException("not initialized"); 191 } 192 193 for ( NodeComparisonRule rule : mRuleIndex) {194 if (rule.isApplicable( node1, node2) && rule.areSyntacticallyEqual(node1, node2)) {195 return true; 196 } 197 } 198 199 return false; 200 } 201 202 /** 203 * <p> 204 * TODO: comment 205 * </p> 206 * 207 * @param child1 208 * @param child2 209 * @return 210 */ 211 public boolean areSemanticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {212 if (mRuleIndex == null) { 213 throw new IllegalStateException("not initialized"); 214 } 215 216 for ( NodeComparisonRule rule : mRuleIndex) {217 if (rule.isApplicable( node1, node2) && rule.areSemanticallyEqual(node1, node2)) {139 public boolean areIdentical(ITask task1, ITask task2) { 140 if (mRuleIndex == null) { 141 throw new IllegalStateException("not initialized"); 142 } 143 144 for (TaskComparisonRule rule : mRuleIndex) { 145 if (rule.isApplicable(task1, task2) && rule.areLexicallyEqual(task1, task2)) { 146 return true; 147 } 148 } 149 150 return false; 151 } 152 153 /** 154 * <p> 155 * TODO: comment 156 * </p> 157 * 158 * @param child1 159 * @param child2 160 * @return 161 */ 162 public boolean areLexicallyEqual(ITask task1, ITask task2) { 163 if (mRuleIndex == null) { 164 throw new IllegalStateException("not initialized"); 165 } 166 167 for (TaskComparisonRule rule : mRuleIndex) { 168 if (rule.isApplicable(task1, task2) && rule.areLexicallyEqual(task1, task2)) { 169 return true; 170 } 171 } 172 173 return false; 174 } 175 176 /** 177 * <p> 178 * TODO: comment 179 * </p> 180 * 181 * @param child1 182 * @param child2 183 * @return 184 */ 185 public boolean areSyntacticallyEqual(ITask task1, ITask task2) { 186 if (mRuleIndex == null) { 187 throw new IllegalStateException("not initialized"); 188 } 189 190 for (TaskComparisonRule rule : mRuleIndex) { 191 if (rule.isApplicable(task1, task2) && rule.areSyntacticallyEqual(task1, task2)) { 192 return true; 193 } 194 } 195 196 return false; 197 } 198 199 /** 200 * <p> 201 * TODO: comment 202 * </p> 203 * 204 * @param child1 205 * @param child2 206 * @return 207 */ 208 public boolean areSemanticallyEqual(ITask task1, ITask task2) { 209 if (mRuleIndex == null) { 210 throw new IllegalStateException("not initialized"); 211 } 212 213 for (TaskComparisonRule rule : mRuleIndex) { 214 if (rule.isApplicable(task1, task2) && rule.areSemanticallyEqual(task1, task2)) { 218 215 return true; 219 216 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/TaskIdentityRule.java
r1125 r1146 13 13 // limitations under the License. 14 14 15 package de.ugoe.cs.autoquest.tasktrees. nodeequality;15 package de.ugoe.cs.autoquest.tasktrees.taskequality; 16 16 17 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask TreeNode;17 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 18 18 19 19 /** 20 20 * <p> 21 * This comparison rule returns <code> NodeEquality.IDENTICAL</code> if the comparison of the two22 * task tree nodes using the <code>==</code> operator or the <code>equals</code> method return true.23 * Else it returns null to denote, that it can not compare the nodes.21 * This comparison rule returns <code>TaskEquality.IDENTICAL</code> if the comparison of the two 22 * tasks using the <code>==</code> operator or the <code>equals</code> method return true. 23 * Else it returns null to denote, that it can not compare the tasks. 24 24 * </p> 25 25 * … … 27 27 * @author 2012, last modified by $Author: patrick$ 28 28 */ 29 public class NodeIdentityRule implements NodeComparisonRule {29 public class TaskIdentityRule implements TaskComparisonRule { 30 30 31 31 /* (non-Javadoc) 32 * @see NodeComparisonRule#isApplicable(ITask TreeNode, ITaskTreeNode)32 * @see NodeComparisonRule#isApplicable(ITask, ITask) 33 33 */ 34 34 @Override 35 public boolean isApplicable(ITask TreeNode node1, ITaskTreeNode node2) {36 return ( node1 == node2);35 public boolean isApplicable(ITask task1, ITask task2) { 36 return (task1 == task2); 37 37 } 38 38 39 39 /* (non-Javadoc) 40 * @see NodeComparisonRule#areLexicallyEqual(ITask TreeNode, ITaskTreeNode)40 * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask) 41 41 */ 42 42 @Override 43 public boolean areLexicallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {44 return ( node1 == node2);43 public boolean areLexicallyEqual(ITask task1, ITask task2) { 44 return (task1 == task2); 45 45 } 46 46 47 47 /* (non-Javadoc) 48 * @see NodeComparisonRule#areSyntacticallyEqual(ITask TreeNode, ITaskTreeNode)48 * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask) 49 49 */ 50 50 @Override 51 public boolean areSyntacticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {52 return ( node1 == node2);51 public boolean areSyntacticallyEqual(ITask task1, ITask task2) { 52 return (task1 == task2); 53 53 } 54 54 55 55 /* (non-Javadoc) 56 * @see NodeComparisonRule#areSemanticallyEqual(ITask TreeNode, ITaskTreeNode)56 * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) 57 57 */ 58 58 @Override 59 public boolean areSemanticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {60 return ( node1 == node2);59 public boolean areSemanticallyEqual(ITask task1, ITask task2) { 60 return (task1 == task2); 61 61 } 62 62 63 63 /* (non-Javadoc) 64 * @see NodeComparisonRule#compare(ITask TreeNode, ITaskTreeNode)64 * @see NodeComparisonRule#compare(ITask, ITask) 65 65 */ 66 66 @Override 67 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) {68 if (isApplicable( node1, node2)) {69 return NodeEquality.IDENTICAL;67 public TaskEquality compare(ITask task1, ITask task2) { 68 if (isApplicable(task1, task2)) { 69 return TaskEquality.IDENTICAL; 70 70 } 71 71 else { -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/ITaskInstanceListScopeRule.java
r1113 r1146 15 15 package de.ugoe.cs.autoquest.tasktrees.temporalrelation; 16 16 17 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask TreeNode;17 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; 18 18 19 19 /** 20 20 * <p> 21 * a temporal relationship rule is able to detected temporal relationships between the child nodes 22 * of the parent node provided to the {@link #apply(ITaskTreeNode, boolean)} method. A rule 23 * creates temporal relationships between the child nodes, i.e. substructures in the task tree, if 24 * it detects a temporal relationship and it can be sure that it is complete. Incomplete but 25 * detected temporal relationships may occur, if there can be more children expected to be added 26 * to the provided parent node. This could be the case during parsing a interaction log file of 27 * a GUI. 21 * a task instance list scope rule is able to detected temporal relationships between a list of task 22 * instances provided to the {@link #apply(ITaskInstanceList)} method. A rule creates temporal 23 * relationships between the task instances, i.e. substructures in the task tree, if 24 * it detects a temporal relationship and instantiates the temporal relationships accordingly. 28 25 * </p> 29 26 * 30 27 * @author Patrick Harms 31 28 */ 32 interface TemporalRelationshipRule {29 interface ITaskInstanceListScopeRule extends ITemporalRelationshipRule { 33 30 34 31 /** 35 32 * <p> 36 * applies the rule to the given parent node. The finalize parameter is used to command the rule 37 * to finish rule applications, in the case it is known that no further data will be available. 38 * </p> 39 * <p> 40 * The returned rule application result is null, if the rule can not be applied, i.e. it does not 41 * detect a temporal relationship. It returns a rule application result with a status 42 * {@link RuleApplicationStatus#RULE_APPLICATION_FINISHED} if the rule was applied. The result 43 * contains all newly created parent nodes. It returns a rule application result with status 44 * {@link RuleApplicationStatus#RULE_APPLICATION_FEASIBLE} if the rule would be applicable if 45 * further children would be available in the parent node. This status MUST not be returned if 46 * the finalize parameter is true. In this case the rule must be applied or not. 33 * applies the rule to the given task instance list. The returned rule application result is null, 34 * if the rule can not be applied, i.e. it does not detect a temporal relationship. It returns a 35 * rule application result with a status {@link RuleApplicationStatus#RULE_APPLICATION_FINISHED} 36 * if the rule was applied. The result contains all newly created parent tasks and task instances. 47 37 * </p> 48 38 * 49 * @param parent the parent node with the children to apply the rule on 50 * @param finalize true, if the rule shall not expect further children to come and that it 51 * should therefore be applied in any case 39 * @param taskInstances the list of task instances to apply the rule on 52 40 * 53 41 * @return the rule application result as described. 54 42 */ 55 RuleApplicationResult apply(ITaskTreeNode parent, 56 boolean finalize); 43 RuleApplicationResult apply(ITaskInstanceList taskInstances); 57 44 58 45 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/RuleApplicationResult.java
r1127 r1146 18 18 import java.util.List; 19 19 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 21 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 21 22 22 23 /** 23 24 * <p> 24 * The rule application result describes the result of applying a {@link TemporalRelationshipRule}25 * on a task tree node. It contains a {@link RuleApplicationStatus} and a list of all parent26 * t ask tree nodes that were created during a rule application. See the description of27 * {@link TemporalRelationshipRule} for more details.25 * The rule application result describes the result of applying a {@link ITemporalRelationshipRule}. 26 * It contains a {@link RuleApplicationStatus} and a list of all parent task instances and tasks 27 * that were created during a rule application. See the description of 28 * {@link ITemporalRelationshipRule} for more details. 28 29 * </p> 29 30 * … … 36 37 37 38 /** */ 38 private List<ITaskTreeNode> newParents = new ArrayList<ITaskTreeNode>(); 39 private List<ITask> newParentTasks = new ArrayList<ITask>(); 40 41 /** */ 42 private List<ITaskInstance> newParentInstances = new ArrayList<ITaskInstance>(); 39 43 40 44 /** … … 67 71 /** 68 72 * <p> 69 * add a further parent nodecreated during the rule application73 * add a further parent task created during the rule application 70 74 * </p> 71 75 */ 72 void addNewlyCreated ParentNode(ITaskTreeNodenewParent) {73 newParent s.add(newParent);76 void addNewlyCreatedTask(ITask newParent) { 77 newParentTasks.add(newParent); 74 78 } 75 79 76 80 /** 77 81 * <p> 78 * return all parent nodes created during the rule application82 * return all parent tasks created during the rule application 79 83 * </p> 80 84 */ 81 List<ITaskTreeNode> getNewlyCreatedParentNodes() { 82 return newParents; 85 List<ITask> getNewlyCreatedTasks() { 86 return newParentTasks; 87 } 88 89 /** 90 * <p> 91 * add a further parent task instance created during the rule application 92 * </p> 93 */ 94 void addNewlyCreatedTaskInstance(ITaskInstance newParent) { 95 newParentInstances.add(newParent); 96 } 97 98 /** 99 * <p> 100 * return all parent task instances created during the rule application 101 * </p> 102 */ 103 List<ITaskInstance> getNewlyCreatedTaskInstances() { 104 return newParentInstances; 83 105 } 84 106 -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/RuleApplicationStatus.java
r1127 r1146 17 17 /** 18 18 * <p> 19 * The rule application status describes the result of applying a {@link TemporalRelationshipRule}20 * on a task tree node. See the description of {@linkTemporalRelationshipRule} for more details.19 * The rule application status describes the result of applying a {@link ITemporalRelationshipRule}. 20 * See the description of {@link ITemporalRelationshipRule} for more details. 21 21 * </p> 22 22 * … … 25 25 enum RuleApplicationStatus { 26 26 FINISHED, 27 // TODO drop feasible 27 28 FEASIBLE, 28 29 NOT_APPLIED; -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/RuleUtils.java
r1127 r1146 15 15 package de.ugoe.cs.autoquest.tasktrees.temporalrelation; 16 16 17 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 18 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder; 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNodeFactory; 17 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 18 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; 21 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; 21 22 22 23 /** … … 35 36 * 36 37 */ 37 static I Sequence getSubSequenceInRange(ITaskTreeNodeparent,38 intstartIndex,39 intendIndex,40 String description,41 ITaskTreeNodeFactory nodeFactory,42 ITaskTreeBuilder builder)38 static ITaskInstance getSubSequenceInRange(ITaskInstanceList parent, 39 int startIndex, 40 int endIndex, 41 ITask model, 42 ITaskFactory taskFactory, 43 ITaskBuilder taskBuilder) 43 44 { 44 ISequence sequence = nodeFactory.createNewSequence(); 45 if (description != null) { 46 builder.setDescription(sequence, description); 45 ITaskInstance subsequence = taskFactory.createNewTaskInstance(model); 46 47 for (int i = startIndex; i <= endIndex; i++) { 48 taskBuilder.addChild(subsequence, parent.get(i)); 47 49 } 48 50 49 for (int i = startIndex; i <= endIndex; i++) { 50 builder.addChild(sequence, parent.getChildren().get(i)); 51 } 52 53 return sequence; 51 return subsequence; 54 52 } 55 53 … … 57 55 * 58 56 */ 59 static I Sequence createNewSubSequenceInRange(ITaskTreeNodeparent,60 intstartIndex,61 intendIndex,62 String description,63 ITaskTreeNodeFactory nodeFactory,64 ITaskTreeBuilder builder)57 static ITaskInstance createNewSubSequenceInRange(ITaskInstanceList parent, 58 int startIndex, 59 int endIndex, 60 ITask model, 61 ITaskFactory taskFactory, 62 ITaskBuilder taskBuilder) 65 63 { 66 ISequence sequence = nodeFactory.createNewSequence(); 67 if (description != null) { 68 builder.setDescription(sequence, description); 64 ITaskInstance subsequence = taskFactory.createNewTaskInstance(model); 65 66 for (int i = startIndex; i <= endIndex; i++) { 67 taskBuilder.addChild(subsequence, parent.get(startIndex)); 68 taskBuilder.removeTaskInstance(parent, startIndex); 69 69 } 70 70 71 for (int i = startIndex; i <= endIndex; i++) {72 builder.addChild(sequence, parent.getChildren().get(startIndex));73 builder.removeChild((ISequence) parent, startIndex);74 }75 71 76 builder.addChild((ISequence) parent, startIndex,sequence);72 taskBuilder.addTaskInstance(parent, startIndex, subsequence); 77 73 78 return s equence;74 return subsequence; 79 75 } 80 76 -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRule.java
r1133 r1146 15 15 package de.ugoe.cs.autoquest.tasktrees.temporalrelation; 16 16 17 import java.util.HashMap; 17 18 import java.util.Iterator; 18 19 import java.util.LinkedList; 19 20 import java.util.List; 20 21 21 import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEquality; 22 import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEqualityRuleManager; 22 import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality; 23 import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEqualityRuleManager; 24 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 23 25 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 24 26 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 25 27 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 26 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder; 27 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 28 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNodeFactory; 28 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 29 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; 30 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; 31 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 32 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; 33 import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 34 import de.ugoe.cs.autoquest.usageprofiles.SymbolComparator; 29 35 import de.ugoe.cs.autoquest.usageprofiles.Trie; 30 36 import de.ugoe.cs.autoquest.usageprofiles.TrieProcessor; 31 37 import de.ugoe.cs.util.StopWatch; 32 import de.ugoe.cs.util.console.Console;33 38 34 39 /** … … 39 44 * @author Patrick Harms 40 45 */ 41 class SequenceForTaskDetectionRule implements TemporalRelationshipRule {46 class SequenceForTaskDetectionRule implements ISessionScopeRule { 42 47 43 48 /** 44 49 * <p> 45 * the task tree nodefactory to be used for creating substructures for the temporal50 * the task factory to be used for creating substructures for the temporal 46 51 * relationships identified during rule 47 52 * </p> 48 53 */ 49 private ITask TreeNodeFactory taskTreeNodeFactory;54 private ITaskFactory taskFactory; 50 55 /** 51 56 * <p> 52 * the task treebuilder to be used for creating substructures for the temporal relationships57 * the task builder to be used for creating substructures for the temporal relationships 53 58 * identified during rule application 54 59 * </p> 55 60 */ 56 private ITask TreeBuilder taskTreeBuilder;61 private ITaskBuilder taskBuilder; 57 62 58 63 /** 59 64 * <p> 60 * the node comparator to be used for comparing task tree nodes65 * the task comparator to be used for comparing tasks 61 66 * </p> 62 67 */ 63 private Task TreeNodeComparator nodeComparator;68 private TaskComparator taskComparator; 64 69 65 70 /** 66 71 * <p> 67 * instantiates the rule and initializes it with a nodeequality rule manager and the minimal68 * nodeequality identified sublist must have to consider them as iterated.72 * instantiates the rule and initializes it with a task equality rule manager and the minimal 73 * task equality identified sublist must have to consider them as iterated. 69 74 * </p> 70 75 */ 71 SequenceForTaskDetectionRule( NodeEqualityRuleManager nodeEqualityRuleManager,72 NodeEquality minimalNodeEquality,73 ITask TreeNodeFactory taskTreeNodeFactory,74 ITask TreeBuilder taskTreeBuilder)76 SequenceForTaskDetectionRule(TaskEqualityRuleManager taskEqualityRuleManager, 77 TaskEquality minimalTaskEquality, 78 ITaskFactory taskFactory, 79 ITaskBuilder taskBuilder) 75 80 { 76 this.taskTreeNodeFactory = taskTreeNodeFactory; 77 this.taskTreeBuilder = taskTreeBuilder; 78 79 this.nodeComparator = 80 new TaskTreeNodeComparator(nodeEqualityRuleManager, minimalNodeEquality); 81 this.taskFactory = taskFactory; 82 this.taskBuilder = taskBuilder; 83 84 this.taskComparator = new TaskComparator(taskEqualityRuleManager, minimalTaskEquality); 81 85 } 82 86 … … 89 93 } 90 94 91 /* 92 * (non-Javadoc) 93 * 94 * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, 95 * boolean) 95 /* (non-Javadoc) 96 * @see de.ugoe.cs.autoquest.tasktrees.temporalrelation.ISessionScopeRule#apply(java.util.List) 96 97 */ 97 98 @Override 98 public RuleApplicationResult apply(ITaskTreeNode parent, boolean finalize) { 99 if (!(parent instanceof ISequence)) { 100 return null; 101 } 102 103 if (!finalize) { 104 // the rule is always feasible as tasks may occur at any time 105 RuleApplicationResult result = new RuleApplicationResult(); 106 result.setRuleApplicationStatus(RuleApplicationStatus.FEASIBLE); 107 return result; 108 } 109 110 List<ITaskTreeNode> children = parent.getChildren(); 111 List<ISequence> sessions = new LinkedList<ISequence>(); 112 113 for (ITaskTreeNode child : children) { 114 if (child instanceof ISequence) { 115 sessions.add((ISequence) child); 116 } 117 else { 118 Console.println("provided parent is no parent of sessions"); 119 return null; 120 } 121 } 122 99 public RuleApplicationResult apply(List<IUserSession> sessions) { 123 100 RuleApplicationData appData = new RuleApplicationData(sessions); 124 101 125 boolean finished = false;126 127 102 // this is the real rule application. Loop while something is replaced. 128 103 do { … … 137 112 appData.getStopWatch().stop("whole loop"); 138 113 139 //((TaskTreeNodeComparator) nodeComparator).getStopWatch().dumpStatistics(System.out);140 //((TaskTreeNodeComparator) nodeComparator).getStopWatch().reset();114 //((TaskTreeNodeComparator) taskComparator).getStopWatch().dumpStatistics(System.out); 115 //((TaskTreeNodeComparator) taskComparator).getStopWatch().reset(); 141 116 142 117 appData.getStopWatch().dumpStatistics(System.out); 143 118 appData.getStopWatch().reset(); 144 119 145 finished = (appData.getReplacementCounter() == 0); 146 } 147 while (!finished); 148 149 System.out.println("created " + appData.getResult().getNewlyCreatedParentNodes().size() + 150 " new parent nodes\n"); 151 152 if (appData.getResult().getNewlyCreatedParentNodes().size() > 0) { 120 } 121 while (appData.detectedAndReplacedTasks()); 122 123 System.out.println 124 ("created " + appData.getResult().getNewlyCreatedTasks().size() + 125 " new tasks and " + appData.getResult().getNewlyCreatedTaskInstances().size() + 126 " appropriate instances\n"); 127 128 if ((appData.getResult().getNewlyCreatedTasks().size() > 0) || 129 (appData.getResult().getNewlyCreatedTaskInstances().size() > 0)) 130 { 153 131 appData.getResult().setRuleApplicationStatus(RuleApplicationStatus.FINISHED); 154 132 } … … 164 142 appData.getStopWatch().start("detecting iterations"); 165 143 166 List<ISequence> sessions = appData.getSessions(); 167 int foundIterations = 0; 168 169 for (ISequence session : sessions) { 170 foundIterations += detectAndReplaceIterations(session, appData); 171 } 144 List<IUserSession> sessions = appData.getSessions(); 145 int iteratedTasks = 0; 146 147 ITask iteratedTask = null; 148 149 do { 150 iteratedTask = searchIteratedTask(sessions); 151 152 if (iteratedTask != null) { 153 replaceIterationsOf(iteratedTask, sessions, appData); 154 iteratedTasks++; 155 } 156 } 157 while (iteratedTask != null); 172 158 173 159 appData.getStopWatch().stop("detecting iterations"); 174 System.out.println(" --> found " + foundIterations); 175 } 176 177 /** 178 * @param appData 179 */ 180 private int detectAndReplaceIterations(ISequence session, 181 RuleApplicationData appData) 160 System.out.println(" --> found " + iteratedTasks + " iterated tasks"); 161 } 162 163 /** 164 * 165 */ 166 private ITask searchIteratedTask(List<IUserSession> sessions) { 167 for (IUserSession session : sessions) { 168 for (int i = 0; i < (session.size() - 1); i++) { 169 if (taskComparator.equals(session.get(i).getTask(), session.get(i + 1).getTask())) { 170 return session.get(i).getTask(); 171 } 172 } 173 } 174 175 return null; 176 } 177 178 /** 179 * 180 */ 181 private void replaceIterationsOf(ITask iteratedTask, 182 List<IUserSession> sessions, 183 RuleApplicationData appData) 182 184 { 183 int count = 0; 184 185 TemporalRelationshipRule rule = new SimpleIterationDetectionRule 186 (nodeComparator, taskTreeNodeFactory, taskTreeBuilder); 187 188 RuleApplicationResult result = rule.apply(session, true); 189 190 if ((result != null) && (result.getNewlyCreatedParentNodes() != null)) { 191 for (ITaskTreeNode newParent : result.getNewlyCreatedParentNodes()) { 192 appData.getResult().addNewlyCreatedParentNode(newParent); 193 if (newParent instanceof IIteration) { 194 count++; 195 } 196 } 197 } 198 199 return count; 185 IIteration iteration = taskFactory.createNewIteration(); 186 ITaskInstance iterationInstance = null; 187 188 List<ITaskInstance> iterationInstances = new LinkedList<ITaskInstance>(); 189 190 for (IUserSession session : sessions) { 191 int index = 0; 192 while (index < session.size()) { 193 if (taskComparator.equals(iteratedTask, session.get(index).getTask())) { 194 if (iterationInstance == null) { 195 iterationInstance = taskFactory.createNewTaskInstance(iteration); 196 iterationInstances.add(iterationInstance); 197 taskBuilder.addTaskInstance(session, index, iterationInstance); 198 index++; 199 } 200 201 taskBuilder.addChild(iterationInstance, session.get(index)); 202 taskBuilder.removeTaskInstance(session, index); 203 } 204 else { 205 if (iterationInstance != null) { 206 iterationInstance = null; 207 } 208 index++; 209 } 210 } 211 } 212 213 harmonizeIterationInstancesModel(iteration, iterationInstances); 214 } 215 216 /** 217 * <p> 218 * TODO: comment 219 * </p> 220 * 221 * @param iteratedTaskVariants 222 */ 223 private void harmonizeIterationInstancesModel(IIteration iteration, 224 List<ITaskInstance> iterationInstances) 225 { 226 List<ITask> iteratedTaskVariants = new LinkedList<ITask>(); 227 228 // merge the lexically different variants of iterated task to a unique list 229 for (ITaskInstance iterationInstance : iterationInstances) { 230 for (ITaskInstance executionVariant : iterationInstance) { 231 ITask candidate = executionVariant.getTask(); 232 233 boolean found = false; 234 for (ITask taskVariant : iteratedTaskVariants) { 235 if (taskComparator.areLexicallyEqual(taskVariant, candidate)) { 236 taskBuilder.setTask(executionVariant, taskVariant); 237 found = true; 238 break; 239 } 240 } 241 242 if (!found) { 243 iteratedTaskVariants.add(candidate); 244 } 245 } 246 } 247 248 // if there are more than one lexically different variant of iterated tasks, adapt the 249 // iteration model to be a selection of different variants. In this case also adapt 250 // the generated iteration instances to correctly contain selection instances. If there 251 // is only one variant of an iterated task, simply set this as the marked task of the 252 // iteration. In this case, the instances can be preserved as is 253 if (iteratedTaskVariants.size() > 1) { 254 ISelection selection = taskFactory.createNewSelection(); 255 256 for (ITask variant : iteratedTaskVariants) { 257 taskBuilder.addChild(selection, variant); 258 } 259 260 taskBuilder.setMarkedTask(iteration, selection); 261 262 for (ITaskInstance instance : iterationInstances) { 263 for (int i = 0; i < instance.size(); i++) { 264 ITaskInstance selectionInstance = taskFactory.createNewTaskInstance(selection); 265 taskBuilder.addChild(selectionInstance, instance.get(i)); 266 taskBuilder.setTaskInstance(instance, i, selectionInstance); 267 } 268 } 269 } 270 else { 271 taskBuilder.setMarkedTask(iteration, iteratedTaskVariants.get(0)); 272 } 200 273 } 201 274 … … 226 299 Tasks tasks; 227 300 boolean createNewTrie = (appData.getLastTrie() == null) || 228 appData. getReplacementCounter() > 0; // tree has changed301 appData.detectedAndReplacedTasks(); // tree has changed 229 302 230 303 do { … … 240 313 createNewTrie = false; 241 314 242 for (List<ITask TreeNode> task : tasks) {315 for (List<ITaskInstance> task : tasks) { 243 316 if (task.size() >= appData.getTrainedSequenceLength()) { 244 317 // Trie must be recreated with a longer sequence length to be sure that … … 267 340 268 341 appData.getStopWatch().start("training trie"); 269 appData.setLastTrie(new Trie<ITask TreeNode>(nodeComparator));342 appData.setLastTrie(new Trie<ITaskInstance>(taskComparator)); 270 343 271 List<I Sequence> sessions = appData.getSessions();272 273 for (I Sequencesession : sessions) {344 List<IUserSession> sessions = appData.getSessions(); 345 346 for (IUserSession session : sessions) { 274 347 trainTrie(session, appData); 275 348 } … … 282 355 * @param parent 283 356 */ 284 private void trainTrie(I Sequencesession, RuleApplicationData appData) {285 List<ITask TreeNode> children = session.getChildren();357 private void trainTrie(IUserSession session, RuleApplicationData appData) { 358 List<ITaskInstance> children = session.getExecutedTasks(); 286 359 287 360 if ((children != null) && (children.size() > 0)) { … … 294 367 */ 295 368 private void replaceSequencesOccurringMostOften(RuleApplicationData appData) { 296 appData. resetReplacementCounter();369 appData.detectedAndReplacedTasks(false); 297 370 298 371 if ((appData.getLastFoundTasks().size() > 0) && 299 372 (appData.getLastFoundTasks().getOccurrenceCount() > 1)) 300 373 { 301 System.out.println("replacing tasks occurrences with merged variants of all versions"); 302 303 for (List<ITaskTreeNode> task : appData.getLastFoundTasks()) { 304 String taskId = "task " + RuleUtils.getNewId(); 305 System.out.println("replacing " + taskId + ": " + task); 306 307 appData.clearTaskOccurrences(); 308 determineVariantsOfTaskOccurrences(task, appData.getSessions(), appData); 309 310 appData.getStopWatch().start("merging task nodes"); 311 ITaskTreeNode taskReplacement = mergeVariantsOfTaskOccurrence(taskId, appData); 312 appData.getStopWatch().stop("merging task nodes"); 313 314 appData.resetReplacementCounter(); 315 replaceTaskOccurrences(task, taskReplacement, appData.getSessions(), appData); 316 317 if (appData.getReplacementCounter() > 0) { 318 appData.getResult().addNewlyCreatedParentNode(taskReplacement); 319 } 320 321 if (appData.getReplacementCounter() < 322 appData.getLastFoundTasks().getOccurrenceCount()) 323 { 324 System.out.println(taskId + ": replaced task only " + 325 appData.getReplacementCounter() + 326 " times instead of expected " + 374 System.out.println("replacing tasks occurrences"); 375 376 for (List<ITaskInstance> task : appData.getLastFoundTasks()) { 377 ISequence sequence = taskFactory.createNewSequence(); 378 379 System.out.println("replacing " + sequence.getId() + ": " + task); 380 381 List<ITaskInstance> sequenceInstances = 382 replaceTaskOccurrences(task, appData.getSessions(), sequence); 383 384 harmonizeSequenceInstancesModel(sequence, sequenceInstances,task.size()); 385 appData.detectedAndReplacedTasks(sequenceInstances.size() > 0); 386 387 if (sequenceInstances.size() < appData.getLastFoundTasks().getOccurrenceCount()) { 388 System.out.println(sequence.getId() + ": replaced task only " + 389 sequenceInstances.size() + " times instead of expected " + 327 390 appData.getLastFoundTasks().getOccurrenceCount()); 328 391 } … … 333 396 334 397 /** 335 * @param tree336 */ 337 private void determineVariantsOfTaskOccurrences(List<ITaskTreeNode> task,338 List<ISequence> sessions,339 RuleApplicationData appData)398 * 399 */ 400 private void harmonizeSequenceInstancesModel(ISequence sequence, 401 List<ITaskInstance> sequenceInstances, 402 int sequenceLength) 340 403 { 341 for (ISequence session : sessions) { 342 int index = -1; 343 344 List<ITaskTreeNode> children = session.getChildren(); 345 346 do { 347 index = getSubListIndex(children, task, ++index); 348 349 if (index > -1) { 350 ISequence taskOccurrence = RuleUtils.getSubSequenceInRange 351 (session, index, index + task.size() - 1, null, 352 taskTreeNodeFactory, taskTreeBuilder); 353 354 appData.addTaskOccurrence(taskOccurrence); 355 356 // let the index point to the last element the belongs the identified occurrence 357 index += task.size() - 1; 358 } 359 } 360 while (index > -1); 361 } 362 } 363 364 /** 365 * @param appData 366 * @return 367 */ 368 private ITaskTreeNode mergeVariantsOfTaskOccurrence(String taskId, 369 RuleApplicationData appData) 370 { 371 return mergeVariantsOfTasks(taskId, appData.getTaskOccurrences()); 372 } 373 374 /** 375 * @param appData 376 * @return 377 */ 378 private ITaskTreeNode mergeVariantsOfTasks(String description, List<ITaskTreeNode> variants) { 379 // merge but preserve lexically distinct variants 380 TaskTreeNodeMerger merger = new TaskTreeNodeMerger 381 (taskTreeNodeFactory, taskTreeBuilder, nodeComparator); 382 383 merger.mergeTaskNodes(variants); 384 385 if (variants.size() == 1) { 386 ITaskTreeNode replacement = variants.get(0); 387 taskTreeBuilder.setDescription(replacement, description); 388 return replacement; 389 } 390 else { 391 ISelection selection = taskTreeNodeFactory.createNewSelection(); 392 taskTreeBuilder.setDescription(selection, "variants of task " + description); 393 394 for (ITaskTreeNode variant : variants) { 395 taskTreeBuilder.addChild(selection, variant); 396 } 397 398 return selection; 399 } 400 } 401 402 /** 403 * @param task 404 * @param parent 405 * @param treeBuilder 406 * @param nodeFactory 407 * @param result 408 */ 409 private void replaceTaskOccurrences(List<ITaskTreeNode> task, 410 ITaskTreeNode replacement, 411 List<ISequence> sessions, 412 RuleApplicationData appData) 413 { 414 // now check the children themselves for an occurrence of the task 415 for (int i = 0; i < sessions.size(); i++) { 416 ISequence session = sessions.get(i); 417 418 int index = -1; 419 420 List<ITaskTreeNode> children = session.getChildren(); 421 422 do { 423 index = getSubListIndex(children, task, ++index); 424 425 if (index > -1) { 426 if ((!(replacement instanceof ISequence)) || 427 (task.size() < children.size())) 428 { 429 for (int j = index; j < index + task.size(); j++) { 430 taskTreeBuilder.removeChild(session, index); 431 } 432 433 taskTreeBuilder.addChild(session, index, replacement); 434 appData.incrementReplacementCounter(); 435 436 children = session.getChildren(); 437 } 438 else { 439 // the whole list of children is an occurrence of this task. So ask the 440 // caller of the method to replace the whole node 441 sessions.set(i, (ISequence) replacement); 442 appData.incrementReplacementCounter(); 404 405 // ensure for each subtask that lexically different variants are preserved 406 for (int subTaskIndex = 0; subTaskIndex < sequenceLength; subTaskIndex++) { 407 List<ITask> subTaskVariants = new LinkedList<ITask>(); 408 409 for (ITaskInstance sequenceInstance : sequenceInstances) { 410 ITask candidate = sequenceInstance.get(subTaskIndex).getTask(); 411 412 boolean found = false; 413 414 for (int i = 0; i < subTaskVariants.size(); i++) { 415 if (taskComparator.areLexicallyEqual(subTaskVariants.get(i), candidate)) { 416 taskBuilder.setTask 417 (sequenceInstance.get(subTaskIndex), subTaskVariants.get(i)); 418 419 found = true; 443 420 break; 444 421 } 445 422 } 423 424 if (!found) { 425 subTaskVariants.add(candidate); 426 } 427 } 428 429 // if there are more than one lexically different variant of the sub task at 430 // the considered position, adapt the sequence model at that position to have 431 // a selection of the different variants. In this case also adapt the 432 // generated sequence instances to correctly contain selection instances. If 433 // there is only one variant of sub tasks at the given position, simply set 434 // this variant as the sub task of the selection. In this case, the instances 435 // can be preserved as is 436 if (subTaskVariants.size() > 1) { 437 ISelection selection = taskFactory.createNewSelection(); 438 439 for (ITask variant : subTaskVariants) { 440 taskBuilder.addChild(selection, variant); 441 } 442 443 taskBuilder.addChild(sequence, selection); 444 445 for (ITaskInstance instance : sequenceInstances) { 446 ITaskInstance selectionInstance = 447 taskFactory.createNewTaskInstance(selection); 448 taskBuilder.addChild(selectionInstance, instance.get(subTaskIndex)); 449 taskBuilder.setTaskInstance(instance, subTaskIndex, selectionInstance); 450 } 451 } 452 else if (subTaskVariants.size() == 1) { 453 taskBuilder.addChild(sequence, subTaskVariants.get(0)); 454 } 455 } 456 } 457 458 /** 459 * @param tree 460 */ 461 private List<ITaskInstance> replaceTaskOccurrences(List<ITaskInstance> task, 462 List<IUserSession> sessions, 463 ISequence temporalTaskModel) 464 { 465 List<ITaskInstance> sequenceInstances = new LinkedList<ITaskInstance>(); 466 467 for (IUserSession session : sessions) { 468 int index = -1; 469 470 do { 471 index = getSubListIndex(session, task, ++index); 472 473 if (index > -1) { 474 sequenceInstances.add 475 (RuleUtils.createNewSubSequenceInRange 476 (session, index, index + task.size() - 1, temporalTaskModel, 477 taskFactory, taskBuilder)); 478 } 446 479 } 447 480 while (index > -1); 448 481 } 482 483 return sequenceInstances; 449 484 } 450 485 … … 454 489 * @return 455 490 */ 456 private int getSubListIndex( List<ITaskTreeNode>list,457 List<ITask TreeNode> subList,491 private int getSubListIndex(ITaskInstanceList list, 492 List<ITaskInstance> subList, 458 493 int startIndex) 459 494 { … … 465 500 466 501 for (int j = 0; j < subList.size(); j++) { 467 if (! nodeComparator.equals(list.get(i + j), subList.get(j))) {502 if (!taskComparator.equals(list.get(i + j), subList.get(j))) { 468 503 matchFound = false; 469 504 break; … … 479 514 return result; 480 515 } 516 517 /** 518 * @param trie 519 * @param object 520 * @return 521 */ 522 private int getSubListIndex(List<ITaskInstance> list, 523 List<ITaskInstance> subList, 524 int startIndex) 525 { 526 boolean matchFound; 527 int result = -1; 528 529 for (int i = startIndex; i <= list.size() - subList.size(); i++) { 530 matchFound = true; 531 532 for (int j = 0; j < subList.size(); j++) { 533 if (!taskComparator.equals(list.get(i + j), subList.get(j))) { 534 matchFound = false; 535 break; 536 } 537 } 538 539 if (matchFound) { 540 result = i; 541 break; 542 } 543 } 544 545 return result; 546 } 481 547 482 548 /** 483 549 * @author Patrick Harms 484 550 */ 485 private class MaxCountAndLongestTasksFinder implements TrieProcessor<ITask TreeNode> {551 private class MaxCountAndLongestTasksFinder implements TrieProcessor<ITaskInstance> { 486 552 487 553 /** … … 493 559 * 494 560 */ 495 private List<List<ITask TreeNode>> foundTasks = new LinkedList<List<ITaskTreeNode>>();561 private List<List<ITaskInstance>> foundTasks = new LinkedList<List<ITaskInstance>>(); 496 562 497 563 /** … … 507 573 */ 508 574 @Override 509 public TrieProcessor.Result process(List<ITask TreeNode> task, int count) {510 if ( task.size() < 2) {511 // ignore single nodes575 public TrieProcessor.Result process(List<ITaskInstance> foundTask, int count) { 576 if (foundTask.size() < 2) { 577 // ignore single tasks 512 578 return TrieProcessor.Result.CONTINUE; 513 579 } … … 519 585 520 586 if (this.currentCount > count) { 521 // ignore this children of this node, as they may have only smaller counts than587 // ignore this children of this task, as they may have only smaller counts than 522 588 // the already found tasks 523 589 return TrieProcessor.Result.SKIP_NODE; … … 536 602 boolean added = false; 537 603 for (int i = 0; i < foundTasks.size(); i++) { 538 if (foundTasks.get(i).size() < task.size()) {604 if (foundTasks.get(i).size() < foundTask.size()) { 539 605 // defensive copy 540 foundTasks.add(i, new LinkedList<ITask TreeNode>(task)); // defensive copy606 foundTasks.add(i, new LinkedList<ITaskInstance>(foundTask)); // defensive copy 541 607 added = true; 542 608 break; … … 545 611 546 612 if (!added) { 547 foundTasks.add(new LinkedList<ITask TreeNode>(task)); // defensive copy613 foundTasks.add(new LinkedList<ITaskInstance>(foundTask)); // defensive copy 548 614 } 549 615 } … … 571 637 // found a task that is a potential subtask. Check for this and remove the 572 638 // subtask if needed 573 List<ITask TreeNode> longTask = foundTasks.get(i);574 List<ITask TreeNode> shortTask = foundTasks.get(j);639 List<ITaskInstance> longTask = foundTasks.get(i); 640 List<ITaskInstance> shortTask = foundTasks.get(j); 575 641 576 642 if (getSubListIndex(longTask, shortTask, 0) > -1) { … … 598 664 * 599 665 */ 600 private List<I Sequence> sessions;601 602 /** 603 * 604 */ 605 private Trie<ITask TreeNode> lastTrie;666 private List<IUserSession> sessions; 667 668 /** 669 * 670 */ 671 private Trie<ITaskInstance> lastTrie; 606 672 607 673 /** … … 618 684 * 619 685 */ 620 private List<ITaskTreeNode> taskOccurrences = new LinkedList<ITaskTreeNode>(); 621 622 /** 623 * 624 */ 625 private int replacementCounter; 686 private boolean detectedAndReplacedTasks; 626 687 627 688 /** … … 638 699 * 639 700 */ 640 private RuleApplicationData(List<I Sequence> sessions) {701 private RuleApplicationData(List<IUserSession> sessions) { 641 702 this.sessions = sessions; 642 703 } … … 645 706 * @return the tree 646 707 */ 647 private List<I Sequence> getSessions() {708 private List<IUserSession> getSessions() { 648 709 return sessions; 649 710 } … … 652 713 * @param lastTrie the lastTrie to set 653 714 */ 654 private void setLastTrie(Trie<ITask TreeNode> lastTrie) {715 private void setLastTrie(Trie<ITaskInstance> lastTrie) { 655 716 this.lastTrie = lastTrie; 656 717 } … … 659 720 * @return the lastTrie 660 721 */ 661 private Trie<ITask TreeNode> getLastTrie() {722 private Trie<ITaskInstance> getLastTrie() { 662 723 return lastTrie; 663 724 } … … 692 753 693 754 /** 694 * @return the taskOccurrences695 */696 private void clearTaskOccurrences() {697 taskOccurrences.clear();698 }699 700 /**701 * @return the taskOccurrences702 */703 private void addTaskOccurrence(ITaskTreeNode taskOccurrence) {704 taskOccurrences.add(taskOccurrence);705 }706 707 /**708 * @return the taskOccurrences709 */710 private List<ITaskTreeNode> getTaskOccurrences() {711 return taskOccurrences;712 }713 714 /**715 755 * 716 756 */ 717 private void resetReplacementCounter() {718 replacementCounter = 0;757 private void detectedAndReplacedTasks(boolean detectedAndReplacedTasks) { 758 this.detectedAndReplacedTasks = detectedAndReplacedTasks; 719 759 } 720 760 … … 722 762 * 723 763 */ 724 private void incrementReplacementCounter() { 725 replacementCounter++; 726 } 727 728 /** 729 * 730 */ 731 private int getReplacementCounter() { 732 return replacementCounter; 764 private boolean detectedAndReplacedTasks() { 765 return detectedAndReplacedTasks; 733 766 } 734 767 … … 753 786 * @author Patrick Harms 754 787 */ 755 private static class Tasks implements Iterable<List<ITask TreeNode>> {788 private static class Tasks implements Iterable<List<ITaskInstance>> { 756 789 757 790 /** … … 763 796 * 764 797 */ 765 private List<List<ITask TreeNode>> sequences;798 private List<List<ITaskInstance>> sequences; 766 799 767 800 /** … … 769 802 * @param sequences 770 803 */ 771 private Tasks(int occurrenceCount, List<List<ITask TreeNode>> sequences) {804 private Tasks(int occurrenceCount, List<List<ITaskInstance>> sequences) { 772 805 super(); 773 806 this.occurrenceCount = occurrenceCount; … … 797 830 */ 798 831 @Override 799 public Iterator<List<ITask TreeNode>> iterator() {832 public Iterator<List<ITaskInstance>> iterator() { 800 833 return this.sequences.iterator(); 801 834 } … … 803 836 } 804 837 838 /** 839 * 840 */ 841 private class TaskComparator implements SymbolComparator<ITaskInstance> { 842 843 /** */ 844 private Comparer comparer; 845 846 /** */ 847 private Comparer lexicalComparer; 848 849 /** */ 850 private HashMap<Long, Boolean> equalityBuffer = new HashMap<Long, Boolean>(); 851 852 /** */ 853 private HashMap<Long, Boolean> lexicalEqualityBuffer; 854 855 /** 856 * 857 */ 858 public TaskComparator(TaskEqualityRuleManager taskEqualityRuleManager, 859 TaskEquality minimalNodeEquality) 860 { 861 super(); 862 863 if (minimalNodeEquality == TaskEquality.LEXICALLY_EQUAL) { 864 comparer = new LexicalComparer(taskEqualityRuleManager); 865 } 866 else if (minimalNodeEquality == TaskEquality.SYNTACTICALLY_EQUAL) { 867 comparer = new SyntacticalComparer(taskEqualityRuleManager); 868 } 869 else if (minimalNodeEquality == TaskEquality.SEMANTICALLY_EQUAL) { 870 comparer = new SemanticalComparer(taskEqualityRuleManager); 871 } 872 else { 873 comparer = new DefaultComparer(taskEqualityRuleManager, minimalNodeEquality); 874 } 875 876 if (minimalNodeEquality == TaskEquality.LEXICALLY_EQUAL) { 877 lexicalComparer = comparer; 878 lexicalEqualityBuffer = equalityBuffer; 879 } 880 else { 881 lexicalComparer = new LexicalComparer(taskEqualityRuleManager); 882 lexicalEqualityBuffer = new HashMap<Long, Boolean>(); 883 } 884 } 885 886 /* (non-Javadoc) 887 * @see de.ugoe.cs.autoquest.tasktrees.temporalrelation.SymbolComparator#equals(java.lang.Object, java.lang.Object) 888 */ 889 @Override 890 public boolean equals(ITaskInstance taskInstance1, ITaskInstance taskInstance2) { 891 return equals(taskInstance1.getTask(), taskInstance2.getTask()); 892 } 893 894 /** 895 * 896 */ 897 public boolean equals(ITask task1, ITask task2) { 898 Boolean result; 899 900 if (task1 != task2) { 901 if ((task1 instanceof IEventTask) && (task2 instanceof IEventTask)) { 902 long key = ((long) System.identityHashCode(task1)) << 32; 903 key += System.identityHashCode(task2); 904 905 result = equalityBuffer.get(key); 906 907 if (result == null) { 908 result = comparer.compare(task1, task2); 909 equalityBuffer.put(key, result); 910 } 911 } 912 else { 913 result = false; 914 } 915 } 916 else { 917 result = true; 918 } 919 920 return result; 921 } 922 923 /** 924 * 925 */ 926 public boolean areLexicallyEqual(ITask task1, ITask task2) { 927 Boolean result; 928 929 if (task1 != task2) { 930 long key = ((long) System.identityHashCode(task1)) << 32; 931 key += System.identityHashCode(task2); 932 933 result = lexicalEqualityBuffer.get(key); 934 935 if (result == null) { 936 result = lexicalComparer.compare(task1, task2); 937 lexicalEqualityBuffer.put(key, result); 938 } 939 } 940 else { 941 result = true; 942 } 943 944 return result; 945 } 946 } 947 948 /** 949 * 950 */ 951 private interface Comparer { 952 953 /** 954 * 955 */ 956 boolean compare(ITask task1, ITask task2); 957 } 958 959 /** 960 * 961 */ 962 private class LexicalComparer implements Comparer { 963 964 /** 965 * <p> 966 * the task equality manager needed for comparing tasks with each other 967 * </p> 968 */ 969 private TaskEqualityRuleManager taskEqualityRuleManager; 970 971 /** 972 * 973 */ 974 public LexicalComparer(TaskEqualityRuleManager taskEqualityRuleManager) { 975 this.taskEqualityRuleManager = taskEqualityRuleManager; 976 } 977 978 /** 979 * 980 */ 981 public boolean compare(ITask task1, ITask task2) { 982 return taskEqualityRuleManager.areLexicallyEqual(task1, task2); 983 } 984 } 985 986 /** 987 * 988 */ 989 private class SyntacticalComparer implements Comparer { 990 991 /** 992 * <p> 993 * the task equality manager needed for comparing tasks with each other 994 * </p> 995 */ 996 private TaskEqualityRuleManager taskEqualityRuleManager; 997 998 /** 999 * 1000 */ 1001 public SyntacticalComparer(TaskEqualityRuleManager taskEqualityRuleManager) { 1002 this.taskEqualityRuleManager = taskEqualityRuleManager; 1003 } 1004 1005 /** 1006 * 1007 */ 1008 public boolean compare(ITask task1, ITask task2) { 1009 return taskEqualityRuleManager.areSyntacticallyEqual(task1, task2); 1010 } 1011 } 1012 1013 /** 1014 * 1015 */ 1016 private class SemanticalComparer implements Comparer { 1017 1018 /** 1019 * <p> 1020 * the task equality manager needed for comparing tasks with each other 1021 * </p> 1022 */ 1023 private TaskEqualityRuleManager taskEqualityRuleManager; 1024 1025 /** 1026 * 1027 */ 1028 public SemanticalComparer(TaskEqualityRuleManager taskEqualityRuleManager) { 1029 this.taskEqualityRuleManager = taskEqualityRuleManager; 1030 } 1031 1032 /** 1033 * 1034 */ 1035 public boolean compare(ITask task1, ITask task2) { 1036 return taskEqualityRuleManager.areSemanticallyEqual(task1, task2); 1037 } 1038 } 1039 1040 /** 1041 * 1042 */ 1043 private class DefaultComparer implements Comparer { 1044 1045 /** 1046 * <p> 1047 * the task equality manager needed for comparing tasks with each other 1048 * </p> 1049 */ 1050 private TaskEqualityRuleManager taskEqualityRuleManager; 1051 1052 /** 1053 * <p> 1054 * the minimal task equality two identified sublists need to have to consider them as equal 1055 * </p> 1056 */ 1057 private TaskEquality minimalNodeEquality; 1058 1059 /** 1060 * 1061 */ 1062 public DefaultComparer(TaskEqualityRuleManager taskEqualityRuleManager, 1063 TaskEquality minimalNodeEquality) 1064 { 1065 this.taskEqualityRuleManager = taskEqualityRuleManager; 1066 this.minimalNodeEquality = minimalNodeEquality; 1067 } 1068 1069 /** 1070 * 1071 */ 1072 public boolean compare(ITask task1, ITask task2) { 1073 return taskEqualityRuleManager.areAtLeastEqual(task1, task2, minimalNodeEquality); 1074 } 1075 } 805 1076 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TemporalRelationshipRuleManager.java
r1131 r1146 22 22 import de.ugoe.cs.autoquest.eventcore.guimodel.IFrame; 23 23 import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; 24 import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEquality; 25 import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEqualityRuleManager; 26 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder; 27 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 28 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNodeFactory; 24 import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality; 25 import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEqualityRuleManager; 26 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; 27 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; 28 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 29 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; 30 import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 29 31 import de.ugoe.cs.util.console.Console; 30 32 31 33 /** 34 * TODO update comment 35 * 32 36 * <p> 33 37 * This class is responsible for applying temporal relationship rules on a task tree. Through this, 34 38 * a flat task tree is restructured to have more depth but to include more temporal relationships 35 * between task tree nodes which are not only a major sequence. I.e. through the application of36 * rule iterations and selections of task tree nodes are detected. Which kind of temporal relations37 * between task tree nodes are detected depends on the {@link TemporalRelationshipRule}s known to39 * between tasks which are not only a major sequence. I.e. through the application of the 40 * rules iterations and selections of tasks are detected. Which kind of temporal relations 41 * between tasks are detected depends on the {@link ITaskInstanceListScopeRule}s known to 38 42 * this class. 39 43 * </p> 40 * <p>The class holds references to the appropriate {@link TemporalRelationshipRule}s and calls41 * their {@link TemporalRelationshipRule#apply(ITaskTreeNode, ITaskTreeBuilder, ITaskTreeNodeFactory, boolean)}42 * method for each nodein the task tree it is needed for. The general behavior of this class is44 * <p>The class holds references to the appropriate {@link ITaskInstanceListScopeRule}s and calls 45 * their {@link ITaskInstanceListScopeRule#apply(ITask, ITaskBuilder, ITaskFactory, boolean)} 46 * method for each task in the task tree it is needed for. The general behavior of this class is 43 47 * the following: 44 48 * <ol> … … 48 52 * </li> 49 53 * <li> 50 * then the {@link #applyRules(ITask TreeNode, ITaskTreeBuilder, ITaskTreeNodeFactory, boolean)}51 * method is called for a so far unstructured task tree node54 * then the {@link #applyRules(ITask, ITaskBuilder, ITaskFactory, boolean)} 55 * method is called for a so far unstructured task 52 56 * </li> 53 57 * <li> 54 58 * the class iterates its internal list of rules and calls their 55 * {@link TemporalRelationshipRule#apply(ITaskTreeNode, ITaskTreeBuilder, ITaskTreeNodeFactory, boolean)}59 * {@link ITaskInstanceListScopeRule#apply(ITask, ITaskBuilder, ITaskFactory, boolean)} 56 60 * method. 57 61 * </li> … … 69 73 * <li> 70 74 * if a rule returns, that it was applied, the same rule is applied again until it returns 71 * null or feasible. For each newly created parent nodeprovided in the rule application72 * result, the {@link #applyRules(ITask TreeNode, ITaskTreeBuilder, ITaskTreeNodeFactory, boolean)}75 * null or feasible. For each newly created parent task provided in the rule application 76 * result, the {@link #applyRules(ITask, ITaskBuilder, ITaskFactory, boolean)} 73 77 * method is called. 74 78 * </li> … … 76 80 * </li> 77 81 * </ol> 78 * Through this, all rules are tried to be applied at least once to the provided parent nodeand79 * all parent nodes created during the rule application.82 * Through this, all rules are tried to be applied at least once to the provided parent task and 83 * all parent tasks created during the rule application. 80 84 * </p> 81 85 * … … 86 90 /** 87 91 * <p> 88 * the node equality manager needed by the rules to compare task tree nodes with each other 89 * </p> 90 */ 91 private NodeEqualityRuleManager nodeEqualityRuleManager; 92 93 /** 94 * <p> 95 * the task tree node factory to be used during rule application 96 * </p> 97 */ 98 private ITaskTreeNodeFactory taskTreeNodeFactory; 99 100 /** 101 * <p> 102 * the task tree builder to be used during rule application 103 * </p> 104 */ 105 private ITaskTreeBuilder taskTreeBuilder; 92 * the task equality manager needed by the rules to compare tasks with each other 93 * </p> 94 */ 95 private TaskEqualityRuleManager taskEqualityRuleManager; 96 97 /** 98 * <p> 99 * the task factory to be used during rule application 100 * </p> 101 */ 102 private ITaskFactory taskFactory; 103 104 /** 105 * <p> 106 * the task builder to be used during rule application 107 * </p> 108 */ 109 private ITaskBuilder taskBuilder; 110 111 /** 112 * <p> 113 * the temporal relationship rules known to the manager that are executed on whole sessions. 114 * The rules are applied in the order they occur in this list. 115 * </p> 116 */ 117 private ISessionScopeRule[] sessionScopeRules; 106 118 107 119 /** … … 111 123 * </p> 112 124 */ 113 private TemporalRelationshipRule[] treeScopeRules; 114 115 /** 116 * <p> 117 * the temporal relationship rules known to the manager that are executed on whole sub trees. 118 * The rules are applied in the order they occur in this list. 119 * </p> 120 */ 121 private TemporalRelationshipRule[] nodeScopeRules; 125 private ITaskInstanceListScopeRule[] taskScopeRules; 122 126 123 127 /** … … 126 130 * </p> 127 131 * 128 * @param nodeEqualityRuleManager the nodeequality rule manager to be used by the known rules129 * for task tree nodecomparison during rule application130 * @param task TreeNodeFactory the nodefactory to be used for instantiating new task tree131 * nodes during rule application132 * @param task TreeBuilder the task tree builder to be used for linking task tree nodes132 * @param taskEqualityRuleManager the task equality rule manager to be used by the known rules 133 * for task comparison during rule application 134 * @param taskFactory the task factory to be used for instantiating new task tree 135 * tasks during rule application 136 * @param taskBuilder the task builder to be used for linking tasks 133 137 * with each other during rule application 134 138 */ 135 public TemporalRelationshipRuleManager( NodeEqualityRuleManager nodeEqualityRuleManager,136 ITask TreeNodeFactory taskTreeNodeFactory,137 ITask TreeBuilder taskTreeBuilder)139 public TemporalRelationshipRuleManager(TaskEqualityRuleManager taskEqualityRuleManager, 140 ITaskFactory taskFactory, 141 ITaskBuilder taskBuilder) 138 142 { 139 143 super(); 140 this. nodeEqualityRuleManager = nodeEqualityRuleManager;141 this.task TreeNodeFactory = taskTreeNodeFactory;142 this.task TreeBuilder = taskTreeBuilder;144 this.taskEqualityRuleManager = taskEqualityRuleManager; 145 this.taskFactory = taskFactory; 146 this.taskBuilder = taskBuilder; 143 147 } 144 148 … … 146 150 * <p> 147 151 * initialized the temporal relationship rule manager by instantiating the known rules and 148 * providing them with a reference to the nodeequality manager or other information they need.152 * providing them with a reference to the task equality manager or other information they need. 149 153 * </p> 150 154 */ … … 156 160 //frameFilter.add(ICanvas.class); 157 161 158 treeScopeRules = new TemporalRelationshipRule[] {162 sessionScopeRules = new ISessionScopeRule[] { 159 163 new SequenceForTaskDetectionRule 160 ( nodeEqualityRuleManager, NodeEquality.SEMANTICALLY_EQUAL,161 task TreeNodeFactory, taskTreeBuilder),164 (taskEqualityRuleManager, TaskEquality.SEMANTICALLY_EQUAL, 165 taskFactory, taskBuilder), 162 166 /*new DefaultTaskSequenceDetectionRule 163 ( nodeEqualityRuleManager, NodeEquality.SYNTACTICALLY_EQUAL,164 task TreeNodeFactory, taskTreeBuilder),167 (taskEqualityRuleManager, NodeEquality.SYNTACTICALLY_EQUAL, 168 taskFactory, taskTreeBuilder), 165 169 new DefaultTaskSequenceDetectionRule 166 ( nodeEqualityRuleManager, NodeEquality.LEXICALLY_EQUAL,167 task TreeNodeFactory, taskTreeBuilder),*/170 (taskEqualityRuleManager, NodeEquality.LEXICALLY_EQUAL, 171 taskFactory, taskTreeBuilder),*/ 168 172 /*new TreeScopeWrapperRule 169 173 (new DefaultIterationDetectionRule 170 ( nodeEqualityRuleManager, NodeEquality.LEXICALLY_EQUAL,171 task TreeNodeFactory, taskTreeBuilder)),174 (taskEqualityRuleManager, NodeEquality.LEXICALLY_EQUAL, 175 taskFactory, taskTreeBuilder)), 172 176 new TreeScopeWrapperRule 173 177 (new DefaultIterationDetectionRule 174 ( nodeEqualityRuleManager, NodeEquality.SYNTACTICALLY_EQUAL,175 task TreeNodeFactory, taskTreeBuilder)),178 (taskEqualityRuleManager, NodeEquality.SYNTACTICALLY_EQUAL, 179 taskFactory, taskTreeBuilder)), 176 180 new TreeScopeWrapperRule 177 181 (new DefaultIterationDetectionRule 178 ( nodeEqualityRuleManager, NodeEquality.SEMANTICALLY_EQUAL,179 task TreeNodeFactory, taskTreeBuilder))*/182 (taskEqualityRuleManager, NodeEquality.SEMANTICALLY_EQUAL, 183 taskFactory, taskTreeBuilder))*/ 180 184 }; 181 185 182 186 //treeScopeRules.add(new DefaultGuiElementSequenceDetectionRule(frameFilter)); 183 187 184 nodeScopeRules = new TemporalRelationshipRule[] { 185 //new SequenceOnGuiElementDetectionRule(taskTreeNodeFactory, taskTreeBuilder), 186 //new EventSequenceOnSameTargetDetectionRule(taskTreeNodeFactory, taskTreeBuilder), 187 new TrackBarSelectionDetectionRule 188 (nodeEqualityRuleManager, taskTreeNodeFactory, taskTreeBuilder), 189 //new DefaultGuiEventSequenceDetectionRule(taskTreeNodeFactory, taskTreeBuilder), 188 taskScopeRules = new ITaskInstanceListScopeRule[] { 189 //new SequenceOnGuiElementDetectionRule(taskFactory, taskTreeBuilder), 190 //new EventSequenceOnSameTargetDetectionRule(taskFactory, taskTreeBuilder), 191 //new TrackBarSelectionDetectionRule(taskEqualityRuleManager, taskFactory, taskBuilder), 192 //new DefaultGuiEventSequenceDetectionRule(taskFactory, taskTreeBuilder), 190 193 }; 191 194 … … 194 197 /** 195 198 * <p> 196 * applies the known rules to the provided parent node. For the creation of further nodes,197 * the provided builder and node factory are utilized. The method expectes, that no more data199 * applies the known rules to the provided sessions. For the creation of further tasks, 200 * the provided builder and task factory are utilized. The method expects, that no more data 198 201 * is available and, therefore, finalizes the rule application. 199 202 * </p> 200 203 * 201 * @param nodeFactory the node factory to be used for instantiating new task tree nodes.202 */ 203 public void applyRules( ITaskTreeNode parent) {204 applyRules( parent, true);205 } 206 207 /** 208 * <p> 209 * applies the known rules to the provided parent node. For the creation of further nodes,210 * the provided builder and nodefactory are utilized. If the finalize parameter is true, the204 * @param taskFactory the task factory to be used for instantiating new tasks. 205 */ 206 public void applyRules(List<IUserSession> sessions) { 207 applyRules(sessionScopeRules, sessions, ""); 208 } 209 210 /** 211 * <p> 212 * applies the known rules to the provided parent task. For the creation of further tasks, 213 * the provided builder and task factory are utilized. If the finalize parameter is true, the 211 214 * rule application is finalized as far as possible without waiting for further data. If it is 212 215 * false, the rule application is broken up at the first rule returning, that its application 213 * would be feasible. 216 * would be feasible. The method calls itself for each parent task created through the rule 217 * application. In this case, the finalize parameter is always true. 214 218 * </p> 215 219 * 216 * @param parent the parent node to apply the rules on 217 * @param finalize used to indicate, if the rule application shall break up if a rule would 218 * be feasible if further data was available, or not. 219 */ 220 public void applyRules(ITaskTreeNode parent, boolean finalize) { 221 applyRules(treeScopeRules, parent, finalize, ""); 222 } 223 224 /** 225 * <p> 226 * applies the known rules to the provided parent node. For the creation of further nodes, 227 * the provided builder and node factory are utilized. If the finalize parameter is true, the 228 * rule application is finalized as far as possible without waiting for further data. If it is 229 * false, the rule application is broken up at the first rule returning, that its application 230 * would be feasible. The method calls itself for each parent node created through the rule 231 * application. In this case, the finalize parameter is always true. 232 * </p> 233 * 234 * @param parent the parent node to apply the rules on 220 * @param parent the parent task to apply the rules on 235 221 * @param finalize used to indicate, if the rule application shall break up if a rule would 236 222 * be feasible if further data was available, or not. … … 238 224 * on the recursion depth of calling this method. 239 225 */ 240 private int applyRules(TemporalRelationshipRule[] rules, 241 ITaskTreeNode parent, 242 boolean finalize, 243 String logIndent) 226 private int applyRules(ISessionScopeRule[] rules, 227 List<IUserSession> sessions, 228 String logIndent) 244 229 { 245 Console.traceln(Level.FINER, logIndent + "applying rules for " + parent); 230 Console.traceln 231 (Level.FINER, logIndent + "applying rules for " + sessions.size() + " sessions"); 246 232 247 233 int noOfRuleApplications = 0; 248 234 249 for ( TemporalRelationshipRule rule : rules) {235 for (ISessionScopeRule rule : rules) { 250 236 RuleApplicationResult result; 251 237 do { 252 Console.traceln(Level.FINER, logIndent + "trying rule " + rule + " on " + parent);253 result = rule.apply( parent, finalize);238 Console.traceln(Level.FINER, logIndent + "trying rule " + rule); 239 result = rule.apply(sessions); 254 240 255 241 if ((result != null) && 256 242 (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED)) 257 243 { 258 Console.traceln 259 (Level.FINE, logIndent + "applied rule " + rule + " on " + parent); 244 Console.traceln(Level.FINE, logIndent + "applied rule " + rule); 260 245 noOfRuleApplications++; 261 246 262 247 //dumpTask(parent, ""); 263 248 264 for (ITask TreeNode newParent : result.getNewlyCreatedParentNodes()) {249 for (ITaskInstance newParent : result.getNewlyCreatedTaskInstances()) { 265 250 noOfRuleApplications += 266 applyRules( nodeScopeRules, newParent, true, logIndent + " ");251 applyRules(taskScopeRules, newParent, logIndent + " "); 267 252 } 268 253 } … … 271 256 (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED)); 272 257 273 if ((!finalize) &&274 (result != null) &&275 (result.getRuleApplicationStatus() == RuleApplicationStatus.FEASIBLE))276 {277 // in this case, don't go on applying rules, which should not be applied yet278 break;279 }280 258 } 281 259 … … 289 267 290 268 /** 269 * <p> 270 * applies the known rules to the provided parent task. For the creation of further tasks, 271 * the provided builder and task factory are utilized. If the finalize parameter is true, the 272 * rule application is finalized as far as possible without waiting for further data. If it is 273 * false, the rule application is broken up at the first rule returning, that its application 274 * would be feasible. The method calls itself for each parent task created through the rule 275 * application. In this case, the finalize parameter is always true. 276 * </p> 277 * 278 * @param parent the parent task to apply the rules on 279 * @param finalize used to indicate, if the rule application shall break up if a rule would 280 * be feasible if further data was available, or not. 281 * @param logIndent simply used for logging purposes to indent the log messages depending 282 * on the recursion depth of calling this method. 283 */ 284 private int applyRules(ITaskInstanceListScopeRule[] rules, 285 ITaskInstanceList taskInstances, 286 String logIndent) 287 { 288 Console.traceln(Level.FINER, logIndent + "applying rules for " + taskInstances.size() + 289 " task instances"); 290 291 int noOfRuleApplications = 0; 292 293 for (ITaskInstanceListScopeRule rule : rules) { 294 RuleApplicationResult result; 295 do { 296 Console.traceln 297 (Level.FINER, logIndent + "trying rule " + rule + " on " + taskInstances); 298 result = rule.apply(taskInstances); 299 300 if ((result != null) && 301 (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED)) 302 { 303 Console.traceln 304 (Level.FINE, logIndent + "applied rule " + rule + " on " + taskInstances); 305 noOfRuleApplications++; 306 307 //dumpTask(parent, ""); 308 309 for (ITaskInstance newParent : result.getNewlyCreatedTaskInstances()) { 310 noOfRuleApplications += 311 applyRules(taskScopeRules, newParent, logIndent + " "); 312 } 313 } 314 } 315 while ((result != null) && 316 (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED)); 317 } 318 319 if (noOfRuleApplications <= 0) { 320 Console.traceln(Level.FINE, logIndent + "no rules applied --> no temporal " + 321 "relationship generated"); 322 } 323 324 return noOfRuleApplications; 325 } 326 327 /** 291 328 * 292 329 */ 293 /*private void dumpTask(ITask TreeNodetask, String indent) {330 /*private void dumpTask(ITask task, String indent) { 294 331 StringBuffer message = new StringBuffer(); 295 332 message.append(indent); … … 304 341 305 342 if ((task.getChildren() != null) && (task.getChildren().size() > 0)) { 306 for (ITask TreeNodechild : task.getChildren()) {343 for (ITask child : task.getChildren()) { 307 344 dumpTask(child, indent + " "); 308 345 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeifc/IEventTask.java
r1114 r1146 24 24 * @author 2011, last modified by $Author: $ 25 25 */ 26 public interface IEventTask extends ITask TreeNode{26 public interface IEventTask extends ITask { 27 27 28 28 /** -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeifc/IIteration.java
r1114 r1146 21 21 * @author 2012, last modified by $Author: patrick$ 22 22 */ 23 public interface IIteration extends I TemporalRelationship {23 public interface IIteration extends IMarkingTemporalRelationship { 24 24 25 25 /** -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeifc/IOptional.java
r1126 r1146 21 21 * @author 2012, last modified by $Author: patrick$ 22 22 */ 23 public interface IOptional extends I TemporalRelationship {23 public interface IOptional extends IMarkingTemporalRelationship { 24 24 25 25 /** -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeifc/ISelection.java
r1114 r1146 21 21 * @author 2012, last modified by $Author: patrick$ 22 22 */ 23 public interface ISelection extends I TemporalRelationship {23 public interface ISelection extends IStructuringTemporalRelationship { 24 24 25 25 /** -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeifc/ISequence.java
r1114 r1146 21 21 * @author 2012, last modified by $Author: patrick$ 22 22 */ 23 public interface ISequence extends I TemporalRelationship {23 public interface ISequence extends IStructuringTemporalRelationship { 24 24 25 25 /** -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeifc/ITaskBuilder.java
r1126 r1146 21 21 * @author 2012, last modified by $Author: patrick$ 22 22 */ 23 public interface ITask TreeBuilder {23 public interface ITaskBuilder { 24 24 25 25 /** 26 * 26 * @param taskInstance 27 * @param child 27 28 */ 28 void addChild(I Sequence parent, ITaskTreeNode child);29 void addChild(ITaskInstance taskInstance, ITaskInstance child) throws IllegalArgumentException; 29 30 30 31 /** 32 * <p> 33 * TODO: comment 34 * </p> 31 35 * 36 * @param session 37 * @param taskInstance 32 38 */ 33 void add Child(ISequence parent, int index, ITaskTreeNode child);39 void addExecutedTask(IUserSession session, ITaskInstance taskInstance); 34 40 35 41 /** … … 38 44 * @param i 39 45 */ 40 void setChild(ISequence parent, int index, ITaskTreeNode child); 46 void addTaskInstance(ITaskInstanceList taskInstanceList, ITaskInstance taskInstance); 47 48 /** 49 * 50 * @param parent 51 * @param i 52 */ 53 void addTaskInstance(ITaskInstanceList taskInstanceList, int index, ITaskInstance taskInstance); 54 55 /** 56 * 57 * @param parent 58 * @param i 59 */ 60 void setTaskInstance(ITaskInstanceList taskInstanceList, int index, ITaskInstance taskInstance); 61 62 /** 63 * <p> 64 * TODO: comment 65 * </p> 66 * 67 * @param instance2 68 * @param task 69 */ 70 void setTask(ITaskInstance taskInstance, ITask task); 71 72 /** 73 * 74 */ 75 void addChild(ISequence parent, ITask child); 76 77 /** 78 * 79 */ 80 void addChild(ISequence parent, int index, ITask child); 81 82 /** 83 * 84 * @param parent 85 * @param i 86 */ 87 void setChild(ISequence parent, int index, ITask child); 41 88 42 89 /** … … 44 91 * @param task 45 92 */ 46 void addChild(ISelection parent, ITask TreeNodechild);93 void addChild(ISelection parent, ITask child); 47 94 48 95 /** … … 51 98 * @param newChild 52 99 */ 53 void set Child(IIteration iteration, ITaskTreeNodenewChild);100 void setMarkedTask(IIteration iteration, ITask newChild); 54 101 55 102 /** … … 58 105 * @param newChild 59 106 */ 60 void set Child(IOptional optional, ITaskTreeNodenewChild);107 void setMarkedTask(IOptional optional, ITask newChild); 61 108 62 109 /** … … 72 119 * @param i 73 120 */ 74 void removeChild(ISelection parent, ITaskTreeNode child); 121 void removeChild(ISelection parent, ITask child); 122 123 /** 124 * 125 * @param parent 126 * @param i 127 */ 128 void removeTaskInstance(ITaskInstanceList taskInstanceList, int index); 75 129 76 130 /** … … 79 133 * @param i 80 134 */ 81 void replaceChild(ISelection parent, ITask TreeNode oldChild, ITaskTreeNodenewChild);135 void replaceChild(ISelection parent, ITask oldChild, ITask newChild); 82 136 83 137 /** … … 86 140 * @param i 87 141 */ 88 void setDescription(ITask TreeNode node, String description);142 void setDescription(ITask task, String description); 89 143 90 144 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeifc/ITaskFactory.java
r1126 r1146 15 15 package de.ugoe.cs.autoquest.tasktrees.treeifc; 16 16 17 import java.util.List; 18 17 19 import de.ugoe.cs.autoquest.eventcore.IEventTarget; 18 20 import de.ugoe.cs.autoquest.eventcore.IEventType; … … 24 26 * @author 2012, last modified by $Author: patrick$ 25 27 */ 26 public interface ITaskTreeNodeFactory 27 { 28 public interface ITaskFactory { 28 29 29 /**30 *31 * @param eventType32 * @param eventTarget33 * @return34 */35 IEventTask createNewEventTask(IEventType eventType, IEventTarget eventTarget);30 /** 31 * 32 * @param eventType 33 * @param eventTarget 34 * @return 35 */ 36 IEventTask createNewEventTask(IEventType eventType, IEventTarget eventTarget); 36 37 37 /**38 *39 * @return40 */41 ISequence createNewSequence();38 /** 39 * 40 * @return 41 */ 42 ISequence createNewSequence(); 42 43 43 /**44 *45 * @return46 */47 IIteration createNewIteration();44 /** 45 * 46 * @return 47 */ 48 IIteration createNewIteration(); 48 49 49 /**50 *51 * @return52 */53 IOptional createNewOptional();50 /** 51 * 52 * @return 53 */ 54 IOptional createNewOptional(); 54 55 55 /**56 *57 * @return58 */59 ISelection createNewSelection();56 /** 57 * 58 * @return 59 */ 60 ISelection createNewSelection(); 60 61 61 /** 62 * 63 * @param rootSequence 64 * @return 65 */ 66 ITaskTree createTaskTree(ITaskTreeNode root); 62 /** 63 * 64 * @return 65 */ 66 ITaskInstance createNewTaskInstance(ITask task); 67 68 /** 69 * 70 * @return 71 */ 72 ITaskInstanceList createNewTaskInstanceList(); 73 74 /** 75 * 76 * @return 77 */ 78 IUserSession createUserSession(); 79 80 /** 81 * 82 * @param rootSequence 83 * @return 84 */ 85 ITaskModel createTaskModel(List<IUserSession> userSessions); 67 86 68 87 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeifc/ITaskInstance.java
r1113 r1146 23 23 * @author 2011, last modified by $Author: $ 24 24 */ 25 public interface ITask TreeNode extends Cloneable{25 public interface ITaskInstance extends ITaskInstanceList { 26 26 27 27 /** 28 28 * 29 29 */ 30 public String getName();30 public List<ITaskInstance> getChildren(); 31 31 32 32 /** 33 33 * 34 34 */ 35 public String getDescription();35 public ITask getTask(); 36 36 37 37 /** 38 38 * 39 39 */ 40 public List<ITaskTreeNode> getChildren(); 41 42 /** 43 * 44 */ 45 public boolean equals(ITaskTreeNode taskTreeNode); 40 public boolean equals(ITaskInstance taskInstance); 46 41 47 42 /** … … 53 48 * 54 49 */ 55 public ITask TreeNode clone();56 50 public ITaskInstance clone(); 51 57 52 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeifc/ITaskModel.java
r1114 r1146 15 15 package de.ugoe.cs.autoquest.tasktrees.treeifc; 16 16 17 import java.util.Map; 17 import java.io.Serializable; 18 import java.util.Collection; 19 import java.util.List; 18 20 19 21 /** … … 23 25 * @author 2012, last modified by $Author: patrick$ 24 26 */ 25 public interface ITask Tree extends Cloneable {27 public interface ITaskModel extends Cloneable, Serializable { 26 28 27 29 /** 28 30 * 29 31 */ 30 public ITaskTreeNode getRoot();32 public List<IUserSession> getUserSessions(); 31 33 32 34 /** 33 35 * 34 36 */ 35 public Map<ITaskTreeNode, ITaskTreeNodeInfo> getTaskMap();37 public Collection<ITask> getTasks(); 36 38 37 39 /** 38 40 * 39 41 */ 40 public ITaskTree clone(); 42 public ITaskInfo getTaskInfo(ITask task); 43 44 /** 45 * 46 */ 47 public ITaskModel clone(); 41 48 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeifc/ITemporalRelationship.java
r1113 r1146 21 21 * @author 2012, last modified by $Author: patrick$ 22 22 */ 23 public interface ITemporalRelationship extends ITask TreeNode{23 public interface ITemporalRelationship extends ITask { 24 24 25 25 /** -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/EventTask.java
r1126 r1146 18 18 import de.ugoe.cs.autoquest.eventcore.IEventType; 19 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;21 20 22 21 /** … … 26 25 * @author 2011, last modified by $Author: $ 27 26 */ 28 public class EventTask extends TaskTreeNodeimplements IEventTask {27 class EventTask extends Task implements IEventTask { 29 28 29 /** */ 30 private static final long serialVersionUID = 1L; 31 30 32 /** */ 31 33 private IEventType eventType; … … 39 41 */ 40 42 EventTask(IEventType eventType, IEventTarget eventTarget) { 41 super(eventType.toString()); 42 super.setDescription("executed on " + eventTarget); 43 super.setDescription(eventType.toString() + " executed on " + eventTarget); 43 44 this.eventType = eventType; 44 45 this.eventTarget = eventTarget; … … 62 63 * (non-Javadoc) 63 64 * 64 * @see de.harms.ctte.Task#equals(de.harms.ctte.Task)65 */66 @Override67 public boolean equals(ITaskTreeNode task) {68 if (!(task instanceof IEventTask)) {69 return false;70 }71 72 IEventType otherType = ((IEventTask) task).getEventType();73 IEventTarget otherTarget = ((IEventTask) task).getEventTarget();74 75 if (((eventType == otherType) ||76 ((eventType != null) && (eventType.equals(otherType)))) &&77 ((eventTarget == otherTarget) ||78 ((eventTarget != null) && (eventTarget.equals(otherTarget)))))79 {80 return true;81 }82 83 return false;84 }85 86 /*87 * (non-Javadoc)88 *89 65 * @see de.harms.tasktrees.TreeNode#clone() 90 66 */ -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/Iteration.java
r1126 r1146 16 16 17 17 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 18 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 18 import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 19 20 20 21 /** … … 24 25 * @author 2012, last modified by $Author: patrick$ 25 26 */ 26 public class Iteration extends TaskTreeNode implements IIteration { 27 class Iteration extends MarkingTemporalRelationship implements IIteration { 28 29 /** */ 30 private static final long serialVersionUID = 1L; 27 31 28 32 /** … … 30 34 */ 31 35 Iteration() { 32 super(" Iteration");36 super("iteration"); 33 37 } 34 38 35 /* 36 * (non-Javadoc) 37 * 38 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNode#addChild(TaskTreeNode) 39 /* (non-Javadoc) 40 * @see MarkingTemporalRelationship#setMarkedTask(ITask) 39 41 */ 40 42 @Override 41 public void addChild(ITaskTreeNode child) { 42 // adding more children is not allowed 43 throw new UnsupportedOperationException 44 ("iterations may not have a list of children. Use setChild() instead."); 45 } 46 47 /** 48 * TODO: comment 49 * 50 * @param selection 51 * @return 52 */ 53 public void setChild(ITaskTreeNode child) { 54 if (super.getChildren().size() > 0) { 55 super.removeChild(0); 43 protected void setMarkedTask(ITask markedTask) { 44 if (markedTask instanceof IIteration) { 45 throw new IllegalArgumentException 46 ("the marked task of an iteration must not be an iteration"); 56 47 } 57 super.addChild(child); 48 else if (markedTask instanceof IOptional) { 49 throw new IllegalArgumentException 50 ("the marked task of an iteration must not be an optional"); 51 } 52 53 super.setMarkedTask(markedTask); 58 54 } 59 55 -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/Optional.java
r1126 r1146 16 16 17 17 import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 18 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask TreeNode;18 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 19 19 20 20 /** … … 24 24 * @author 2012, last modified by $Author: patrick$ 25 25 */ 26 public class Optional extends TaskTreeNode implements IOptional { 26 class Optional extends MarkingTemporalRelationship implements IOptional { 27 28 /** */ 29 private static final long serialVersionUID = 1L; 27 30 28 31 /** … … 30 33 */ 31 34 Optional() { 32 super(" Optional");35 super("optionality"); 33 36 } 34 35 /* 36 * (non-Javadoc) 37 * 38 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNode#addChild(TaskTreeNode) 37 38 /* (non-Javadoc) 39 * @see MarkingTemporalRelationship#setMarkedTask(ITask) 39 40 */ 40 41 @Override 41 public void addChild(ITaskTreeNode child) { 42 // adding more children is not allowed 43 throw new UnsupportedOperationException 44 ("optionalities may not have a list of children. Use setChild() instead."); 45 } 46 47 /** 48 * TODO: comment 49 * 50 * @param selection 51 * @return 52 */ 53 public void setChild(ITaskTreeNode child) { 54 if (super.getChildren().size() > 0) { 55 super.removeChild(0); 42 protected void setMarkedTask(ITask markedTask) { 43 if (markedTask instanceof IOptional) { 44 throw new IllegalArgumentException 45 ("the marked task of an optional must not be an optional"); 56 46 } 57 super.addChild(child); 47 48 super.setMarkedTask(markedTask); 58 49 } 59 50 … … 67 58 return (Optional) super.clone(); 68 59 } 69 70 60 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/Selection.java
r1113 r1146 16 16 17 17 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 18 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 18 19 19 20 /** … … 23 24 * @author 2012, last modified by $Author: patrick$ 24 25 */ 25 public class Selection extends TaskTreeNode implements ISelection { 26 class Selection extends StructuringTemporalRelationship implements ISelection { 27 28 /** */ 29 private static final long serialVersionUID = 1L; 26 30 27 31 /** … … 31 35 */ 32 36 Selection() { 33 super(" Selection");37 super("selection"); 34 38 } 35 39 … … 44 48 } 45 49 50 /** 51 * <p> 52 * TODO: comment 53 * </p> 54 * 55 * @param i 56 * @param newChild 57 */ 58 public void addChild(ITask newChild) { 59 super.addChild(newChild); 60 super.setDescription("selection of " + newChild); 61 } 62 63 /** 64 * <p> 65 * TODO: comment 66 * </p> 67 * 68 * @param i 69 * @param newChild 70 */ 71 public void addChild(int index, ITask newChild) { 72 super.addChild(index, newChild); 73 super.setDescription("selection of " + newChild); 74 } 75 46 76 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/Sequence.java
r1113 r1146 23 23 * @author 2012, last modified by $Author: patrick$ 24 24 */ 25 public class Sequence extends TaskTreeNodeimplements ISequence {25 class Sequence extends StructuringTemporalRelationship implements ISequence { 26 26 27 /** */ 28 private static final long serialVersionUID = 1L; 29 27 30 /** 28 31 * TODO: comment … … 31 34 */ 32 35 Sequence() { 33 super("Sequence"); 34 } 35 36 /** 37 * TODO: comment 38 * 39 * @param name 40 */ 41 Sequence(String name) { 42 super(name); 36 super("sequence"); 43 37 } 44 38 -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/Task.java
r1126 r1146 15 15 package de.ugoe.cs.autoquest.tasktrees.treeimpl; 16 16 17 import java.util.Collections; 18 import java.util.LinkedList; 19 import java.util.List; 20 21 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 17 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 22 18 23 19 /** … … 27 23 * @author 2011, last modified by $Author: $ 28 24 */ 29 public class TaskTreeNode implements ITaskTreeNode { 25 class Task implements ITask { 26 27 /** */ 28 private static final long serialVersionUID = 1L; 29 30 30 /** */ 31 31 private static int temporalId = 0; 32 32 33 33 /** */ 34 private String name;34 private int id; 35 35 36 36 /** */ 37 37 private String description; 38 38 39 /** */40 private int id;41 42 /** children */43 private List<ITaskTreeNode> children;44 45 39 /** 46 40 * 47 41 */ 48 public TaskTreeNode(String name) { 49 this.name = name; 42 Task() { 50 43 id = getNewId(); 51 44 } … … 67 60 * @return Returns the name. 68 61 */ 69 public String getName() {70 return name;62 public int getId() { 63 return id; 71 64 } 72 65 … … 81 74 } 82 75 83 /**84 *85 */86 public synchronized List<ITaskTreeNode> getChildren() {87 if ((children == null) || (children.size() == 0)) {88 return new LinkedList<ITaskTreeNode>();89 }90 91 return Collections.unmodifiableList(children);92 }93 94 76 /* 95 77 * (non-Javadoc) … … 98 80 */ 99 81 @Override 100 public boolean equals(ITaskTreeNode taskTreeNode) { 101 if (!this.getClass().isInstance(taskTreeNode)) { 102 return false; 103 } 104 105 if (taskTreeNode.hashCode() != hashCode()) { 106 return false; 107 } 108 109 TaskTreeNode other = (TaskTreeNode) taskTreeNode; 110 111 if (id != other.id) { 112 return false; 113 } 114 115 if (!name.equals(other.name)) { 116 return false; 117 } 118 119 synchronized (other) { 120 if (children == null) { 121 return (other.children == null); 122 } 123 else if (other.children == null) { 124 return (children == null); 125 } 126 else if (other.children.size() != children.size()) { 127 return false; 128 } 129 130 for (int i = 0; i < children.size(); i++) { 131 if (!children.get(i).equals(other.children.get(i))) { 132 return false; 133 } 134 } 135 } 136 137 return true; 82 public final boolean equals(ITask task) { 83 // tasks are only equal if they are identical or if they have the same id 84 // (may happen, if they are cloned) 85 return (this == task) || (this.hashCode() == task.hashCode()); 138 86 } 139 87 … … 145 93 @Override 146 94 public synchronized int hashCode() { 147 return getClass().getSimpleName().hashCode();95 return id; 148 96 } 149 97 … … 156 104 public synchronized String toString() { 157 105 StringBuffer result = new StringBuffer(); 158 result.append(name); 159 result.append('('); 106 result.append("task "); 160 107 result.append(id); 161 108 162 109 if (description != null) { 163 result.append(" ,");110 result.append(" ("); 164 111 result.append(description); 112 result.append(')'); 165 113 } 166 114 167 if (children != null) { 168 result.append(", "); 169 result.append(children.size()); 170 result.append(" children"); 115 return result.toString(); 116 } 117 118 /* 119 * (non-Javadoc) 120 * 121 * @see java.lang.Object#clone() 122 */ 123 @Override 124 public synchronized ITask clone() { 125 Task clone = null; 126 try { 127 clone = (Task) super.clone(); 171 128 } 172 173 result.append(')'); 174 return result.toString(); 129 catch (CloneNotSupportedException e) { 130 // this should never happen. Therefore simply dump the exception 131 e.printStackTrace(); 132 } 133 134 return clone; 175 135 } 176 136 … … 185 145 } 186 146 187 /**188 *189 */190 synchronized void addChild(ITaskTreeNode child) {191 if (children == null) {192 children = new LinkedList<ITaskTreeNode>();193 }194 195 children.add(child);196 }197 198 /**199 *200 */201 synchronized void addChild(int index, ITaskTreeNode child) {202 if (children == null) {203 children = new LinkedList<ITaskTreeNode>();204 }205 206 children.add(index, child);207 }208 209 /**210 * TODO: comment211 *212 * @param i213 * @return214 */215 synchronized ITaskTreeNode removeChild(int index) {216 return children.remove(index);217 }218 219 /*220 * (non-Javadoc)221 *222 * @see java.lang.Object#clone()223 */224 @Override225 public synchronized ITaskTreeNode clone() {226 TaskTreeNode clone = null;227 try {228 clone = (TaskTreeNode) super.clone();229 230 if (children != null) {231 clone.children = new LinkedList<ITaskTreeNode>();232 233 for (ITaskTreeNode child : children) {234 clone.children.add(child.clone());235 }236 }237 238 }239 catch (CloneNotSupportedException e) {240 // this should never happen. Therefore simply dump the exception241 e.printStackTrace();242 }243 244 return clone;245 }246 247 147 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskBuilder.java
r1126 r1146 17 17 import java.util.List; 18 18 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 19 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 20 21 import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 21 22 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 22 23 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 23 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder; 24 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 24 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 25 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; 26 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 27 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; 28 import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 25 29 26 30 /** … … 30 34 * @author 2012, last modified by $Author: patrick$ 31 35 */ 32 public class TaskTreeBuilder implements ITaskTreeBuilder { 36 public class TaskBuilder implements ITaskBuilder { 37 38 /* (non-Javadoc) 39 * @see ITaskBuilder#addChild(ITaskInstance, ITaskInstance) 40 */ 41 @Override 42 public void addChild(ITaskInstance parent, ITaskInstance child) throws IllegalArgumentException 43 { 44 if (!(parent instanceof TaskInstance)) { 45 throw new IllegalArgumentException 46 ("illegal type of task instance provided: " + parent.getClass()); 47 } 48 49 if (!(child instanceof TaskInstance)) { 50 throw new IllegalArgumentException 51 ("illegal type of task instance provided: " + parent.getClass()); 52 } 53 54 // check, that the correct number of children for the distinct types are added 55 ITask task = parent.getTask(); 56 57 if (task instanceof IEventTask) { 58 throw new IllegalArgumentException 59 ("can not add children to a task instance of an event task"); 60 } 61 else if (task instanceof ISelection) { 62 if (parent.getChildren().size() > 0) { 63 throw new IllegalArgumentException 64 ("the instance of a selection must have at most one child"); 65 } 66 } 67 else if (task instanceof IOptional) { 68 if (parent.getChildren().size() > 1) { 69 throw new IllegalArgumentException 70 ("the instance of an optional must have at most one child"); 71 } 72 } 73 /* else if (task instanceof IIteration) { 74 for (ITaskInstance childInstance : parent.getChildren()) { 75 if (!childInstance.getTask().equals(child.getTask())) { 76 throw new IllegalArgumentException 77 ("all children of an instance of an iteration must have exactly the " + 78 "same type"); 79 } 80 } 81 } 82 83 boolean foundChildTask = false; 84 if (parent.getTask() instanceof IStructuringTemporalRelationship) { 85 IStructuringTemporalRelationship parentTask = 86 (IStructuringTemporalRelationship) parent.getTask(); 87 88 for (ITask parentTaskChild : parentTask.getChildren()) { 89 if (parentTaskChild.equals(child.getTask())) { 90 foundChildTask = true; 91 break; 92 } 93 } 94 } 95 else if (parent.getTask() instanceof IMarkingTemporalRelationship) { 96 IMarkingTemporalRelationship parentTask = 97 (IMarkingTemporalRelationship) parent.getTask(); 98 99 foundChildTask = parentTask.getMarkedTask() != null ? 100 parentTask.getMarkedTask().equals(child.getTask()) : false; 101 } 102 103 if (!foundChildTask) { 104 throw new IllegalArgumentException 105 ("the task of the child instance to be added does not belong to the children " + 106 "of the task of the parent instance"); 107 }*/ 108 109 // finally, after all checks are positive, add the child 110 ((TaskInstance) parent).addChild(child); 111 } 112 113 /* (non-Javadoc) 114 * @see ITaskBuilder#addExecutedTask(IUserSession, ITaskInstance) 115 */ 116 @Override 117 public void addExecutedTask(IUserSession session, ITaskInstance taskInstance) { 118 if (!(session instanceof UserSession)) { 119 throw new IllegalArgumentException 120 ("illegal type of session provided: " + session.getClass()); 121 } 122 123 if (!(taskInstance instanceof TaskInstance)) { 124 throw new IllegalArgumentException 125 ("illegal type of task instance provided: " + taskInstance.getClass()); 126 } 127 128 ((UserSession) session).addExecutedTask(taskInstance); 129 } 130 131 /* (non-Javadoc) 132 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder#addTaskInstance(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance) 133 */ 134 @Override 135 public void addTaskInstance(ITaskInstanceList taskInstanceList, ITaskInstance taskInstance) { 136 if (taskInstanceList instanceof TaskInstance) { 137 ((TaskInstance) taskInstanceList).addChild(taskInstance); 138 } 139 else if (taskInstanceList instanceof UserSession) { 140 ((UserSession) taskInstanceList).addExecutedTask(taskInstance); 141 } 142 else { 143 throw new IllegalArgumentException 144 ("illegal type of task instance list provided: " + taskInstanceList.getClass()); 145 } 146 } 147 148 /* (non-Javadoc) 149 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder#addTaskInstance(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList, int, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance) 150 */ 151 @Override 152 public void addTaskInstance(ITaskInstanceList taskInstanceList, 153 int index, 154 ITaskInstance taskInstance) 155 { 156 if (taskInstanceList instanceof TaskInstance) { 157 ((TaskInstance) taskInstanceList).addChild(index, taskInstance); 158 } 159 else if (taskInstanceList instanceof UserSession) { 160 ((UserSession) taskInstanceList).addExecutedTask(index, taskInstance); 161 } 162 else { 163 throw new IllegalArgumentException 164 ("illegal type of task instance list provided: " + taskInstanceList.getClass()); 165 } 166 } 167 168 /* (non-Javadoc) 169 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder#setTaskInstance(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList, int, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance) 170 */ 171 @Override 172 public void setTaskInstance(ITaskInstanceList taskInstanceList, 173 int index, 174 ITaskInstance taskInstance) 175 { 176 if (taskInstanceList instanceof TaskInstance) { 177 ((TaskInstance) taskInstanceList).removeChild(index); 178 ((TaskInstance) taskInstanceList).addChild(index, taskInstance); 179 } 180 else if (taskInstanceList instanceof UserSession) { 181 ((UserSession) taskInstanceList).removeExecutedTask(index); 182 ((UserSession) taskInstanceList).addExecutedTask(index, taskInstance); 183 } 184 else { 185 throw new IllegalArgumentException 186 ("illegal type of task instance list provided: " + taskInstanceList.getClass()); 187 } 188 } 189 190 /* (non-Javadoc) 191 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder#setTask(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance, de.ugoe.cs.autoquest.tasktrees.treeifc.ITask) 192 */ 193 @Override 194 public void setTask(ITaskInstance taskInstance, ITask task) { 195 if (!(taskInstance instanceof TaskInstance)) { 196 throw new IllegalArgumentException 197 ("illegal type of task instance provided: " + taskInstance.getClass()); 198 } 199 200 ((TaskInstance) taskInstance).setTask(task); 201 } 33 202 34 203 /* … … 38 207 */ 39 208 @Override 40 public void addChild(ISequence parent, ITask TreeNodechild) {209 public void addChild(ISequence parent, ITask child) { 41 210 if (!(parent instanceof Sequence)) { 42 211 throw new IllegalArgumentException 43 ("illegal type of task tree node provided: " + parent.getClass());44 } 45 46 addChildInternal( parent, -1, child);212 ("illegal type of sequence provided: " + parent.getClass()); 213 } 214 215 addChildInternal((Sequence) parent, -1, child); 47 216 } 48 217 … … 53 222 */ 54 223 @Override 55 public void addChild(ISequence parent, int index, ITask TreeNodechild) {224 public void addChild(ISequence parent, int index, ITask child) { 56 225 if (!(parent instanceof Sequence)) { 57 226 throw new IllegalArgumentException 58 ("illegal type of task tree node provided: " + parent.getClass());59 } 60 61 addChildInternal( parent, index, child);227 ("illegal type of sequence provided: " + parent.getClass()); 228 } 229 230 addChildInternal((Sequence) parent, index, child); 62 231 } 63 232 … … 66 235 */ 67 236 @Override 68 public void setChild(ISequence parent, int index, ITask TreeNodechild) {237 public void setChild(ISequence parent, int index, ITask child) { 69 238 if (!(parent instanceof Sequence)) { 70 239 throw new IllegalArgumentException 71 ("illegal type of task tree node provided: " + parent.getClass());72 } 73 74 (( TaskTreeNode) parent).removeChild(index);75 addChildInternal( parent, index, child);240 ("illegal type of sequence provided: " + parent.getClass()); 241 } 242 243 ((Sequence) parent).removeChild(index); 244 addChildInternal((Sequence) parent, index, child); 76 245 } 77 246 … … 82 251 */ 83 252 @Override 84 public void addChild(ISelection parent, ITask TreeNodechild) {253 public void addChild(ISelection parent, ITask child) { 85 254 if (!(parent instanceof Selection)) { 86 255 throw new IllegalArgumentException 87 ("illegal type of task tree nodeprovided: " + parent.getClass());88 } 89 90 addChildInternal( parent, -1, child);256 ("illegal type of selection provided: " + parent.getClass()); 257 } 258 259 addChildInternal((Selection) parent, -1, child); 91 260 } 92 261 … … 97 266 */ 98 267 @Override 99 public void set Child(IIteration iteration, ITaskTreeNodenewChild) {268 public void setMarkedTask(IIteration iteration, ITask newChild) { 100 269 if (!(iteration instanceof Iteration)) { 101 270 throw new IllegalArgumentException … … 103 272 } 104 273 105 if (!(newChild instanceof Task TreeNode)) {106 throw new IllegalArgumentException 107 ("illegal type of task tree nodeprovided: " + newChild.getClass());108 } 109 110 ((Iteration) iteration).set Child(newChild);274 if (!(newChild instanceof Task)) { 275 throw new IllegalArgumentException 276 ("illegal type of task provided: " + newChild.getClass()); 277 } 278 279 ((Iteration) iteration).setMarkedTask(newChild); 111 280 } 112 281 … … 115 284 */ 116 285 @Override 117 public void set Child(IOptional optional, ITaskTreeNodenewChild) {286 public void setMarkedTask(IOptional optional, ITask newChild) { 118 287 if (!(optional instanceof Optional)) { 119 288 throw new IllegalArgumentException … … 121 290 } 122 291 123 if (!(newChild instanceof Task TreeNode)) {124 throw new IllegalArgumentException 125 ("illegal type of task tree nodeprovided: " + newChild.getClass());126 } 127 128 ((Optional) optional).set Child(newChild);292 if (!(newChild instanceof Task)) { 293 throw new IllegalArgumentException 294 ("illegal type of task provided: " + newChild.getClass()); 295 } 296 297 ((Optional) optional).setMarkedTask(newChild); 129 298 } 130 299 … … 136 305 @Override 137 306 public void removeChild(ISequence parent, int index) { 138 if (!(parent instanceof TaskTreeNode)) {139 throw new IllegalArgumentException 140 ("illegal type of task tree node provided: " + parent.getClass());141 } 142 143 (( TaskTreeNode) parent).removeChild(index);307 if (!(parent instanceof Sequence)) { 308 throw new IllegalArgumentException 309 ("illegal type of sequence provided: " + parent.getClass()); 310 } 311 312 ((Sequence) parent).removeChild(index); 144 313 } 145 314 … … 150 319 */ 151 320 @Override 152 public void removeChild(ISelection parent, ITask TreeNodechild) {153 if (!(parent instanceof TaskTreeNode)) {154 throw new IllegalArgumentException 155 ("illegal type of task tree nodeprovided: " + parent.getClass());156 } 157 158 List<ITask TreeNode> children = parent.getChildren();321 public void removeChild(ISelection parent, ITask child) { 322 if (!(parent instanceof Selection)) { 323 throw new IllegalArgumentException 324 ("illegal type of selection provided: " + parent.getClass()); 325 } 326 327 List<ITask> children = parent.getChildren(); 159 328 160 329 for (int i = 0; i < children.size(); i++) { … … 162 331 ((children.get(i) != null) && (children.get(i).equals(child)))) 163 332 { 164 (( TaskTreeNode) parent).removeChild(i);333 ((Selection) parent).removeChild(i); 165 334 break; 166 335 } … … 169 338 170 339 /* (non-Javadoc) 340 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder#removeTaskInstance(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList, int) 341 */ 342 @Override 343 public void removeTaskInstance(ITaskInstanceList taskInstanceList, int index) { 344 if (taskInstanceList instanceof TaskInstance) { 345 ((TaskInstance) taskInstanceList).removeChild(index); 346 } 347 else if (taskInstanceList instanceof UserSession) { 348 ((UserSession) taskInstanceList).removeExecutedTask(index); 349 } 350 else { 351 throw new IllegalArgumentException 352 ("illegal type of task instance list provided: " + taskInstanceList.getClass()); 353 } 354 } 355 356 /* (non-Javadoc) 171 357 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder#replaceChild(de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode) 172 358 */ 173 359 @Override 174 public void replaceChild(ISelection parent, ITask TreeNode oldChild, ITaskTreeNodenewChild) {175 if (!(parent instanceof TaskTreeNode)) {176 throw new IllegalArgumentException 177 ("illegal type of task tree nodeprovided: " + parent.getClass());178 } 179 180 List<ITask TreeNode> children = parent.getChildren();360 public void replaceChild(ISelection parent, ITask oldChild, ITask newChild) { 361 if (!(parent instanceof Selection)) { 362 throw new IllegalArgumentException 363 ("illegal type of selection provided: " + parent.getClass()); 364 } 365 366 List<ITask> children = parent.getChildren(); 181 367 182 368 for (int i = 0; i < children.size(); i++) { … … 184 370 ((children.get(i) != null) && (children.get(i).equals(oldChild)))) 185 371 { 186 (( TaskTreeNode) parent).removeChild(i);187 (( TaskTreeNode) parent).addChild(i, newChild);372 ((Selection) parent).removeChild(i); 373 ((Selection) parent).addChild(i, newChild); 188 374 break; 189 375 } … … 197 383 */ 198 384 @Override 199 public void setDescription(ITask TreeNodeparent, String description) {200 if (!(parent instanceof Task TreeNode)) {201 throw new IllegalArgumentException 202 ("illegal type of task tree nodeprovided: " + parent.getClass());203 } 204 205 ((Task TreeNode) parent).setDescription(description);385 public void setDescription(ITask parent, String description) { 386 if (!(parent instanceof Task)) { 387 throw new IllegalArgumentException 388 ("illegal type of task provided: " + parent.getClass()); 389 } 390 391 ((Task) parent).setDescription(description); 206 392 } 207 393 … … 209 395 * 210 396 */ 211 private void addChildInternal( ITaskTreeNode parent, int index, ITaskTreeNodechild) {212 if (!(child instanceof Task TreeNode)) {213 throw new IllegalArgumentException 214 ("illegal type of task tree nodeprovided: " + child.getClass());397 private void addChildInternal(StructuringTemporalRelationship parent, int index, ITask child) { 398 if (!(child instanceof Task)) { 399 throw new IllegalArgumentException 400 ("illegal type of task provided: " + child.getClass()); 215 401 } 216 402 217 403 if (index > -1) { 218 ((TaskTreeNode) parent).addChild(index, child);404 parent.addChild(index, child); 219 405 } 220 406 else { 221 ((TaskTreeNode) parent).addChild(child);407 parent.addChild(child); 222 408 } 223 409 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskFactory.java
r1126 r1146 15 15 package de.ugoe.cs.autoquest.tasktrees.treeimpl; 16 16 17 import java.util.List; 18 17 19 import de.ugoe.cs.autoquest.eventcore.IEventTarget; 18 20 import de.ugoe.cs.autoquest.eventcore.IEventType; … … 22 24 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 23 25 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 24 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree; 25 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 26 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNodeFactory; 26 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 27 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 28 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; 29 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; 30 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; 31 import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 27 32 28 33 /** … … 32 37 * @author 2012, last modified by $Author: patrick$ 33 38 */ 34 public class Task TreeNodeFactory implements ITaskTreeNodeFactory {39 public class TaskFactory implements ITaskFactory { 35 40 36 41 /* … … 82 87 } 83 88 84 /* 85 * (non-Javadoc) 86 * 87 * @see 88 * de.ugoe.cs.tasktree.treeifc.TaskTreeNodeFactory#createTaskTree(de.ugoe.cs.tasktree.treeifc 89 * .TaskTreeNode) 89 /* (non-Javadoc) 90 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory#createNewTaskInstance(ITask) 90 91 */ 91 92 @Override 92 public ITaskTree createTaskTree(ITaskTreeNode root) { 93 return new TaskTree(root); 93 public ITaskInstance createNewTaskInstance(ITask task) { 94 return new TaskInstance(task); 95 } 96 97 /* (non-Javadoc) 98 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory#createNewTaskInstanceList() 99 */ 100 @Override 101 public ITaskInstanceList createNewTaskInstanceList() { 102 return new TaskInstance(new Sequence()); 103 } 104 105 /* (non-Javadoc) 106 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory#createUserSession() 107 */ 108 @Override 109 public IUserSession createUserSession() { 110 return new UserSession(); 111 } 112 113 /* (non-Javadoc) 114 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory#createTaskModel(IUserSession) 115 */ 116 @Override 117 public ITaskModel createTaskModel(List<IUserSession> userSessions) { 118 return new TaskModel(userSessions); 94 119 } 95 120 -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskModel.java
r1132 r1146 15 15 package de.ugoe.cs.autoquest.tasktrees.treeimpl; 16 16 17 import java.util.Collection; 18 import java.util.Collections; 17 19 import java.util.HashMap; 20 import java.util.List; 18 21 import java.util.Map; 19 22 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree; 21 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 22 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNodeInfo; 23 import de.ugoe.cs.autoquest.tasktrees.treeifc.IMarkingTemporalRelationship; 24 import de.ugoe.cs.autoquest.tasktrees.treeifc.IStructuringTemporalRelationship; 25 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 26 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 27 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; 28 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInfo; 29 import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 23 30 24 31 /** … … 28 35 * @author 2012, last modified by $Author: patrick$ 29 36 */ 30 public class TaskTree implements ITaskTree{37 class TaskModel implements ITaskModel { 31 38 32 /** the map of nodes*/33 private Map<ITaskTreeNode, ITaskTreeNodeInfo> taskMap;39 /** */ 40 private static final long serialVersionUID = 1L; 34 41 35 /** the root node of the task tree */ 36 private ITaskTreeNode rootNode; 42 /** the map of tasks */ 43 private List<IUserSession> userSessions; 44 45 /** the map of tasks */ 46 private Map<ITask, TaskInfo> taskMap = new HashMap<ITask, TaskInfo>(); 37 47 38 48 /** 39 * TODO: comment 40 * 49 * 41 50 */ 42 TaskTree(ITaskTreeNode rootNode) { 43 this.rootNode = rootNode; 51 TaskModel(List<IUserSession> userSessions) { 52 if ((userSessions == null) || (userSessions.size() == 0)) { 53 throw new IllegalArgumentException("user sessions must not be null"); 54 } 55 56 this.userSessions = userSessions; 57 58 for (IUserSession session : this.userSessions) { 59 for (ITaskInstance taskInstance : session) { 60 addTaskToMap(taskInstance.getTask()); 61 } 62 } 44 63 } 45 64 46 /* 47 * (non-Javadoc) 48 * 49 * @see de.ugoe.cs.tasktree.treeifc.TaskTree#getRoot() 65 66 /* (non-Javadoc) 67 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getUserSessions() 50 68 */ 51 69 @Override 52 public ITaskTreeNode getRoot() {53 return rootNode;70 public List<IUserSession> getUserSessions() { 71 return Collections.unmodifiableList(userSessions); 54 72 } 55 73 56 /* 57 * (non-Javadoc) 58 * 59 * @see de.ugoe.cs.tasktree.treeifc.TaskTree#getTaskMap() 74 75 /* (non-Javadoc) 76 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getTasks() 60 77 */ 61 78 @Override 62 public synchronized Map<ITaskTreeNode, ITaskTreeNodeInfo> getTaskMap() { 63 if (taskMap == null) { 64 taskMap = new HashMap<ITaskTreeNode, ITaskTreeNodeInfo>(); 65 addNodeToMap(rootNode, null); 66 } 67 return taskMap; 79 public Collection<ITask> getTasks() { 80 return Collections.unmodifiableCollection(taskMap.keySet()); 81 } 82 83 84 /* (non-Javadoc) 85 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getTaskInfo(de.ugoe.cs.autoquest.tasktrees.treeifc.ITask) 86 */ 87 @Override 88 public ITaskInfo getTaskInfo(ITask task) { 89 return taskMap.get(task); 68 90 } 69 91 70 92 /** 71 * TODO: comment 72 * 73 * @param rootNode 93 * 74 94 */ 75 private void add NodeToMap(ITaskTreeNode node, ITaskTreeNode parent) {76 NodeInfo nodeInfo = (NodeInfo) taskMap.get(node);95 private void addTaskToMap(ITask task) { 96 TaskInfo taskInfo = taskMap.get(task); 77 97 78 if ( nodeInfo == null) {79 nodeInfo = new NodeInfo(node);80 taskMap.put( node, nodeInfo);98 if (taskInfo == null) { 99 taskInfo = new TaskInfo(task); 100 taskMap.put(task, taskInfo); 81 101 } 82 102 83 if (parent != null) { 84 // through first removing an existing parent it is assured, that a parent is recorded 85 // only once. This is needed, because parent may be reused in a tree as well, but we 86 // always iterate the whole tree 87 //nodeInfo.removeParent(parent); 88 nodeInfo.addParent(parent); 103 if (task instanceof IStructuringTemporalRelationship) { 104 for (ITask child : ((IStructuringTemporalRelationship) task).getChildren()) { 105 addTaskToMap(child); 106 } 89 107 } 90 91 for (ITaskTreeNode child : node.getChildren()) { 92 addNodeToMap(child, node); 108 else if (task instanceof IMarkingTemporalRelationship) { 109 addTaskToMap(((IMarkingTemporalRelationship) task).getMarkedTask()); 93 110 } 94 111 } … … 100 117 */ 101 118 @Override 102 public TaskTree clone() { 103 TaskTree clone = null; 104 try { 105 clone = (TaskTree) super.clone(); 106 107 clone.rootNode = rootNode.clone(); 108 109 // the clone will create the task map itself, when it is first retrieved 110 clone.taskMap = null; 111 112 } 113 catch (CloneNotSupportedException e) { 114 // this should never happen. Therefore simply dump the exception 115 e.printStackTrace(); 116 } 117 118 return clone; 119 public TaskModel clone() { 120 return new TaskModel(userSessions); 119 121 } 120 122
Note: See TracChangeset
for help on using the changeset viewer.