Changeset 1146 for trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/SequenceComparisonRule.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/SequenceComparisonRule.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.ISequence; 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask TreeNode;20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 21 21 22 22 /** … … 31 31 * @author 2012, last modified by $Author: patrick$ 32 32 */ 33 public class SequenceComparisonRule implements NodeComparisonRule {33 public class SequenceComparisonRule implements TaskComparisonRule { 34 34 35 /** the rule manager for internally comparing task tree nodes */36 private NodeEqualityRuleManager mRuleManager;35 /** the rule manager for internally comparing tasks */ 36 private TaskEqualityRuleManager mRuleManager; 37 37 38 38 /** 39 39 * <p> 40 * simple constructor to provide the rule with the nodeequality rule manager to be able41 * to perform comparisons of the children of provided task tree nodes40 * simple constructor to provide the rule with the task equality rule manager to be able 41 * to perform comparisons of the children of provided tasks 42 42 * </p> 43 43 * 44 * @param ruleManager the rule manager for comparing task tree nodes44 * @param ruleManager the rule manager for comparing tasks 45 45 */ 46 SequenceComparisonRule( NodeEqualityRuleManager ruleManager) {46 SequenceComparisonRule(TaskEqualityRuleManager ruleManager) { 47 47 super(); 48 48 mRuleManager = ruleManager; … … 50 50 51 51 /* (non-Javadoc) 52 * @see NodeComparisonRule#isApplicable(ITask TreeNode, ITaskTreeNode)52 * @see NodeComparisonRule#isApplicable(ITask, ITask) 53 53 */ 54 54 @Override 55 public boolean isApplicable(ITask TreeNode node1, ITaskTreeNode node2) {56 return ( node1 instanceof ISequence) && (node2 instanceof ISequence);55 public boolean isApplicable(ITask task1, ITask task2) { 56 return (task1 instanceof ISequence) && (task2 instanceof ISequence); 57 57 } 58 58 59 59 /* (non-Javadoc) 60 * @see NodeComparisonRule#areLexicallyEqual(ITask TreeNode, ITaskTreeNode)60 * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask) 61 61 */ 62 62 @Override 63 public boolean areLexicallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {64 NodeEquality equality = getEquality(node1, node2, NodeEquality.LEXICALLY_EQUAL);65 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)); 66 66 } 67 67 68 68 /* (non-Javadoc) 69 * @see NodeComparisonRule#areSyntacticallyEqual(ITask TreeNode, ITaskTreeNode)69 * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask) 70 70 */ 71 71 @Override 72 public boolean areSyntacticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {73 NodeEquality equality = getEquality(node1, node2, NodeEquality.SYNTACTICALLY_EQUAL);74 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)); 75 75 } 76 76 77 77 /* (non-Javadoc) 78 * @see NodeComparisonRule#areSemanticallyEqual(ITask TreeNode, ITaskTreeNode)78 * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) 79 79 */ 80 80 @Override 81 public boolean areSemanticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {82 NodeEquality equality = getEquality(node1, node2, NodeEquality.SEMANTICALLY_EQUAL);83 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)); 84 84 } 85 85 86 86 /* (non-Javadoc) 87 * @see NodeComparisonRule#compare(ITask TreeNode, ITaskTreeNode)87 * @see NodeComparisonRule#compare(ITask, ITask) 88 88 */ 89 89 @Override 90 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) {91 return getEquality( node1, node2, null);90 public TaskEquality compare(ITask task1, ITask task2) { 91 return getEquality(task1, task2, null); 92 92 } 93 93 … … 95 95 * 96 96 */ 97 private NodeEquality getEquality(ITaskTreeNode node1, 98 ITaskTreeNode node2, 99 NodeEquality requiredEqualityLevel) 100 { 101 List<ITaskTreeNode> children1 = node1.getChildren(); 102 List<ITaskTreeNode> children2 = node2.getChildren(); 97 private TaskEquality getEquality(ITask task1, ITask task2, TaskEquality requiredEqualityLevel) { 98 List<ITask> children1 = ((ISequence) task1).getChildren(); 99 List<ITask> children2 = ((ISequence) task2).getChildren(); 103 100 104 101 // if both sequences do not have children, they are equal although this doesn't make sense 105 102 if ((children1.size() == 0) && (children2.size() == 0)) { 106 return NodeEquality.LEXICALLY_EQUAL;103 return TaskEquality.LEXICALLY_EQUAL; 107 104 } 108 105 109 106 if (children1.size() != children2.size()) { 110 return NodeEquality.UNEQUAL;107 return TaskEquality.UNEQUAL; 111 108 } 112 109 113 NodeEquality resultingEquality = NodeEquality.LEXICALLY_EQUAL;110 TaskEquality resultingEquality = TaskEquality.LEXICALLY_EQUAL; 114 111 for (int i = 0; i < children1.size(); i++) { 115 ITask TreeNodechild1 = children1.get(i);116 ITask TreeNodechild2 = children2.get(i);112 ITask child1 = children1.get(i); 113 ITask child2 = children2.get(i); 117 114 118 NodeEquality nodeEquality = callRuleManager(child1, child2, requiredEqualityLevel);115 TaskEquality taskEquality = callRuleManager(child1, child2, requiredEqualityLevel); 119 116 120 if (( nodeEquality == null) || (nodeEquality == NodeEquality.UNEQUAL)) {121 return NodeEquality.UNEQUAL;117 if ((taskEquality == null) || (taskEquality == TaskEquality.UNEQUAL)) { 118 return TaskEquality.UNEQUAL; 122 119 } 123 120 124 resultingEquality = resultingEquality.getCommonDenominator( nodeEquality);121 resultingEquality = resultingEquality.getCommonDenominator(taskEquality); 125 122 } 126 123 … … 138 135 * @return 139 136 */ 140 private NodeEquality callRuleManager(ITaskTreeNodechild1,141 ITask TreeNodechild2,142 NodeEqualityrequiredEqualityLevel)137 private TaskEquality callRuleManager(ITask child1, 138 ITask child2, 139 TaskEquality requiredEqualityLevel) 143 140 { 144 141 if (requiredEqualityLevel == null) { … … 149 146 } 150 147 else { 151 return NodeEquality.UNEQUAL;148 return TaskEquality.UNEQUAL; 152 149 } 153 150 }
Note: See TracChangeset
for help on using the changeset viewer.