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