Changeset 1125 for trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/nodeequality/IterationComparisonRule.java
- Timestamp:
- 03/18/13 11:46:47 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.