Changeset 1125 for trunk/autoquest-core-tasktrees/src/main
- Timestamp:
- 03/18/13 11:46:47 (12 years ago)
- Location:
- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/nodeequality
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/nodeequality/EventTaskComparisonRule.java
r1113 r1125 28 28 public class EventTaskComparisonRule implements NodeComparisonRule { 29 29 30 /* 31 * (non-Javadoc) 32 * 33 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 30 /* (non-Javadoc) 31 * @see NodeComparisonRule#isApplicable(ITaskTreeNode, ITaskTreeNode) 34 32 */ 35 33 @Override 36 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 37 if ((!(node1 instanceof IEventTask)) || (!(node2 instanceof IEventTask))) { 38 return null; 39 } 34 public boolean isApplicable(ITaskTreeNode node1, ITaskTreeNode node2) { 35 return (node1 instanceof IEventTask) && (node2 instanceof IEventTask); 36 } 40 37 41 if (node1 == node2) { 42 return NodeEquality.IDENTICAL; 43 } 44 38 /* (non-Javadoc) 39 * @see NodeComparisonRule#areLexicallyEqual(ITaskTreeNode, ITaskTreeNode) 40 */ 41 @Override 42 public boolean areLexicallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 45 43 IEventTask task1 = (IEventTask) node1; 46 44 IEventTask task2 = (IEventTask) node2; 47 45 48 if (task1.getEventType().equals(task2.getEventType()) && 49 task1.getEventTarget().equals(task2.getEventTarget())) 50 { 46 return (task1.getEventType().equals(task2.getEventType()) && 47 task1.getEventTarget().equals(task2.getEventTarget())); 48 } 49 50 /* (non-Javadoc) 51 * @see NodeComparisonRule#areSyntacticallyEqual(ITaskTreeNode, ITaskTreeNode) 52 */ 53 @Override 54 public boolean areSyntacticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 55 return areLexicallyEqual(node1, node2); 56 } 57 58 /* (non-Javadoc) 59 * @see NodeComparisonRule#areSemanticallyEqual(ITaskTreeNode, ITaskTreeNode) 60 */ 61 @Override 62 public boolean areSemanticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 63 return areLexicallyEqual(node1, node2); 64 } 65 66 @Override 67 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 68 if (areLexicallyEqual(node1, node2)) { 51 69 return NodeEquality.LEXICALLY_EQUAL; 52 70 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/nodeequality/GUIEventTaskComparisonRule.java
r1113 r1125 17 17 import de.ugoe.cs.autoquest.eventcore.IEventTarget; 18 18 import de.ugoe.cs.autoquest.eventcore.gui.IInteraction; 19 import de.ugoe.cs.autoquest.eventcore.gui.KeyInteraction; 20 import de.ugoe.cs.autoquest.eventcore.gui.KeyPressed; 21 import de.ugoe.cs.autoquest.eventcore.gui.KeyReleased; 22 import de.ugoe.cs.autoquest.eventcore.gui.KeyTyped; 23 import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonDown; 24 import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonInteraction; 25 import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonUp; 19 26 import de.ugoe.cs.autoquest.eventcore.gui.MouseClick; 20 27 import de.ugoe.cs.autoquest.eventcore.gui.MouseDoubleClick; 21 28 import de.ugoe.cs.autoquest.eventcore.gui.MouseDragAndDrop; 29 import de.ugoe.cs.autoquest.eventcore.gui.Scroll; 22 30 import de.ugoe.cs.autoquest.eventcore.gui.TextInput; 23 31 import de.ugoe.cs.autoquest.eventcore.gui.ValueSelection; … … 27 35 import de.ugoe.cs.autoquest.eventcore.guimodel.IImage; 28 36 import de.ugoe.cs.autoquest.eventcore.guimodel.IListBox; 37 import de.ugoe.cs.autoquest.eventcore.guimodel.IMenu; 29 38 import de.ugoe.cs.autoquest.eventcore.guimodel.IMenuButton; 30 39 import de.ugoe.cs.autoquest.eventcore.guimodel.IRadioButton; … … 51 60 public class GUIEventTaskComparisonRule implements NodeComparisonRule { 52 61 53 /* 54 * (non-Javadoc) 55 * 56 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 62 /* (non-Javadoc) 63 * @see NodeComparisonRule#isApplicable(ITaskTreeNode, ITaskTreeNode) 64 */ 65 @Override 66 public boolean isApplicable(ITaskTreeNode node1, ITaskTreeNode node2) { 67 return 68 ((node1 instanceof IEventTask) && (node2 instanceof IEventTask) && 69 (((IEventTask) node1).getEventType() instanceof IInteraction) && 70 (((IEventTask) node2).getEventType() instanceof IInteraction)); 71 } 72 73 /* (non-Javadoc) 74 * @see NodeComparisonRule#areLexicallyEqual(ITaskTreeNode, ITaskTreeNode) 75 */ 76 @Override 77 public boolean areLexicallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 78 NodeEquality equality = getEquality(node1, node2, NodeEquality.LEXICALLY_EQUAL); 79 return (equality != null) && (equality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)); 80 } 81 82 /* (non-Javadoc) 83 * @see NodeComparisonRule#areSyntacticallyEqual(ITaskTreeNode, ITaskTreeNode) 84 */ 85 @Override 86 public boolean areSyntacticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 87 NodeEquality equality = getEquality(node1, node2, NodeEquality.SYNTACTICALLY_EQUAL); 88 return (equality != null) && (equality.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL)); 89 } 90 91 /* (non-Javadoc) 92 * @see NodeComparisonRule#areSemanticallyEqual(ITaskTreeNode, ITaskTreeNode) 93 */ 94 @Override 95 public boolean areSemanticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 96 NodeEquality equality = getEquality(node1, node2, NodeEquality.SEMANTICALLY_EQUAL); 97 return (equality != null) && (equality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)); 98 } 99 100 /* (non-Javadoc) 101 * @see NodeComparisonRule#compare(ITaskTreeNode, ITaskTreeNode) 57 102 */ 58 103 @Override 59 104 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 60 if ((!(node1 instanceof IEventTask)) || (!(node2 instanceof IEventTask))) { 61 return null; 62 } 63 105 return getEquality(node1, node2, null); 106 } 107 108 /** 109 * 110 */ 111 private NodeEquality getEquality(ITaskTreeNode node1, 112 ITaskTreeNode node2, 113 NodeEquality requiredEqualityLevel) 114 { 64 115 IEventTask task1 = (IEventTask) node1; 65 116 IEventTask task2 = (IEventTask) node2; 66 117 67 if ((!(task1.getEventType() instanceof IInteraction)) ||68 (!(task2.getEventType() instanceof IInteraction)))69 {70 return null;71 }72 73 if (node1 == node2) {74 return NodeEquality.IDENTICAL;75 }76 77 118 if (!task1.getEventTarget().equals(task2.getEventTarget())) { 78 119 return NodeEquality.UNEQUAL; … … 82 123 IInteraction interaction2 = (IInteraction) task2.getEventType(); 83 124 84 return compareInteractions(interaction1, interaction2, task1.getEventTarget()); 125 return compareInteractions 126 (interaction1, interaction2, task1.getEventTarget(), requiredEqualityLevel); 85 127 } 86 128 … … 105 147 private NodeEquality compareInteractions(IInteraction interaction1, 106 148 IInteraction interaction2, 107 IEventTarget eventTarget) 108 { 149 IEventTarget eventTarget, 150 NodeEquality equalityLevel) 151 { 152 NodeEquality level = equalityLevel; 153 154 if (level == null) { 155 level = NodeEquality.LEXICALLY_EQUAL; 156 } 157 109 158 if (interaction1 == interaction2) { 110 159 return NodeEquality.LEXICALLY_EQUAL; 111 160 } 161 else if ((interaction1 instanceof KeyInteraction) && 162 (interaction2 instanceof KeyInteraction)) 163 { 164 return compareKeyInteractions 165 ((KeyInteraction) interaction1, (KeyInteraction) interaction2, level); 166 } 167 else if ((interaction1 instanceof MouseButtonInteraction) && 168 (interaction2 instanceof MouseButtonInteraction)) 169 { 170 return compareMouseButtonInteractions 171 ((MouseButtonInteraction) interaction1, (MouseButtonInteraction) interaction2, 172 eventTarget, level); 173 } 174 else if ((interaction1 instanceof Scroll) && (interaction2 instanceof Scroll)) { 175 return compareScrolls((Scroll) interaction1, (Scroll) interaction2, level); 176 } 112 177 else if ((interaction1 instanceof TextInput) && (interaction2 instanceof TextInput)) { 113 return compareTextInputs((TextInput) interaction1, (TextInput) interaction2); 178 return compareTextInputs 179 ((TextInput) interaction1, (TextInput) interaction2, level); 114 180 } 115 181 else if ((interaction1 instanceof ValueSelection) && … … 117 183 { 118 184 return compareValueSelections 119 ((ValueSelection<?>) interaction1, (ValueSelection<?>) interaction2); 120 } 121 else if ((interaction1 instanceof MouseClick) && 122 (interaction2 instanceof MouseClick)) 123 { 124 return compareMouseClicks 125 ((MouseClick) interaction1, (MouseClick) interaction2, eventTarget); 126 } 127 else if ((interaction1 instanceof MouseDoubleClick) && 128 (interaction2 instanceof MouseDoubleClick)) 129 { 130 return compareMouseDoubleClicks 131 ((MouseDoubleClick) interaction1, (MouseDoubleClick) interaction2, eventTarget); 132 } 133 else if ((interaction1 instanceof MouseDragAndDrop) && 134 (interaction2 instanceof MouseDragAndDrop)) 135 { 136 return compareMouseDragAndDrops 137 ((MouseDragAndDrop) interaction1, (MouseDragAndDrop) interaction2); 185 ((ValueSelection<?>) interaction1, (ValueSelection<?>) interaction2, level); 138 186 } 139 187 else if (interaction1.equals(interaction2)) { … … 143 191 return NodeEquality.UNEQUAL; 144 192 } 193 } 194 195 /** 196 * <p> 197 * TODO: comment 198 * </p> 199 * 200 * @param interaction1 201 * @param interaction2 202 * @param eventTarget 203 * @param level 204 * @return 205 */ 206 private NodeEquality compareKeyInteractions(KeyInteraction interaction1, 207 KeyInteraction interaction2, 208 NodeEquality equalityLevel) 209 { 210 if (((interaction1 instanceof KeyPressed) && (interaction2 instanceof KeyPressed)) || 211 ((interaction1 instanceof KeyReleased) && (interaction2 instanceof KeyReleased)) || 212 ((interaction1 instanceof KeyTyped) && (interaction2 instanceof KeyTyped))) 213 { 214 if ((equalityLevel.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL)) && 215 (interaction1.getKey() == interaction2.getKey())) 216 { 217 return NodeEquality.LEXICALLY_EQUAL; 218 } 219 else { 220 return NodeEquality.SEMANTICALLY_EQUAL; 221 } 222 } 223 224 return NodeEquality.UNEQUAL; 225 } 226 227 /** 228 * <p> 229 * compares two mouse drag and drops. If both drag and drops have the same start and end 230 * coordinates, they are lexically equal. Otherwise, they are semantically equal. 231 * </p> 232 * 233 * @param interaction1 the first mouse drag and drop to compare 234 * @param interaction2 the second mouse drag and drop to compare 235 * 236 * @return as described 237 */ 238 private NodeEquality compareMouseDragAndDrops(MouseDragAndDrop interaction1, 239 MouseDragAndDrop interaction2, 240 NodeEquality equalityLevel) 241 { 242 if (interaction1.getButton() != interaction2.getButton()) { 243 return NodeEquality.UNEQUAL; 244 } 245 246 if (equalityLevel.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL)) { 247 int x1 = interaction1.getX(); 248 int x1Start = interaction1.getXStart(); 249 int x2 = interaction2.getX(); 250 int x2Start = interaction2.getXStart(); 251 int y1 = interaction1.getY(); 252 int y1Start = interaction1.getYStart(); 253 int y2 = interaction2.getY(); 254 int y2Start = interaction2.getYStart(); 255 256 if ((x1Start == x2Start) && (x1 == x2) && (y1Start == y2Start) && (y1 == y2)) { 257 return NodeEquality.LEXICALLY_EQUAL; 258 } 259 } 260 261 return NodeEquality.SEMANTICALLY_EQUAL; 262 } 263 264 /** 265 * <p> 266 * compares two mouse button interactions such as clicks, mouse button down, or double clicks. 267 * If both interactions have the same coordinates, they are lexically equal. Otherwise, they 268 * are semantically equal. Mouse clicks for which the coordinates make no lexical difference 269 * (see {@link #clickCoordinatesMakeLexicalDifference(IEventTarget)}) are treated as 270 * lexically equal. 271 * </p> 272 * 273 * @param interaction1 the first mouse button interaction to compare 274 * @param interaction2 the second mouse button interaction to compare 275 * @param eventTarget the event target on which the interactions happened (used within 276 * special comparisons like mouse clicks on buttons, where the coordinates 277 * can be ignored) 278 * 279 * @return as described 280 */ 281 private NodeEquality compareMouseButtonInteractions(MouseButtonInteraction interaction1, 282 MouseButtonInteraction interaction2, 283 IEventTarget eventTarget, 284 NodeEquality equalityLevel) 285 { 286 boolean coordinatesMatch = true; 287 288 if ((interaction1 instanceof MouseDragAndDrop) && 289 (interaction2 instanceof MouseDragAndDrop)) 290 { 291 return compareMouseDragAndDrops 292 ((MouseDragAndDrop) interaction1, (MouseDragAndDrop) interaction2, equalityLevel); 293 } 294 else if (interaction1.getButton() != interaction2.getButton()) { 295 return NodeEquality.UNEQUAL; 296 } 297 else if (equalityLevel.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL) && 298 clickCoordinatesMakeLexicalDifference(eventTarget)) 299 { 300 int x1 = interaction1.getX(); 301 int x2 = interaction2.getX(); 302 int y1 = interaction1.getY(); 303 int y2 = interaction2.getY(); 304 305 if ((x1 != x2) || (y1 != y2)) { 306 coordinatesMatch = false; 307 } 308 } 309 310 // up to now, they can be equal. Now check the types. Do it as last action as these 311 // checks take the most time and should, therefore, only be done latest 312 if (((interaction1 instanceof MouseClick) && (interaction2 instanceof MouseClick)) || 313 ((interaction1 instanceof MouseDoubleClick) && 314 (interaction2 instanceof MouseDoubleClick)) || 315 ((interaction1 instanceof MouseButtonDown) && 316 (interaction2 instanceof MouseButtonDown)) || 317 ((interaction1 instanceof MouseButtonUp) && 318 (interaction2 instanceof MouseButtonUp))) 319 { 320 if (coordinatesMatch) { 321 return NodeEquality.LEXICALLY_EQUAL; 322 } 323 else { 324 return NodeEquality.SEMANTICALLY_EQUAL; 325 } 326 } 327 328 return NodeEquality.UNEQUAL; 329 } 330 331 /** 332 * <p> 333 * compares two mouse button interactions such as clicks, mouse button down, or double clicks. 334 * If both interactions have the same coordinates, they are lexically equal. Otherwise, they 335 * are semantically equal. Mouse clicks for which the coordinates make no lexical difference 336 * (see {@link #clickCoordinatesMakeLexicalDifference(IEventTarget)}) are treated as 337 * lexically equal. 338 * </p> 339 * 340 * @param interaction1 the first mouse button interaction to compare 341 * @param interaction2 the second mouse button interaction to compare 342 * @param eventTarget the event target on which the interactions happened (used within 343 * special comparisons like mouse clicks on buttons, where the coordinates 344 * can be ignored) 345 * 346 * @return as described 347 */ 348 private NodeEquality compareScrolls(Scroll interaction1, 349 Scroll interaction2, 350 NodeEquality equalityLevel) 351 { 352 if (equalityLevel.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL)) { 353 int x1 = interaction1.getXPosition(); 354 int x2 = interaction2.getXPosition(); 355 int y1 = interaction1.getYPosition(); 356 int y2 = interaction2.getYPosition(); 357 358 if ((x1 == x2) && (y1 == y2)) { 359 return NodeEquality.LEXICALLY_EQUAL; 360 } 361 } 362 363 return NodeEquality.SEMANTICALLY_EQUAL; 145 364 } 146 365 … … 158 377 * @return as described 159 378 */ 160 private NodeEquality compareTextInputs(TextInput interaction1, TextInput interaction2) { 161 if (interaction1.getEnteredText().equals(interaction2.getEnteredText())) { 162 if (interaction1.getTextInputEvents().equals(interaction2.getTextInputEvents())) { 163 return NodeEquality.LEXICALLY_EQUAL; 164 } 165 else { 166 return NodeEquality.SYNTACTICALLY_EQUAL; 167 } 168 } 169 else { 170 return NodeEquality.SEMANTICALLY_EQUAL; 379 private NodeEquality compareTextInputs(TextInput interaction1, 380 TextInput interaction2, 381 NodeEquality equalityLevel) 382 { 383 switch (equalityLevel) { 384 case LEXICALLY_EQUAL: 385 if (interaction1.getTextInputEvents().equals(interaction2.getTextInputEvents())) { 386 return NodeEquality.LEXICALLY_EQUAL; 387 } 388 // fall through 389 case SYNTACTICALLY_EQUAL: 390 if (interaction1.getEnteredText().equals(interaction2.getEnteredText())) { 391 return NodeEquality.SYNTACTICALLY_EQUAL; 392 } 393 // fall through 394 case SEMANTICALLY_EQUAL: 395 return NodeEquality.SEMANTICALLY_EQUAL; 396 default: 397 return NodeEquality.UNEQUAL; 171 398 } 172 399 } … … 185 412 */ 186 413 private NodeEquality compareValueSelections(ValueSelection<?> interaction1, 187 ValueSelection<?> interaction2) 188 { 189 Object value1 = interaction1.getSelectedValue(); 190 Object value2 = interaction2.getSelectedValue(); 191 192 if ((value1 == value2) || ((value1 != null) && (value1.equals(value2)))) { 193 return NodeEquality.LEXICALLY_EQUAL; 194 } 195 else { 196 return NodeEquality.SEMANTICALLY_EQUAL; 197 } 198 } 199 200 /** 201 * <p> 202 * compares two mouse clicks. If both clicks have the same coordinates, they are lexically 203 * equal. Otherwise, they are semantically equal. Mouse clicks for which the coordinates make 204 * no lexical difference (see {@link #clickCoordinatesMakeLexicalDifference(IEventTarget)}) 205 * are treated as lexically equal. 206 * </p> 207 * 208 * @param interaction1 the first mouse click to compare 209 * @param interaction2 the second mouse click to compare 210 * @param eventTarget the event target on which the interactions happened (used within 211 * special comparisons like mouse clicks on buttons, where the coordinates 212 * can be ignored) 213 * 214 * @return as described 215 */ 216 private NodeEquality compareMouseClicks(MouseClick interaction1, 217 MouseClick interaction2, 218 IEventTarget eventTarget) 219 { 220 if (interaction1.getButton() != interaction2.getButton()) { 221 return NodeEquality.UNEQUAL; 222 } 223 224 if (!clickCoordinatesMakeLexicalDifference(eventTarget)) { 225 return NodeEquality.LEXICALLY_EQUAL; 226 } 227 228 int x1 = interaction1.getX(); 229 int x2 = interaction2.getX(); 230 int y1 = interaction1.getY(); 231 int y2 = interaction2.getY(); 232 233 if ((x1 == x2) && (y1 == y2)) { 234 return NodeEquality.LEXICALLY_EQUAL; 235 } 236 else { 237 return NodeEquality.SEMANTICALLY_EQUAL; 238 } 239 } 240 241 /** 242 * <p> 243 * compares two mouse double clicks. If both double clicks have the same coordinates, they are 244 * lexically equal. Otherwise, they are semantically equal. Double clicks for which the 245 * coordinates make no lexical difference 246 * (see {@link #clickCoordinatesMakeLexicalDifference(IEventTarget)}) are treated as lexically 247 * equal. 248 * </p> 249 * 250 * @param interaction1 the first mouse double click to compare 251 * @param interaction2 the second mouse double click to compare 252 * @param eventTarget the event target on which the interactions happened (used within 253 * special comparisons like mouse clicks on buttons, where the coordinates 254 * can be ignored) 255 * 256 * @return as described 257 */ 258 private NodeEquality compareMouseDoubleClicks(MouseDoubleClick interaction1, 259 MouseDoubleClick interaction2, 260 IEventTarget eventTarget) 261 { 262 if (interaction1.getButton() != interaction2.getButton()) { 263 return NodeEquality.UNEQUAL; 264 } 265 266 if (!clickCoordinatesMakeLexicalDifference(eventTarget)) { 267 return NodeEquality.LEXICALLY_EQUAL; 268 } 269 270 int x1 = interaction1.getX(); 271 int x2 = interaction2.getX(); 272 int y1 = interaction1.getY(); 273 int y2 = interaction2.getY(); 274 275 if ((x1 == x2) && (y1 == y2)) { 276 return NodeEquality.LEXICALLY_EQUAL; 277 } 278 else { 279 return NodeEquality.SEMANTICALLY_EQUAL; 280 } 281 } 282 283 /** 284 * <p> 285 * compares two mouse drag and drops. If both drag and drops have the same start and end 286 * coordinates, they are lexically equal. Otherwise, they are semantically equal. 287 * </p> 288 * 289 * @param interaction1 the first mouse drag and drop to compare 290 * @param interaction2 the second mouse drag and drop to compare 291 * 292 * @return as described 293 */ 294 private NodeEquality compareMouseDragAndDrops(MouseDragAndDrop interaction1, 295 MouseDragAndDrop interaction2) 296 { 297 if (interaction1.getButton() != interaction2.getButton()) { 298 return NodeEquality.UNEQUAL; 299 } 300 301 int x1 = interaction1.getX(); 302 int x1Start = interaction1.getXStart(); 303 int x2 = interaction2.getX(); 304 int x2Start = interaction2.getXStart(); 305 int y1 = interaction1.getY(); 306 int y1Start = interaction1.getYStart(); 307 int y2 = interaction2.getY(); 308 int y2Start = interaction2.getYStart(); 309 310 if ((x1Start == x2Start) && (x1 == x2) && (y1Start == y2Start) && (y1 == y2)) { 311 return NodeEquality.LEXICALLY_EQUAL; 312 } 313 else { 314 return NodeEquality.SEMANTICALLY_EQUAL; 315 } 414 ValueSelection<?> interaction2, 415 NodeEquality equalityLevel) 416 { 417 if (equalityLevel.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL)) { 418 Object value1 = interaction1.getSelectedValue(); 419 Object value2 = interaction2.getSelectedValue(); 420 421 if ((value1 == value2) || ((value1 != null) && (value1.equals(value2)))) { 422 return NodeEquality.LEXICALLY_EQUAL; 423 } 424 } 425 426 return NodeEquality.SEMANTICALLY_EQUAL; 316 427 } 317 428 … … 336 447 (eventTarget instanceof IImage) || 337 448 (eventTarget instanceof IListBox) || 449 (eventTarget instanceof IMenu) || 338 450 (eventTarget instanceof IMenuButton) || 339 451 (eventTarget instanceof IRadioButton) || -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/nodeequality/IterationComparisonRule.java
r1113 r1125 15 15 package de.ugoe.cs.autoquest.tasktrees.nodeequality; 16 16 17 import java.util.List; 18 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 17 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 18 21 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 22 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 19 23 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 20 24 … … 95 99 } 96 100 97 /* 98 * (non-Javadoc) 99 * 100 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 101 /* (non-Javadoc) 102 * @see NodeComparisonRule#isApplicable(ITaskTreeNode, ITaskTreeNode) 103 */ 104 @Override 105 public boolean isApplicable(ITaskTreeNode node1, ITaskTreeNode node2) { 106 return (node1 instanceof IIteration) && (node2 instanceof IIteration); 107 } 108 109 /* (non-Javadoc) 110 * @see NodeComparisonRule#areLexicallyEqual(ITaskTreeNode, ITaskTreeNode) 111 */ 112 @Override 113 public boolean areLexicallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 114 List<ITaskTreeNode> children1 = node1.getChildren(); 115 List<ITaskTreeNode> children2 = node2.getChildren(); 116 117 if (children1.size() == children2.size()) { 118 if (children1.size() == 0) { 119 return true; 120 } 121 else { 122 ITaskTreeNode child1 = children1.get(0); 123 ITaskTreeNode child2 = children2.get(0); 124 125 // iterations may have 3 different structures. 126 // 1. they have one child, which is the iterated one 127 // 2. they have a sequence of children, which is iterated 128 // 3. they have a selection of different iterated variants (usually the variants 129 // are semantically equal) 130 // check if the type of children match. If not, return false. If they match, 131 // use the equality manager to perform further comparisons 132 133 if (((child1 instanceof ISelection) && (child2 instanceof ISelection)) || 134 ((child1 instanceof ISequence) && (child2 instanceof ISequence)) || 135 ((child1 instanceof IEventTask) && (child2 instanceof IEventTask))) 136 { 137 return getNodeEquality 138 (child1, child2).isAtLeast(NodeEquality.LEXICALLY_EQUAL); 139 } 140 } 141 } 142 143 return false; 144 } 145 146 /* (non-Javadoc) 147 * @see NodeComparisonRule#areSyntacticallyEqual(ITaskTreeNode, ITaskTreeNode) 148 */ 149 @Override 150 public boolean areSyntacticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 151 List<ITaskTreeNode> children1 = node1.getChildren(); 152 List<ITaskTreeNode> children2 = node2.getChildren(); 153 154 if (children1.size() == children2.size()) { 155 if (children1.size() == 0) { 156 return true; 157 } 158 else { 159 ITaskTreeNode child1 = children1.get(0); 160 ITaskTreeNode child2 = children2.get(0); 161 162 // iterations may have 3 different structures. 163 // 1. they have one child, which is the iterated one 164 // 2. they have a sequence of children, which is iterated 165 // 3. they have a selection of different iterated variants (usually the variants 166 // are semantically equal) 167 // ignore the type of the children but check them for equality. 168 169 return getNodeEquality(child1, child2).isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL); 170 } 171 } 172 173 return false; 174 } 175 176 /* (non-Javadoc) 177 * @see NodeComparisonRule#areSemanticallyEqual(ITaskTreeNode, ITaskTreeNode) 178 */ 179 @Override 180 public boolean areSemanticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 181 return compare(node1, node2).isAtLeast(NodeEquality.SEMANTICALLY_EQUAL); 182 } 183 184 /* (non-Javadoc) 185 * @see NodeComparisonRule#compare(ITaskTreeNode, ITaskTreeNode) 101 186 */ 102 187 @Override 103 188 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 104 if ((!(node1 instanceof IIteration)) || (!(node2 instanceof IIteration))) { 105 return null; 106 } 107 108 if (node1 == node2) { 109 return NodeEquality.IDENTICAL; 110 } 189 List<ITaskTreeNode> children1 = node1.getChildren(); 190 List<ITaskTreeNode> children2 = node2.getChildren(); 111 191 112 192 // if both iterations do not have children, they are equal although this doesn't make sense 113 if (( node1.getChildren().size() == 0) && (node2.getChildren().size() == 0)) {193 if ((children1.size() == 0) && (children2.size() == 0)) { 114 194 return NodeEquality.LEXICALLY_EQUAL; 115 195 } 116 else if (( node1.getChildren().size() == 0) || (node2.getChildren().size() == 0)) {196 else if ((children1.size() == 0) || (children2.size() == 0)) { 117 197 return NodeEquality.UNEQUAL; 118 198 } 119 199 120 ITaskTreeNode child1 = node1.getChildren().get(0);121 ITaskTreeNode child2 = node2.getChildren().get(0);200 ITaskTreeNode child1 = children1.get(0); 201 ITaskTreeNode child2 = children2.get(0); 122 202 123 203 // iterations may have 3 different structures. … … 132 212 // This condition matches, if both iterations are the same variants of iteration. I.e. three 133 213 // combinations of the permutation are handled herewith. 134 NodeEquality nodeEquality = mRuleManager.applyRules(child1, child2); 214 NodeEquality nodeEquality = getNodeEquality(child1, child2); 215 216 if (nodeEquality != null) { 217 return nodeEquality; 218 } 219 220 // compare one iteration with a single node as a child and another one with a selection of 221 // semantically equal nodes 222 return selectionChildrenSemanticallyEqualNode(child1, child2); 223 224 // all other combinations (i.e. sequence with single child and sequence with selection) 225 // can not match 226 } 227 228 /** 229 * TODO update comment 230 */ 231 private NodeEquality getNodeEquality(ITaskTreeNode child1, ITaskTreeNode child2) { 232 NodeEquality nodeEquality = callRuleManager(child1, child2, null); 135 233 136 234 if (nodeEquality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)) { … … 144 242 } 145 243 } 146 147 // compare one iteration with a single node as a child and another one with a selection of 148 // semantically equal nodes 149 return selectionChildrenSemanticallyEqualNode(child1, child2); 150 151 // all other combinations (i.e. sequence with single child and sequence with selection) 152 // can not match 244 245 return NodeEquality.UNEQUAL; 153 246 } 154 247 … … 189 282 190 283 for (ITaskTreeNode child : selection.getChildren()) { 191 NodeEquality nodeEquality = mRuleManager.applyRules(node, child); 284 NodeEquality nodeEquality = 285 callRuleManager(node, child, commonDenominatorForAllComparisons); 192 286 193 287 if ((nodeEquality == null) || (nodeEquality == NodeEquality.UNEQUAL)) … … 203 297 } 204 298 299 /** 300 * <p> 301 * TODO: comment 302 * </p> 303 * 304 * @param child1 305 * @param child2 306 * @param requiredEqualityLevel 307 * @return 308 */ 309 private NodeEquality callRuleManager(ITaskTreeNode child1, 310 ITaskTreeNode child2, 311 NodeEquality requiredEqualityLevel) 312 { 313 if (requiredEqualityLevel == null) { 314 return mRuleManager.compare(child1, child2); 315 } 316 else if (mRuleManager.areAtLeastEqual(child1, child2, requiredEqualityLevel)) { 317 return requiredEqualityLevel; 318 } 319 else { 320 return NodeEquality.UNEQUAL; 321 } 322 } 205 323 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/nodeequality/NodeAndIterationComparisonRule.java
r1113 r1125 14 14 15 15 package de.ugoe.cs.autoquest.tasktrees.nodeequality; 16 17 import java.util.List; 16 18 17 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; … … 48 50 } 49 51 50 /* 51 * (non-Javadoc) 52 * 53 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 52 /* (non-Javadoc) 53 * @see NodeComparisonRule#isApplicable(ITaskTreeNode, ITaskTreeNode) 54 */ 55 @Override 56 public boolean isApplicable(ITaskTreeNode node1, ITaskTreeNode node2) { 57 return ((node1 instanceof IIteration) && (!(node2 instanceof IIteration))) || 58 ((node2 instanceof IIteration) && (!(node1 instanceof IIteration))); 59 } 60 61 /* (non-Javadoc) 62 * @see NodeComparisonRule#areLexicallyEqual(ITaskTreeNode, ITaskTreeNode) 63 */ 64 @Override 65 public boolean areLexicallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 66 NodeEquality equality = getEquality(node1, node2, NodeEquality.LEXICALLY_EQUAL); 67 return (equality != null) && (equality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)); 68 } 69 70 /* (non-Javadoc) 71 * @see NodeComparisonRule#areSyntacticallyEqual(ITaskTreeNode, ITaskTreeNode) 72 */ 73 @Override 74 public boolean areSyntacticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 75 NodeEquality equality = getEquality(node1, node2, NodeEquality.SYNTACTICALLY_EQUAL); 76 return (equality != null) && (equality.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL)); 77 } 78 79 /* (non-Javadoc) 80 * @see NodeComparisonRule#areSemanticallyEqual(ITaskTreeNode, ITaskTreeNode) 81 */ 82 @Override 83 public boolean areSemanticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 84 NodeEquality equality = getEquality(node1, node2, NodeEquality.SEMANTICALLY_EQUAL); 85 return (equality != null) && (equality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)); 86 } 87 88 /* (non-Javadoc) 89 * @see NodeComparisonRule#compare(ITaskTreeNode, ITaskTreeNode) 54 90 */ 55 91 @Override 56 92 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 93 return getEquality(node1, node2, null); 94 } 95 96 /** 97 * 98 */ 99 private NodeEquality getEquality(ITaskTreeNode node1, 100 ITaskTreeNode node2, 101 NodeEquality requiredEqualityLevel) 102 { 57 103 IIteration iteration = null; 58 104 ITaskTreeNode node = null; … … 80 126 } 81 127 128 List<ITaskTreeNode> children = iteration.getChildren(); 129 82 130 // now, that we found the iteration and the node, lets compare the child of the iteration 83 131 // with the node. 84 if ( iteration.getChildren().size() < 1) {132 if (children.size() < 1) { 85 133 return null; 86 134 } 87 135 88 NodeEquality nodeEquality = mRuleManager.applyRules(iteration.getChildren().get(0), node);136 NodeEquality nodeEquality = callRuleManager(children.get(0), node, requiredEqualityLevel); 89 137 90 138 // although the subtask may be identical to the node, we can not return identical, as … … 98 146 99 147 } 148 149 /** 150 * <p> 151 * TODO: comment 152 * </p> 153 * 154 * @param child1 155 * @param child2 156 * @param requiredEqualityLevel 157 * @return 158 */ 159 private NodeEquality callRuleManager(ITaskTreeNode child1, 160 ITaskTreeNode child2, 161 NodeEquality requiredEqualityLevel) 162 { 163 if (requiredEqualityLevel == null) { 164 return mRuleManager.compare(child1, child2); 165 } 166 else if (mRuleManager.areAtLeastEqual(child1, child2, requiredEqualityLevel)) { 167 return requiredEqualityLevel; 168 } 169 else { 170 return NodeEquality.UNEQUAL; 171 } 172 } 100 173 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/nodeequality/NodeAndSelectionComparisonRule.java
r1113 r1125 14 14 15 15 package de.ugoe.cs.autoquest.tasktrees.nodeequality; 16 17 import java.util.List; 16 18 17 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; … … 33 35 /** the rule manager for internally comparing task tree nodes */ 34 36 private NodeEqualityRuleManager mRuleManager; 35 37 36 38 /** 37 39 * <p> … … 47 49 } 48 50 49 /* 50 * (non-Javadoc) 51 * 52 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 51 /* (non-Javadoc) 52 * @see NodeComparisonRule#isApplicable(ITaskTreeNode, ITaskTreeNode) 53 */ 54 @Override 55 public boolean isApplicable(ITaskTreeNode node1, ITaskTreeNode node2) { 56 return ((node1 instanceof ISelection) && (!(node2 instanceof ISelection))) || 57 ((node2 instanceof ISelection) && (!(node1 instanceof ISelection))); 58 } 59 60 /* (non-Javadoc) 61 * @see NodeComparisonRule#areLexicallyEqual(ITaskTreeNode, ITaskTreeNode) 62 */ 63 @Override 64 public boolean areLexicallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 65 NodeEquality equality = getEquality(node1, node2, NodeEquality.LEXICALLY_EQUAL); 66 return (equality != null) && (equality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)); 67 } 68 69 /* (non-Javadoc) 70 * @see NodeComparisonRule#areSyntacticallyEqual(ITaskTreeNode, ITaskTreeNode) 71 */ 72 @Override 73 public boolean areSyntacticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 74 NodeEquality equality = getEquality(node1, node2, NodeEquality.SYNTACTICALLY_EQUAL); 75 return (equality != null) && (equality.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL)); 76 } 77 78 /* (non-Javadoc) 79 * @see NodeComparisonRule#areSemanticallyEqual(ITaskTreeNode, ITaskTreeNode) 80 */ 81 @Override 82 public boolean areSemanticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 83 NodeEquality equality = getEquality(node1, node2, NodeEquality.SEMANTICALLY_EQUAL); 84 return (equality != null) && (equality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)); 85 } 86 87 /* (non-Javadoc) 88 * @see NodeComparisonRule#compare(ITaskTreeNode, ITaskTreeNode) 53 89 */ 54 90 @Override 55 91 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 92 return getEquality(node1, node2, null); 93 } 94 95 /** 96 * 97 */ 98 private NodeEquality getEquality(ITaskTreeNode node1, 99 ITaskTreeNode node2, 100 NodeEquality requiredEqualityLevel) 101 { 56 102 ISelection selection = null; 57 103 ITaskTreeNode node = null; … … 59 105 if (node1 instanceof ISelection) { 60 106 if (node2 instanceof ISelection) { 61 // the rule is not responsible for two iterations107 // the rule is not responsible for two selections 62 108 return null; 63 109 } … … 68 114 else if (node2 instanceof ISelection) { 69 115 if (node1 instanceof ISelection) { 70 // the rule is not responsible for two iterations116 // the rule is not responsible for two selections 71 117 return null; 72 118 } … … 79 125 } 80 126 81 // now, that we found the iteration and the node, lets compare the child of the iteration127 // now, that we found the selection and the node, lets compare the children of the selection 82 128 // with the node. 83 if (selection.getChildren().size() < 1) { 129 List<ITaskTreeNode> children = selection.getChildren(); 130 131 if (children.size() < 1) { 84 132 return null; 85 133 } … … 87 135 NodeEquality mostConcreteNodeEquality = null; 88 136 89 for (ITaskTreeNode child : selection.getChildren()) {90 NodeEquality nodeEquality = mRuleManager.applyRules(child, node);137 for (ITaskTreeNode child : children) { 138 NodeEquality nodeEquality = callRuleManager(child, node, requiredEqualityLevel); 91 139 92 140 if (nodeEquality != NodeEquality.UNEQUAL) { … … 94 142 mostConcreteNodeEquality = nodeEquality; 95 143 } 96 else { 97 mostConcreteNodeEquality = 98 mostConcreteNodeEquality.getCommonDenominator(nodeEquality); 144 else if (mostConcreteNodeEquality.isAtLeast(nodeEquality)) { 145 mostConcreteNodeEquality = nodeEquality; 146 147 } 148 149 if ((requiredEqualityLevel != null) && 150 (mostConcreteNodeEquality.isAtLeast(requiredEqualityLevel))) 151 { 152 // 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. 154 // So we break up checking further children. 155 break; 99 156 } 100 157 } … … 111 168 112 169 } 170 171 /** 172 * <p> 173 * TODO: comment 174 * </p> 175 * 176 * @param child1 177 * @param child2 178 * @param requiredEqualityLevel 179 * @return 180 */ 181 private NodeEquality callRuleManager(ITaskTreeNode child1, 182 ITaskTreeNode child2, 183 NodeEquality requiredEqualityLevel) 184 { 185 if (requiredEqualityLevel == null) { 186 return mRuleManager.compare(child1, child2); 187 } 188 else if (mRuleManager.areAtLeastEqual(child1, child2, requiredEqualityLevel)) { 189 return requiredEqualityLevel; 190 } 191 else { 192 return NodeEquality.UNEQUAL; 193 } 194 } 113 195 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/nodeequality/NodeComparisonRule.java
r1113 r1125 30 30 /** 31 31 * <p> 32 * checks if the rule is applicable for comparing the two provided nodes 33 * </p> 34 * 35 * @param node1 the first task tree node to compare 36 * @param node2 the second task tree node to compare 37 * 38 * @return true, if the rule is applicable, false else 39 */ 40 public boolean isApplicable(ITaskTreeNode node1, ITaskTreeNode node2); 41 42 /** 43 * <p> 44 * checks, if the provided nodes are lexically equal 45 * </p> 46 * 47 * @param node1 the first task tree node to compare 48 * @param node2 the second task tree node to compare 49 * 50 * @return true, if the nodes are equal, false else 51 */ 52 public boolean areLexicallyEqual(ITaskTreeNode node1, ITaskTreeNode node2); 53 54 /** 55 * <p> 56 * checks, if the provided nodes are syntactically equal 57 * </p> 58 * 59 * @param node1 the first task tree node to compare 60 * @param node2 the second task tree node to compare 61 * 62 * @return true, if the nodes are equal, false else 63 */ 64 public boolean areSyntacticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2); 65 66 /** 67 * <p> 68 * checks, if the provided nodes are semantically equal 69 * </p> 70 * 71 * @param node1 the first task tree node to compare 72 * @param node2 the second task tree node to compare 73 * 74 * @return true, if the nodes are equal, false else 75 */ 76 public boolean areSemanticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2); 77 78 /** 79 * <p> 32 80 * compares two nodes with each other. The result of the method is either a node equality or 33 81 * null. If it is null, it means, that the rule is not able to correctly compare the two given -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/nodeequality/NodeEqualityRuleManager.java
r1113 r1125 72 72 * manager before a call to this method. 73 73 */ 74 public NodeEquality applyRules(ITaskTreeNode node1, ITaskTreeNode node2)74 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) 75 75 throws IllegalStateException 76 76 { … … 83 83 84 84 for (NodeComparisonRule rule : mRuleIndex) { 85 nodeEquality = rule.compare(node1, node2); 86 87 if (nodeEquality != null) { 88 // LOG.warning("used rule " + rule + " for equality check"); 89 return nodeEquality; 85 if (rule.isApplicable(node1, node2)) { 86 nodeEquality = rule.compare(node1, node2); 87 if (nodeEquality != null) { 88 // LOG.warning("used rule " + rule + " for equality check"); 89 return nodeEquality; 90 } 90 91 } 91 92 } … … 96 97 } 97 98 99 /** 100 * <p> 101 * TODO: comment 102 * </p> 103 * 104 * @param child1 105 * @param child2 106 * @param equalityLevel 107 * @return 108 */ 109 public boolean areAtLeastEqual(ITaskTreeNode node1, 110 ITaskTreeNode node2, 111 NodeEquality equalityLevel) 112 { 113 if (equalityLevel == null) { 114 throw new IllegalArgumentException("required equality level must not be null"); 115 } 116 117 switch (equalityLevel) { 118 case IDENTICAL: 119 return areIdentical(node1, node2); 120 case LEXICALLY_EQUAL: 121 return areLexicallyEqual(node1, node2); 122 case SYNTACTICALLY_EQUAL: 123 return areSyntacticallyEqual(node1, node2); 124 case SEMANTICALLY_EQUAL: 125 return areSemanticallyEqual(node1, node2); 126 case UNEQUAL: 127 return !areSemanticallyEqual(node1, node2); 128 default: 129 throw new IllegalArgumentException("unknown required equality: " + equalityLevel); 130 } 131 } 132 133 /** 134 * <p> 135 * TODO: comment 136 * </p> 137 * 138 * @param child1 139 * @param child2 140 * @return 141 */ 142 public boolean areIdentical(ITaskTreeNode 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(ITaskTreeNode 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(ITaskTreeNode 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(ITaskTreeNode 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)) { 218 return true; 219 } 220 } 221 222 return false; 223 } 224 98 225 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/nodeequality/NodeIdentityRule.java
r1113 r1125 29 29 public class NodeIdentityRule implements NodeComparisonRule { 30 30 31 /* 32 * (non-Javadoc) 33 * 34 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 31 /* (non-Javadoc) 32 * @see NodeComparisonRule#isApplicable(ITaskTreeNode, ITaskTreeNode) 33 */ 34 @Override 35 public boolean isApplicable(ITaskTreeNode node1, ITaskTreeNode node2) { 36 return (node1 == node2); 37 } 38 39 /* (non-Javadoc) 40 * @see NodeComparisonRule#areLexicallyEqual(ITaskTreeNode, ITaskTreeNode) 41 */ 42 @Override 43 public boolean areLexicallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 44 return (node1 == node2); 45 } 46 47 /* (non-Javadoc) 48 * @see NodeComparisonRule#areSyntacticallyEqual(ITaskTreeNode, ITaskTreeNode) 49 */ 50 @Override 51 public boolean areSyntacticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 52 return (node1 == node2); 53 } 54 55 /* (non-Javadoc) 56 * @see NodeComparisonRule#areSemanticallyEqual(ITaskTreeNode, ITaskTreeNode) 57 */ 58 @Override 59 public boolean areSemanticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 60 return (node1 == node2); 61 } 62 63 /* (non-Javadoc) 64 * @see NodeComparisonRule#compare(ITaskTreeNode, ITaskTreeNode) 35 65 */ 36 66 @Override 37 67 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 38 if ( node1 == node2) {68 if (isApplicable(node1, node2)) { 39 69 return NodeEquality.IDENTICAL; 40 70 } -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/nodeequality/SelectionComparisonRule.java
r1113 r1125 14 14 15 15 package de.ugoe.cs.autoquest.tasktrees.nodeequality; 16 17 import java.util.List; 16 18 17 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; … … 51 53 } 52 54 53 /* 54 * (non-Javadoc) 55 /* (non-Javadoc) 56 * @see NodeComparisonRule#isApplicable(ITaskTreeNode, ITaskTreeNode) 57 */ 58 @Override 59 public boolean isApplicable(ITaskTreeNode node1, ITaskTreeNode node2) { 60 return (node1 instanceof ISelection) && (node2 instanceof ISelection); 61 } 62 63 /* (non-Javadoc) 64 * @see NodeComparisonRule#areLexicallyEqual(ITaskTreeNode, ITaskTreeNode) 65 */ 66 @Override 67 public boolean areLexicallyEqual(ITaskTreeNode 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(ITaskTreeNode, ITaskTreeNode) 74 */ 75 @Override 76 public boolean areSyntacticallyEqual(ITaskTreeNode 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(ITaskTreeNode, ITaskTreeNode) 83 */ 84 @Override 85 public boolean areSemanticallyEqual(ITaskTreeNode 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(ITaskTreeNode, ITaskTreeNode) 92 */ 93 @Override 94 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 95 return getEquality(node1, node2, null); 96 } 97 98 /** 55 99 * 56 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 57 */ 58 @Override 59 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 60 if ((!(node1 instanceof ISelection)) || (!(node2 instanceof ISelection))) { 61 return null; 62 } 63 64 if (node1 == node2) { 65 return NodeEquality.IDENTICAL; 66 } 67 68 // if both sequences do not have children, they are identical. If only one of them has 69 // children, they are unequal. 70 if ((node1.getChildren().size() == 0) && (node2.getChildren().size() == 0)) { 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(); 107 108 // if both selections do not have children, they are lexically equal. If only one of them 109 // has children, they are unequal. 110 if ((children1.size() == 0) && (children2.size() == 0)) { 71 111 return NodeEquality.LEXICALLY_EQUAL; 72 112 } 73 else if (( node1.getChildren().size() == 0) || (node2.getChildren().size() == 0)) {113 else if ((children1.size() == 0) || (children2.size() == 0)) { 74 114 return NodeEquality.UNEQUAL; 75 115 } 76 116 77 NodeEquality selectionEquality = NodeEquality.LEXICALLY_EQUAL; 78 79 // compare each child of selection one with each child of selection two 117 NodeEquality selectionEquality; 118 119 if (requiredEqualityLevel == null) { 120 // calculate the common equality level for all children of both selections. 121 // do it in both directions to ensure commutative comparison 122 selectionEquality = getCommonEqualityLevel(children1, children2); 123 if (selectionEquality != NodeEquality.UNEQUAL) { 124 return selectionEquality.getCommonDenominator 125 (getCommonEqualityLevel(children2, children1)); 126 } 127 else { 128 return NodeEquality.UNEQUAL; 129 } 130 } 131 else { 132 // we are searching for a specific equality 133 if (checkEqualityLevel(children1, children2, requiredEqualityLevel) && 134 checkEqualityLevel(children2, children1, requiredEqualityLevel)) 135 { 136 return requiredEqualityLevel; 137 } 138 else { 139 return NodeEquality.UNEQUAL; 140 } 141 } 142 } 143 144 /** 145 * <p> 146 * TODO: comment 147 * </p> 148 * 149 * @param children1 150 * @param children2 151 * @param requiredEqualityLevel 152 */ 153 private NodeEquality getCommonEqualityLevel(List<ITaskTreeNode> children1, 154 List<ITaskTreeNode> children2) 155 { 156 NodeEquality listEquality = NodeEquality.LEXICALLY_EQUAL; 157 80 158 NodeEquality childEquality; 81 159 NodeEquality currentEquality; 82 for (ITaskTreeNode child1 : node1.getChildren()) {160 for (ITaskTreeNode child1 : children1) { 83 161 childEquality = null; 84 for (ITaskTreeNode child2 : node2.getChildren()) {85 currentEquality = mRuleManager.applyRules(child1, child2);162 for (ITaskTreeNode child2 : children2) { 163 currentEquality = callRuleManager(child1, child2, null); 86 164 if ((currentEquality != null) && (currentEquality != NodeEquality.UNEQUAL)) { 87 165 if (childEquality == null) { … … 91 169 childEquality = childEquality.getCommonDenominator(currentEquality); 92 170 } 93 } 94 } 95 96 if (childEquality != null) { 97 selectionEquality = selectionEquality.getCommonDenominator(childEquality); 98 } 99 else { 100 return NodeEquality.UNEQUAL; 101 } 102 } 103 104 // compare each child of selection two with each child of selection one 105 for (ITaskTreeNode child2 : node2.getChildren()) { 106 childEquality = null; 107 for (ITaskTreeNode child1 : node1.getChildren()) { 108 currentEquality = mRuleManager.applyRules(child1, child2); 109 if ((currentEquality != null) && (currentEquality != NodeEquality.UNEQUAL)) { 110 if (childEquality == null) { 111 childEquality = currentEquality; 112 } 113 else { 114 childEquality = childEquality.getCommonDenominator(currentEquality); 171 172 if (childEquality == NodeEquality.SEMANTICALLY_EQUAL) { 173 // as we calculate only the common denominator, we can break up here for 174 // the current child. We will not improve the denominator anymore 175 break; 115 176 } 116 177 } 117 178 } 118 179 119 if (childEquality != null) { 120 selectionEquality = selectionEquality.getCommonDenominator(childEquality); 180 if (childEquality == null) { 181 // we did not find any child in the second list, that is equal to the searched 182 // child 183 return NodeEquality.UNEQUAL; 121 184 } 122 185 else { 123 return NodeEquality.UNEQUAL; 124 } 125 } 126 127 return selectionEquality; 186 listEquality = listEquality.getCommonDenominator(childEquality); 187 } 188 } 189 190 return listEquality; 191 } 192 193 /** 194 * <p> 195 * TODO: comment 196 * </p> 197 * 198 * @param children1 199 * @param children2 200 * @param requiredEqualityLevel 201 */ 202 private boolean checkEqualityLevel(List<ITaskTreeNode> children1, 203 List<ITaskTreeNode> children2, 204 NodeEquality requiredEqualityLevel) 205 { 206 NodeEquality childEquality; 207 NodeEquality currentEquality; 208 for (ITaskTreeNode child1 : children1) { 209 childEquality = null; 210 for (ITaskTreeNode child2 : children2) { 211 currentEquality = callRuleManager(child1, child2, requiredEqualityLevel); 212 if ((currentEquality != null) && (currentEquality.isAtLeast(requiredEqualityLevel))) 213 { 214 // we found at least one equal child with sufficient equality in the 215 // second list. So be can break up for this child. 216 childEquality = currentEquality; 217 break; 218 } 219 } 220 221 if (childEquality == null) { 222 // we did not find any child in the second list, that is equal to the searched 223 // child 224 return false; 225 } 226 } 227 228 // for all children, we found an equality 229 return true; 230 } 231 232 /** 233 * <p> 234 * TODO: comment 235 * </p> 236 * 237 * @param child1 238 * @param child2 239 * @param requiredEqualityLevel 240 * @return 241 */ 242 private NodeEquality callRuleManager(ITaskTreeNode child1, 243 ITaskTreeNode child2, 244 NodeEquality requiredEqualityLevel) 245 { 246 if (requiredEqualityLevel == null) { 247 return mRuleManager.compare(child1, child2); 248 } 249 else if (mRuleManager.areAtLeastEqual(child1, child2, requiredEqualityLevel)) { 250 return requiredEqualityLevel; 251 } 252 else { 253 return NodeEquality.UNEQUAL; 254 } 128 255 } 129 256 -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/nodeequality/SequenceComparisonRule.java
r1113 r1125 14 14 15 15 package de.ugoe.cs.autoquest.tasktrees.nodeequality; 16 17 import java.util.List; 16 18 17 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; … … 47 49 } 48 50 49 /* 50 * (non-Javadoc) 51 * 52 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 51 /* (non-Javadoc) 52 * @see NodeComparisonRule#isApplicable(ITaskTreeNode, ITaskTreeNode) 53 */ 54 @Override 55 public boolean isApplicable(ITaskTreeNode node1, ITaskTreeNode node2) { 56 return (node1 instanceof ISequence) && (node2 instanceof ISequence); 57 } 58 59 /* (non-Javadoc) 60 * @see NodeComparisonRule#areLexicallyEqual(ITaskTreeNode, ITaskTreeNode) 61 */ 62 @Override 63 public boolean areLexicallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 64 NodeEquality equality = getEquality(node1, node2, NodeEquality.LEXICALLY_EQUAL); 65 return (equality != null) && (equality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)); 66 } 67 68 /* (non-Javadoc) 69 * @see NodeComparisonRule#areSyntacticallyEqual(ITaskTreeNode, ITaskTreeNode) 70 */ 71 @Override 72 public boolean areSyntacticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 73 NodeEquality equality = getEquality(node1, node2, NodeEquality.SYNTACTICALLY_EQUAL); 74 return (equality != null) && (equality.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL)); 75 } 76 77 /* (non-Javadoc) 78 * @see NodeComparisonRule#areSemanticallyEqual(ITaskTreeNode, ITaskTreeNode) 79 */ 80 @Override 81 public boolean areSemanticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 82 NodeEquality equality = getEquality(node1, node2, NodeEquality.SEMANTICALLY_EQUAL); 83 return (equality != null) && (equality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)); 84 } 85 86 /* (non-Javadoc) 87 * @see NodeComparisonRule#compare(ITaskTreeNode, ITaskTreeNode) 53 88 */ 54 89 @Override 55 90 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 56 if ((!(node1 instanceof ISequence)) || (!(node2 instanceof ISequence))) { 57 return null; 58 } 91 return getEquality(node1, node2, null); 92 } 59 93 60 if (node1 == node2) { 61 return NodeEquality.IDENTICAL; 62 } 94 /** 95 * 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(); 63 103 64 104 // if both sequences do not have children, they are equal although this doesn't make sense 65 if (( node1.getChildren().size() == 0) && (node2.getChildren().size() == 0)) {105 if ((children1.size() == 0) && (children2.size() == 0)) { 66 106 return NodeEquality.LEXICALLY_EQUAL; 67 107 } 68 108 69 if ( node1.getChildren().size() != node2.getChildren().size()) {109 if (children1.size() != children2.size()) { 70 110 return NodeEquality.UNEQUAL; 71 111 } 72 112 73 113 NodeEquality resultingEquality = NodeEquality.LEXICALLY_EQUAL; 74 for (int i = 0; i < node1.getChildren().size(); i++) {75 ITaskTreeNode child1 = node1.getChildren().get(i);76 ITaskTreeNode child2 = node2.getChildren().get(i);114 for (int i = 0; i < children1.size(); i++) { 115 ITaskTreeNode child1 = children1.get(i); 116 ITaskTreeNode child2 = children2.get(i); 77 117 78 NodeEquality nodeEquality = mRuleManager.applyRules(child1, child2);118 NodeEquality nodeEquality = callRuleManager(child1, child2, requiredEqualityLevel); 79 119 80 120 if ((nodeEquality == null) || (nodeEquality == NodeEquality.UNEQUAL)) { … … 88 128 } 89 129 130 /** 131 * <p> 132 * TODO: comment 133 * </p> 134 * 135 * @param child1 136 * @param child2 137 * @param requiredEqualityLevel 138 * @return 139 */ 140 private NodeEquality callRuleManager(ITaskTreeNode child1, 141 ITaskTreeNode child2, 142 NodeEquality requiredEqualityLevel) 143 { 144 if (requiredEqualityLevel == null) { 145 return mRuleManager.compare(child1, child2); 146 } 147 else if (mRuleManager.areAtLeastEqual(child1, child2, requiredEqualityLevel)) { 148 return requiredEqualityLevel; 149 } 150 else { 151 return NodeEquality.UNEQUAL; 152 } 153 } 90 154 }
Note: See TracChangeset
for help on using the changeset viewer.