Changeset 1146 for trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/SelectionComparisonRule.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/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 }
Note: See TracChangeset
for help on using the changeset viewer.