Changeset 1146 for trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/IterationComparisonRule.java
- Timestamp:
- 04/04/13 16:06:07 (11 years ago)
- Location:
- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality
- Files:
-
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.