Changeset 1146 for trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/TaskAndIterationComparisonRule.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/TaskAndIterationComparisonRule.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.IIteration; 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask TreeNode;18 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 21 19 22 20 /** 23 21 * <p> 24 * This class is capable of comparing any task tree nodewhich is not an iteration with an25 * iteration. This is needed, because iterations may iterate exactly that node. In this26 * case, the iteration would be equal to that nodeif it was executed exactly once. The rule27 * returns lexically equal, it the child of the iteration is lexically equal to the node22 * This class is capable of comparing any task which is not an iteration with an 23 * iteration. This is needed, because iterations may iterate exactly that task. In this 24 * case, the iteration would be equal to that task if it was executed exactly once. The rule 25 * returns lexically equal, it the child of the iteration is lexically equal to the task 28 26 * or if the child of the iteration is a selection and this selections contains a lexically equal 29 * node. The same applies for syntactical and semantical equality.27 * task. The same applies for syntactical and semantical equality. 30 28 * </p> 31 29 32 30 * @author Patrick Harms 33 31 */ 34 public class NodeAndIterationComparisonRule implements NodeComparisonRule {32 public class TaskAndIterationComparisonRule implements TaskComparisonRule { 35 33 36 /** the rule manager for internally comparing task tree nodes */37 private NodeEqualityRuleManager mRuleManager;34 /** the rule manager for internally comparing tasks */ 35 private TaskEqualityRuleManager mRuleManager; 38 36 39 37 /** 40 38 * <p> 41 * simple constructor to provide the rule with the nodeequality rule manager to be able42 * to perform comparisons of the children of provided task tree nodes39 * simple constructor to provide the rule with the task equality rule manager to be able 40 * to perform comparisons of the children of provided tasks 43 41 * </p> 44 42 * 45 * @param ruleManager the rule manager for comparing task tree nodes43 * @param ruleManager the rule manager for comparing tasks 46 44 */ 47 NodeAndIterationComparisonRule(NodeEqualityRuleManager ruleManager) {45 TaskAndIterationComparisonRule(TaskEqualityRuleManager ruleManager) { 48 46 super(); 49 47 mRuleManager = ruleManager; … … 51 49 52 50 /* (non-Javadoc) 53 * @see NodeComparisonRule#isApplicable(ITask TreeNode, ITaskTreeNode)51 * @see NodeComparisonRule#isApplicable(ITask, ITask) 54 52 */ 55 53 @Override 56 public boolean isApplicable(ITask TreeNode node1, ITaskTreeNode node2) {57 return (( node1 instanceof IIteration) && (!(node2 instanceof IIteration))) ||58 (( node2 instanceof IIteration) && (!(node1 instanceof IIteration)));54 public boolean isApplicable(ITask task1, ITask task2) { 55 return ((task1 instanceof IIteration) && (!(task2 instanceof IIteration))) || 56 ((task2 instanceof IIteration) && (!(task1 instanceof IIteration))); 59 57 } 60 58 61 59 /* (non-Javadoc) 62 * @see NodeComparisonRule#areLexicallyEqual(ITask TreeNode, ITaskTreeNode)60 * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask) 63 61 */ 64 62 @Override 65 public boolean areLexicallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {66 NodeEquality equality = getEquality(node1, node2, NodeEquality.LEXICALLY_EQUAL);67 return (equality != null) && (equality.isAtLeast( NodeEquality.LEXICALLY_EQUAL));63 public boolean areLexicallyEqual(ITask task1, ITask task2) { 64 TaskEquality equality = getEquality(task1, task2, TaskEquality.LEXICALLY_EQUAL); 65 return (equality != null) && (equality.isAtLeast(TaskEquality.LEXICALLY_EQUAL)); 68 66 } 69 67 70 68 /* (non-Javadoc) 71 * @see NodeComparisonRule#areSyntacticallyEqual(ITask TreeNode, ITaskTreeNode)69 * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask) 72 70 */ 73 71 @Override 74 public boolean areSyntacticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {75 NodeEquality equality = getEquality(node1, node2, NodeEquality.SYNTACTICALLY_EQUAL);76 return (equality != null) && (equality.isAtLeast( NodeEquality.SYNTACTICALLY_EQUAL));72 public boolean areSyntacticallyEqual(ITask task1, ITask task2) { 73 TaskEquality equality = getEquality(task1, task2, TaskEquality.SYNTACTICALLY_EQUAL); 74 return (equality != null) && (equality.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)); 77 75 } 78 76 79 77 /* (non-Javadoc) 80 * @see NodeComparisonRule#areSemanticallyEqual(ITask TreeNode, ITaskTreeNode)78 * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) 81 79 */ 82 80 @Override 83 public boolean areSemanticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {84 NodeEquality equality = getEquality(node1, node2, NodeEquality.SEMANTICALLY_EQUAL);85 return (equality != null) && (equality.isAtLeast( NodeEquality.SEMANTICALLY_EQUAL));81 public boolean areSemanticallyEqual(ITask task1, ITask task2) { 82 TaskEquality equality = getEquality(task1, task2, TaskEquality.SEMANTICALLY_EQUAL); 83 return (equality != null) && (equality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL)); 86 84 } 87 85 88 86 /* (non-Javadoc) 89 * @see NodeComparisonRule#compare(ITask TreeNode, ITaskTreeNode)87 * @see NodeComparisonRule#compare(ITask, ITask) 90 88 */ 91 89 @Override 92 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) {93 return getEquality( node1, node2, null);90 public TaskEquality compare(ITask task1, ITask task2) { 91 return getEquality(task1, task2, null); 94 92 } 95 93 … … 97 95 * 98 96 */ 99 private NodeEquality getEquality(ITaskTreeNode node1, 100 ITaskTreeNode node2, 101 NodeEquality requiredEqualityLevel) 102 { 97 private TaskEquality getEquality(ITask task1, ITask task2, TaskEquality requiredEqualityLevel) { 103 98 IIteration iteration = null; 104 ITask TreeNode node= null;99 ITask task = null; 105 100 106 if ( node1 instanceof IIteration) {107 if ( node2 instanceof IIteration) {101 if (task1 instanceof IIteration) { 102 if (task2 instanceof IIteration) { 108 103 // the rule is not responsible for two iterations 109 104 return null; 110 105 } 111 106 112 iteration = (IIteration) node1;113 node = node2;107 iteration = (IIteration) task1; 108 task = task2; 114 109 } 115 else if ( node2 instanceof IIteration) {116 if ( node1 instanceof IIteration) {110 else if (task2 instanceof IIteration) { 111 if (task1 instanceof IIteration) { 117 112 // the rule is not responsible for two iterations 118 113 return null; 119 114 } 120 115 121 iteration = (IIteration) node2;122 node = node1;116 iteration = (IIteration) task2; 117 task = task1; 123 118 } 124 119 else { … … 126 121 } 127 122 128 List<ITaskTreeNode> children = iteration.getChildren();123 ITask child = iteration.getMarkedTask(); 129 124 130 // now, that we found the iteration and the node, lets compare the child of the iteration131 // with the node.132 if (child ren.size() < 1) {125 // now, that we found the iteration and the task, lets compare the child of the iteration 126 // with the task. 127 if (child == null) { 133 128 return null; 134 129 } 135 130 136 NodeEquality nodeEquality = callRuleManager(children.get(0), node, requiredEqualityLevel);131 TaskEquality taskEquality = callRuleManager(child, task, requiredEqualityLevel); 137 132 138 // although the subtask may be identical to the node, we can not return identical, as139 // the iteration is not identical to the node, but at most lexically equal140 if ( nodeEquality == NodeEquality.IDENTICAL) {141 return NodeEquality.LEXICALLY_EQUAL;133 // although the subtask may be identical to the task, we can not return identical, as 134 // the iteration is not identical to the task, but at most lexically equal 135 if (taskEquality == TaskEquality.IDENTICAL) { 136 return TaskEquality.LEXICALLY_EQUAL; 142 137 } 143 138 else { 144 return nodeEquality;139 return taskEquality; 145 140 } 146 141 … … 157 152 * @return 158 153 */ 159 private NodeEquality callRuleManager(ITaskTreeNodechild1,160 ITask TreeNodechild2,161 NodeEqualityrequiredEqualityLevel)154 private TaskEquality callRuleManager(ITask child1, 155 ITask child2, 156 TaskEquality requiredEqualityLevel) 162 157 { 163 158 if (requiredEqualityLevel == null) { … … 168 163 } 169 164 else { 170 return NodeEquality.UNEQUAL;165 return TaskEquality.UNEQUAL; 171 166 } 172 167 }
Note: See TracChangeset
for help on using the changeset viewer.