Changeset 1146 for trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/TaskAndSelectionComparisonRule.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/TaskAndSelectionComparisonRule.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 class is capable of comparing any task tree nodewhich is not a selection with a25 * selection. This is needed, because selections may contain exactly that node. Therefore, if26 * this node is selected out of a selection the selection is equal to the nodeitself.27 * The rule returns lexically equal, i t the selection contains a lexically equal node. The same24 * This class is capable of comparing any task which is not a selection with a 25 * selection. This is needed, because selections may contain exactly that task. Therefore, if 26 * this task is selected out of a selection the selection is equal to the task itself. 27 * The rule returns lexically equal, if the selection contains a lexically equal task. The same 28 28 * applies for syntactical and semantical equality. 29 29 * </p> … … 31 31 * @author Patrick Harms 32 32 */ 33 public class NodeAndSelectionComparisonRule implements NodeComparisonRule {33 public class TaskAndSelectionComparisonRule 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 NodeAndSelectionComparisonRule(NodeEqualityRuleManager ruleManager) {46 TaskAndSelectionComparisonRule(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 ISelection) && (!(node2 instanceof ISelection))) ||57 (( node2 instanceof ISelection) && (!(node1 instanceof ISelection)));55 public boolean isApplicable(ITask task1, ITask task2) { 56 return ((task1 instanceof ISelection) && (!(task2 instanceof ISelection))) || 57 ((task2 instanceof ISelection) && (!(task1 instanceof ISelection))); 58 58 } 59 59 60 60 /* (non-Javadoc) 61 * @see NodeComparisonRule#areLexicallyEqual(ITask TreeNode, ITaskTreeNode)61 * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask) 62 62 */ 63 63 @Override 64 public boolean areLexicallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {65 NodeEquality equality = getEquality(node1, node2, NodeEquality.LEXICALLY_EQUAL);66 return (equality != null) && (equality.isAtLeast( NodeEquality.LEXICALLY_EQUAL));64 public boolean areLexicallyEqual(ITask task1, ITask task2) { 65 TaskEquality equality = getEquality(task1, task2, TaskEquality.LEXICALLY_EQUAL); 66 return (equality != null) && (equality.isAtLeast(TaskEquality.LEXICALLY_EQUAL)); 67 67 } 68 68 69 69 /* (non-Javadoc) 70 * @see NodeComparisonRule#areSyntacticallyEqual(ITask TreeNode, ITaskTreeNode)70 * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask) 71 71 */ 72 72 @Override 73 public boolean areSyntacticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {74 NodeEquality equality = getEquality(node1, node2, NodeEquality.SYNTACTICALLY_EQUAL);75 return (equality != null) && (equality.isAtLeast( NodeEquality.SYNTACTICALLY_EQUAL));73 public boolean areSyntacticallyEqual(ITask task1, ITask task2) { 74 TaskEquality equality = getEquality(task1, task2, TaskEquality.SYNTACTICALLY_EQUAL); 75 return (equality != null) && (equality.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)); 76 76 } 77 77 78 78 /* (non-Javadoc) 79 * @see NodeComparisonRule#areSemanticallyEqual(ITask TreeNode, ITaskTreeNode)79 * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) 80 80 */ 81 81 @Override 82 public boolean areSemanticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {83 NodeEquality equality = getEquality(node1, node2, NodeEquality.SEMANTICALLY_EQUAL);84 return (equality != null) && (equality.isAtLeast( NodeEquality.SEMANTICALLY_EQUAL));82 public boolean areSemanticallyEqual(ITask task1, ITask task2) { 83 TaskEquality equality = getEquality(task1, task2, TaskEquality.SEMANTICALLY_EQUAL); 84 return (equality != null) && (equality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL)); 85 85 } 86 86 87 87 /* (non-Javadoc) 88 * @see NodeComparisonRule#compare(ITask TreeNode, ITaskTreeNode)88 * @see NodeComparisonRule#compare(ITask, ITask) 89 89 */ 90 90 @Override 91 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) {92 return getEquality( node1, node2, null);91 public TaskEquality compare(ITask task1, ITask task2) { 92 return getEquality(task1, task2, null); 93 93 } 94 94 … … 96 96 * 97 97 */ 98 private NodeEquality getEquality(ITaskTreeNode node1, 99 ITaskTreeNode node2, 100 NodeEquality requiredEqualityLevel) 101 { 98 private TaskEquality getEquality(ITask task1, ITask task2, TaskEquality requiredEqualityLevel) { 102 99 ISelection selection = null; 103 ITask TreeNode node= null;100 ITask task = null; 104 101 105 if ( node1 instanceof ISelection) {106 if ( node2 instanceof ISelection) {102 if (task1 instanceof ISelection) { 103 if (task2 instanceof ISelection) { 107 104 // the rule is not responsible for two selections 108 105 return null; 109 106 } 110 107 111 selection = (ISelection) node1;112 node = node2;108 selection = (ISelection) task1; 109 task = task2; 113 110 } 114 else if ( node2 instanceof ISelection) {115 if ( node1 instanceof ISelection) {111 else if (task2 instanceof ISelection) { 112 if (task1 instanceof ISelection) { 116 113 // the rule is not responsible for two selections 117 114 return null; 118 115 } 119 116 120 selection = (ISelection) node2;121 node = node1;117 selection = (ISelection) task2; 118 task = task1; 122 119 } 123 120 else { … … 125 122 } 126 123 127 // now, that we found the selection and the node, lets compare the children of the selection128 // with the node.129 List<ITask TreeNode> children = selection.getChildren();124 // now, that we found the selection and the task, lets compare the children of the selection 125 // with the task. 126 List<ITask> children = selection.getChildren(); 130 127 131 128 if (children.size() < 1) { … … 133 130 } 134 131 135 NodeEquality mostConcreteNodeEquality = null;132 TaskEquality mostConcreteNodeEquality = null; 136 133 137 for (ITask TreeNodechild : children) {138 NodeEquality nodeEquality = callRuleManager(child, node, requiredEqualityLevel);134 for (ITask child : children) { 135 TaskEquality taskEquality = callRuleManager(child, task, requiredEqualityLevel); 139 136 140 if ( nodeEquality != NodeEquality.UNEQUAL) {137 if (taskEquality != TaskEquality.UNEQUAL) { 141 138 if (mostConcreteNodeEquality == null) { 142 mostConcreteNodeEquality = nodeEquality;139 mostConcreteNodeEquality = taskEquality; 143 140 } 144 else if (mostConcreteNodeEquality.isAtLeast( nodeEquality)) {145 mostConcreteNodeEquality = nodeEquality;141 else if (mostConcreteNodeEquality.isAtLeast(taskEquality)) { 142 mostConcreteNodeEquality = taskEquality; 146 143 147 144 } … … 151 148 { 152 149 // 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.150 // we can consider the selection to be sufficiently equal to the other task. 154 151 // So we break up checking further children. 155 152 break; … … 158 155 } 159 156 160 // although the subtask may be identical to the node, we can not return identical, as161 // the selection is not identical to the node, but at most lexically equal162 if (mostConcreteNodeEquality == NodeEquality.IDENTICAL) {163 return NodeEquality.LEXICALLY_EQUAL;157 // although the subtask may be identical to the task, we can not return identical, as 158 // the selection is not identical to the task, but at most lexically equal 159 if (mostConcreteNodeEquality == TaskEquality.IDENTICAL) { 160 return TaskEquality.LEXICALLY_EQUAL; 164 161 } 165 162 else { … … 179 176 * @return 180 177 */ 181 private NodeEquality callRuleManager(ITaskTreeNodechild1,182 ITask TreeNodechild2,183 NodeEqualityrequiredEqualityLevel)178 private TaskEquality callRuleManager(ITask child1, 179 ITask child2, 180 TaskEquality requiredEqualityLevel) 184 181 { 185 182 if (requiredEqualityLevel == null) { … … 190 187 } 191 188 else { 192 return NodeEquality.UNEQUAL;189 return TaskEquality.UNEQUAL; 193 190 } 194 191 }
Note: See TracChangeset
for help on using the changeset viewer.