- Timestamp:
- 09/11/12 16:45:51 (12 years ago)
- Location:
- trunk
- Files:
-
- 6 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/nodeequality/NodeEqualityTest.java
r655 r807 6 6 7 7 /** 8 * TODO comment 9 * 10 * @version $Revision: $ $Date: 15.08.2012$ 11 * @author 2012, last modified by $Author: pharms$ 8 * @author Patrick Harms 12 9 */ 13 10 public class NodeEqualityTest { 14 11 15 12 /** 16 * TODO: comment17 13 * 18 14 */ -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/nodeequality/SequenceComparisonRuleTest.java
r655 r807 5 5 import org.junit.Test; 6 6 7 import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; 7 8 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 8 9 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; … … 14 15 15 16 /** 16 * <p> 17 * TODO comment 18 * </p> 19 * 20 * @version $Revision: $ $Date: 16.08.2012$ 21 * @author 2012, last modified by $Author: pharms$ 17 * @author Patrick Harms 22 18 */ 23 19 public class SequenceComparisonRuleTest { 24 20 25 21 /** 26 * <p> 27 * TODO: comment 28 * </p> 29 * 22 * 30 23 */ 31 24 @Test … … 45 38 46 39 ISequence sequence1 = treeNodeFactory.createNewSequence(); 47 assertEquals(NodeEquality. LEXICALLY_EQUAL, rule.compare(sequence1, sequence1));40 assertEquals(NodeEquality.IDENTICAL, rule.compare(sequence1, sequence1)); 48 41 49 42 ISequence sequence2 = treeNodeFactory.createNewSequence(); … … 54 47 treeBuilder.addChild(sequence1, task1); 55 48 56 assert Null(rule.compare(sequence1, sequence2));57 assert Null(rule.compare(sequence2, sequence1));49 assertEquals(NodeEquality.UNEQUAL, rule.compare(sequence1, sequence2)); 50 assertEquals(NodeEquality.UNEQUAL, rule.compare(sequence2, sequence1)); 58 51 59 52 treeBuilder.addChild(sequence2, task1); … … 64 57 treeBuilder.addChild(sequence1, task2); 65 58 66 assert Null(rule.compare(sequence1, sequence2));67 assert Null(rule.compare(sequence2, sequence1));59 assertEquals(NodeEquality.UNEQUAL, rule.compare(sequence1, sequence2)); 60 assertEquals(NodeEquality.UNEQUAL, rule.compare(sequence2, sequence1)); 68 61 69 62 treeBuilder.addChild(sequence2, task2); … … 76 69 treeBuilder.addChild(sequence3, task1); 77 70 78 assertNull(rule.compare(sequence1, sequence3)); 79 assertNull(rule.compare(sequence3, sequence1)); 71 assertEquals(NodeEquality.UNEQUAL, rule.compare(sequence1, sequence3)); 72 assertEquals(NodeEquality.UNEQUAL, rule.compare(sequence3, sequence1)); 73 assertEquals(NodeEquality.UNEQUAL, rule.compare(sequence2, sequence3)); 74 assertEquals(NodeEquality.UNEQUAL, rule.compare(sequence3, sequence2)); 75 76 ISelection selection = treeNodeFactory.createNewSelection(); 77 assertNull(rule.compare(sequence1, selection)); 78 assertNull(rule.compare(selection, sequence1)); 79 assertNull(rule.compare(sequence2, selection)); 80 assertNull(rule.compare(selection, sequence2)); 81 assertNull(rule.compare(sequence3, selection)); 82 assertNull(rule.compare(selection, sequence3)); 80 83 } 81 84 -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/IterationComparisonRule.java
r655 r807 41 41 * </tr> 42 42 * <tr> 43 * <td>an iteration with a selection of syntactically equal children</td> 44 * <td>an iteration with a selection of syntactically equal children that are all syntactically 45 * equal to the selection of children of iteration 1</td> 46 * <td><code>NodeEquality.SYNTACTICALLY_EQUAL</code></td> 47 * </tr> 48 * <tr> 43 49 * <td>an iteration with a selection of semantically equal children</td> 44 50 * <td>an iteration with a child that is semantically equal to the children of the child 45 51 * selection of iteration 1</td> 52 * <td><code>NodeEquality.SEMANTICALLY_EQUAL</code></td> 53 * </tr> 54 * <tr> 55 * <td>an iteration with a selection of semantically equal children</td> 56 * <td>an iteration with a selection of semantically equal children that are all semantically 57 * equal to the selection of children of iteration 1</td> 46 58 * <td><code>NodeEquality.SEMANTICALLY_EQUAL</code></td> 47 59 * </tr> … … 80 92 } 81 93 94 if (node1 == node2) { 95 return NodeEquality.IDENTICAL; 96 } 97 82 98 // if both iterations do not have children, they are equal although this doesn't make sense 83 99 if ((node1.getChildren().size() == 0) && (node2.getChildren().size() == 0)) { 84 return NodeEquality.IDENTICAL; 100 return NodeEquality.LEXICALLY_EQUAL; 101 } 102 else if ((node1.getChildren().size() == 0) || (node2.getChildren().size() == 0)) { 103 return NodeEquality.UNEQUAL; 85 104 } 86 105 … … 102 121 103 122 if (nodeEquality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)) { 104 return nodeEquality; 123 // prevent, that identical is returned, because the iterations itself are not identical 124 // although the iterated tasks are 125 if (nodeEquality == NodeEquality.IDENTICAL) { 126 return NodeEquality.LEXICALLY_EQUAL; 127 } 128 else { 129 return nodeEquality; 130 } 105 131 } 106 132 … … 115 141 /** 116 142 * <p> 117 * compares two task tree nodes. One of them must be a selection of at least semantically118 * equal children. The other one can be any task tree node. The method returns a node equality119 * that is not <code>NodeEquality.UNEQUAL</code> if the other node is at least semantically120 * equal to the children of the selection. It returns more concrete equalities, if the121 * equality between the other node and the childrenof the selection is more concrete.143 * compares two task tree nodes. One of them must be a selection, the other one can be any task 144 * tree node. The method returns a node equality that is not <code>NodeEquality.UNEQUAL</code> 145 * if the other node is at least semantically equal to the children of the selection. It 146 * returns more concrete equalities, if the equality between the other node and the children 147 * of the selection is more concrete. 122 148 * </p> 123 149 * … … 144 170 } 145 171 146 NodeEquality lessConcreteEqualityForAllComparisons = NodeEquality.IDENTICAL; 172 // Iterations, where one has a selection and the other one not can at most be syntactically 173 // equal but not identical 174 NodeEquality commonDenominatorForAllComparisons = NodeEquality.SYNTACTICALLY_EQUAL; 147 175 148 176 for (ITaskTreeNode child : selection.getChildren()) { 149 177 NodeEquality nodeEquality = mRuleManager.applyRules(node, child); 150 178 151 if (!nodeEquality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)) { 179 if ((nodeEquality == null) || (nodeEquality == NodeEquality.UNEQUAL)) 180 { 152 181 return NodeEquality.UNEQUAL; 153 182 } 154 else if (!lessConcreteEqualityForAllComparisons.isAtLeast(nodeEquality)) {155 lessConcreteEqualityForAllComparisons = nodeEquality;156 }183 184 commonDenominatorForAllComparisons = 185 commonDenominatorForAllComparisons.getCommonDenominator(nodeEquality); 157 186 } 158 187 159 return lessConcreteEqualityForAllComparisons;188 return commonDenominatorForAllComparisons; 160 189 } 161 190 -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/NodeEquality.java
r655 r807 90 90 } 91 91 } 92 93 /** 94 * <p> 95 * returns the common denominator of this node equality and the provided one. I.e. if one 96 * equality is e.g. syntactical and the other one only semantical, then semantical is returned. 97 * </p> 98 * 99 * @param equality the equality, to compare this with 100 * @return 101 */ 102 public NodeEquality getCommonDenominator(NodeEquality otherEquality) { 103 if (this.isAtLeast(otherEquality)) { 104 return otherEquality; 105 } 106 else if (otherEquality.isAtLeast(this)) { 107 return this; 108 } 109 else { 110 return NodeEquality.UNEQUAL; 111 } 112 } 92 113 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/NodeEqualityRuleManager.java
r725 r807 33 33 mRuleIndex = new ArrayList<NodeComparisonRule>(); 34 34 mRuleIndex.add(new NodeIdentityRule()); 35 mRuleIndex.add(new GUIEventTaskComparisonRule()); 36 mRuleIndex.add(new EventTaskComparisonRule()); 35 37 mRuleIndex.add(new IterationComparisonRule(this)); 36 38 mRuleIndex.add(new SequenceComparisonRule(this)); -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/NodeIdentityRule.java
r655 r807 22 22 @Override 23 23 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 24 if ( (node1 == node2) || ((node1 != null) && (node1.equals(node2)))) {24 if (node1 == node2) { 25 25 return NodeEquality.IDENTICAL; 26 26 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/SelectionComparisonRule.java
r655 r807 7 7 * <p> 8 8 * this node comparison rule is capable of comparing selections. If both selections do not have 9 * children, they are treated as lexically equal. If they have the same number of children other 10 * than 0 and all these children are lexically equal, then the selections are lexically equal. 11 * They are syntactically equal, if each child of both selections is syntactically equal to any 12 * other child. The rule can not compare semantical equality if the nodes are not at least 13 * syntactically equal and returns null, if it can not decide this. 9 * children, they are treated as identical. If they have children, each child of both selections 10 * is compared to each child of the respective other selection. The resulting equality is the most 11 * concrete one of all these comparisons. I.e. if all children are at least lexically equal, then 12 * the selections are lexically equal. If all children are at least syntactically equal, then the 13 * selections are syntactically equal. If all children are at least semantically equal, then the 14 * selections are semantically equal. If only one of the selections has children, then the 15 * selections are unequal. 14 16 * </p> 15 17 * … … 46 48 } 47 49 48 // if both sequences do not have children, they are equal although this doesn't make sense 50 if (node1 == node2) { 51 return NodeEquality.IDENTICAL; 52 } 53 54 // if both sequences do not have children, they are identical. If only one of them has 55 // children, they are unequal. 49 56 if ((node1.getChildren().size() == 0) && (node2.getChildren().size() == 0)) { 50 57 return NodeEquality.LEXICALLY_EQUAL; 51 58 } 59 else if ((node1.getChildren().size() == 0) || (node2.getChildren().size() == 0)) { 60 return NodeEquality.UNEQUAL; 61 } 52 62 53 // Selections are syntactically equal, if they have children, which are all syntactically 54 // equal. 55 // They are lexically equals, if they have the same number and order of lexically equal 56 // children 57 boolean lexicallyEqual = node1.getChildren().size() == node2.getChildren().size(); 63 NodeEquality selectionEquality = NodeEquality.LEXICALLY_EQUAL; 58 64 59 for (int i = 0; i < node1.getChildren().size(); i++) {60 ITaskTreeNode child1 = node1.getChildren().get(i);61 boolean foundLexicallyEqualChild = false;62 63 for (int j = 0; j < node2.getChildren().size(); j++) {64 ITaskTreeNode child2 = node2.getChildren().get(j);65 66 NodeEquality nodeEquality = mRuleManager.applyRules(child1, child2);67 68 if (!nodeEquality.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL)) {69 return null;70 }71 else if (nodeEquality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)) {72 foundLexicallyEqualChild = true;65 // compare each child of selection one with each child of selection two 66 NodeEquality childEquality; 67 NodeEquality currentEquality; 68 for (ITaskTreeNode child1 : node1.getChildren()) { 69 childEquality = null; 70 for (ITaskTreeNode child2 : node2.getChildren()) { 71 currentEquality = mRuleManager.applyRules(child1, child2); 72 if ((currentEquality != null) && (currentEquality != NodeEquality.UNEQUAL)) { 73 if (childEquality == null) { 74 childEquality = currentEquality; 75 } 76 else { 77 childEquality = childEquality.getCommonDenominator(currentEquality); 78 } 73 79 } 74 80 } 75 76 // if we compare two children at the same position and if they are lexically equal 77 // then it can be further expected, that the selections are lexically equal 78 lexicallyEqual &= foundLexicallyEqualChild; 81 82 if (childEquality != null) { 83 selectionEquality = selectionEquality.getCommonDenominator(childEquality); 84 } 85 else { 86 return NodeEquality.UNEQUAL; 87 } 79 88 } 80 89 81 if (lexicallyEqual) { 82 return NodeEquality.LEXICALLY_EQUAL; 90 // compare each child of selection two with each child of selection one 91 for (ITaskTreeNode child2 : node2.getChildren()) { 92 childEquality = null; 93 for (ITaskTreeNode child1 : node1.getChildren()) { 94 currentEquality = mRuleManager.applyRules(child1, child2); 95 if ((currentEquality != null) && (currentEquality != NodeEquality.UNEQUAL)) { 96 if (childEquality == null) { 97 childEquality = currentEquality; 98 } 99 else { 100 childEquality = childEquality.getCommonDenominator(currentEquality); 101 } 102 } 103 } 104 105 if (childEquality != null) { 106 selectionEquality = selectionEquality.getCommonDenominator(childEquality); 107 } 108 else { 109 return NodeEquality.UNEQUAL; 110 } 83 111 } 84 else { 85 return NodeEquality.SYNTACTICALLY_EQUAL; 86 } 112 113 return selectionEquality; 87 114 } 115 88 116 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/SequenceComparisonRule.java
r655 r807 44 44 } 45 45 46 if (node1 == node2) { 47 return NodeEquality.IDENTICAL; 48 } 49 46 50 // if both sequences do not have children, they are equal although this doesn't make sense 47 51 if ((node1.getChildren().size() == 0) && (node2.getChildren().size() == 0)) { … … 49 53 } 50 54 51 //52 55 if (node1.getChildren().size() != node2.getChildren().size()) { 53 return null;56 return NodeEquality.UNEQUAL; 54 57 } 55 58 59 NodeEquality resultingEquality = NodeEquality.LEXICALLY_EQUAL; 56 60 for (int i = 0; i < node1.getChildren().size(); i++) { 57 61 ITaskTreeNode child1 = node1.getChildren().get(i); … … 60 64 NodeEquality nodeEquality = mRuleManager.applyRules(child1, child2); 61 65 62 if ( !nodeEquality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)) {63 return null;66 if ((nodeEquality == null) || (nodeEquality == NodeEquality.UNEQUAL)) { 67 return NodeEquality.UNEQUAL; 64 68 } 69 70 resultingEquality = resultingEquality.getCommonDenominator(nodeEquality); 65 71 } 66 72 67 return NodeEquality.LEXICALLY_EQUAL;73 return resultingEquality; 68 74 } 69 75
Note: See TracChangeset
for help on using the changeset viewer.