Changeset 1146 for trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/TaskEqualityRuleManager.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/TaskEqualityRuleManager.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.ArrayList; 18 18 import java.util.List; 19 19 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 * The node equality rule manager is capable of comparing task tree nodes based on its internal list25 * of comparison rules. The current list of rules contains the {@link NodeIdentityRule}, the24 * The task equality rule manager is capable of comparing tasks based on its internal list 25 * of comparison rules. The current list of rules contains the {@link TaskIdentityRule}, the 26 26 * {@link IterationComparisonRule}, the {@link SequenceComparisonRule}, and 27 * {@link SelectionComparisonRule}. These rules are asked for comparing the two provided task tree28 * nodes in the mentioned order. If a rule returns a nodeequality other than null, this equality is27 * {@link SelectionComparisonRule}. These rules are asked for comparing the two provided tasks 28 * in the mentioned order. If a rule returns a task equality other than null, this equality is 29 29 * returned. Otherwise the next rule is asked. 30 30 * </p> … … 33 33 * @author 2012, last modified by $Author: patrick$ 34 34 */ 35 public class NodeEqualityRuleManager {35 public class TaskEqualityRuleManager { 36 36 37 37 /** */ 38 private List< NodeComparisonRule> mRuleIndex = null;39 40 /** 41 * <p> 42 * initializes the nodeequality rule manager by filling the internal list of comparison rules.38 private List<TaskComparisonRule> mRuleIndex = null; 39 40 /** 41 * <p> 42 * initializes the task equality rule manager by filling the internal list of comparison rules. 43 43 * This method must be called before any other method is called on the rule manager. 44 44 * </p> 45 45 */ 46 46 public void init() { 47 mRuleIndex = new ArrayList< NodeComparisonRule>();48 mRuleIndex.add(new NodeIdentityRule());47 mRuleIndex = new ArrayList<TaskComparisonRule>(); 48 mRuleIndex.add(new TaskIdentityRule()); 49 49 mRuleIndex.add(new GUIEventTaskComparisonRule()); 50 50 mRuleIndex.add(new EventTaskComparisonRule()); … … 52 52 mRuleIndex.add(new SequenceComparisonRule(this)); 53 53 mRuleIndex.add(new SelectionComparisonRule(this)); 54 mRuleIndex.add(new NodeAndIterationComparisonRule(this));55 mRuleIndex.add(new NodeAndSelectionComparisonRule(this));56 } 57 58 /** 59 * <p> 60 * this method performs a comparison of the two provided task tree nodes. It iterates its61 * internal comparison rules. If the first rule returns a nodeequality other than null,54 mRuleIndex.add(new TaskAndIterationComparisonRule(this)); 55 mRuleIndex.add(new TaskAndSelectionComparisonRule(this)); 56 } 57 58 /** 59 * <p> 60 * this method performs a comparison of the two provided tasks. It iterates its internal 61 * comparison rules. If the first rule returns a task equality other than null, 62 62 * this equality is returned. Otherwise the next rule is tried. If no rule returns an equality 63 63 * <code>NodeEquality.UNEQUAL</code> is returned. 64 64 * </p> 65 65 * 66 * @param node1 the first task tree nodeto be compared67 * @param node2 the second task tree nodeto be compared66 * @param task1 the first task to be compared 67 * @param task2 the second task to be compared 68 68 * 69 69 * @return as described … … 72 72 * manager before a call to this method. 73 73 */ 74 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2)74 public TaskEquality compare(ITask task1, ITask task2) 75 75 throws IllegalStateException 76 76 { … … 79 79 } 80 80 81 // LOG.info("checking for equality of " + node1 + " and " + node2);82 NodeEquality nodeEquality = null;83 84 for ( NodeComparisonRule rule : mRuleIndex) {85 if (rule.isApplicable( node1, node2)) {86 nodeEquality = rule.compare(node1, node2);87 if ( nodeEquality != null) {81 // LOG.info("checking for equality of " + task1 + " and " + task2); 82 TaskEquality taskEquality = null; 83 84 for (TaskComparisonRule rule : mRuleIndex) { 85 if (rule.isApplicable(task1, task2)) { 86 taskEquality = rule.compare(task1, task2); 87 if (taskEquality != null) { 88 88 // LOG.warning("used rule " + rule + " for equality check"); 89 return nodeEquality;89 return taskEquality; 90 90 } 91 91 } 92 92 } 93 93 94 // LOG.warning("no rule could be applied --> handling nodes as unequal");95 96 return NodeEquality.UNEQUAL;94 // LOG.warning("no rule could be applied --> handling tasks as unequal"); 95 96 return TaskEquality.UNEQUAL; 97 97 } 98 98 … … 107 107 * @return 108 108 */ 109 public boolean areAtLeastEqual(ITaskTreeNode node1, 110 ITaskTreeNode node2, 111 NodeEquality equalityLevel) 112 { 109 public boolean areAtLeastEqual(ITask task1, ITask task2, TaskEquality equalityLevel) { 113 110 if (equalityLevel == null) { 114 111 throw new IllegalArgumentException("required equality level must not be null"); … … 117 114 switch (equalityLevel) { 118 115 case IDENTICAL: 119 return areIdentical( node1, node2);116 return areIdentical(task1, task2); 120 117 case LEXICALLY_EQUAL: 121 return areLexicallyEqual( node1, node2);118 return areLexicallyEqual(task1, task2); 122 119 case SYNTACTICALLY_EQUAL: 123 return areSyntacticallyEqual( node1, node2);120 return areSyntacticallyEqual(task1, task2); 124 121 case SEMANTICALLY_EQUAL: 125 return areSemanticallyEqual( node1, node2);122 return areSemanticallyEqual(task1, task2); 126 123 case UNEQUAL: 127 return !areSemanticallyEqual( node1, node2);124 return !areSemanticallyEqual(task1, task2); 128 125 default: 129 126 throw new IllegalArgumentException("unknown required equality: " + equalityLevel); … … 140 137 * @return 141 138 */ 142 public boolean areIdentical(ITask TreeNode node1, ITaskTreeNode node2) {143 if (mRuleIndex == null) { 144 throw new IllegalStateException("not initialized"); 145 } 146 147 for ( NodeComparisonRule rule : mRuleIndex) {148 if (rule.isApplicable( node1, node2) && rule.areLexicallyEqual(node1, node2)) {149 return true; 150 } 151 } 152 153 return false; 154 } 155 156 /** 157 * <p> 158 * TODO: comment 159 * </p> 160 * 161 * @param child1 162 * @param child2 163 * @return 164 */ 165 public boolean areLexicallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {166 if (mRuleIndex == null) { 167 throw new IllegalStateException("not initialized"); 168 } 169 170 for ( NodeComparisonRule rule : mRuleIndex) {171 if (rule.isApplicable( node1, node2) && rule.areLexicallyEqual(node1, node2)) {172 return true; 173 } 174 } 175 176 return false; 177 } 178 179 /** 180 * <p> 181 * TODO: comment 182 * </p> 183 * 184 * @param child1 185 * @param child2 186 * @return 187 */ 188 public boolean areSyntacticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {189 if (mRuleIndex == null) { 190 throw new IllegalStateException("not initialized"); 191 } 192 193 for ( NodeComparisonRule rule : mRuleIndex) {194 if (rule.isApplicable( node1, node2) && rule.areSyntacticallyEqual(node1, node2)) {195 return true; 196 } 197 } 198 199 return false; 200 } 201 202 /** 203 * <p> 204 * TODO: comment 205 * </p> 206 * 207 * @param child1 208 * @param child2 209 * @return 210 */ 211 public boolean areSemanticallyEqual(ITask TreeNode node1, ITaskTreeNode node2) {212 if (mRuleIndex == null) { 213 throw new IllegalStateException("not initialized"); 214 } 215 216 for ( NodeComparisonRule rule : mRuleIndex) {217 if (rule.isApplicable( node1, node2) && rule.areSemanticallyEqual(node1, node2)) {139 public boolean areIdentical(ITask task1, ITask task2) { 140 if (mRuleIndex == null) { 141 throw new IllegalStateException("not initialized"); 142 } 143 144 for (TaskComparisonRule rule : mRuleIndex) { 145 if (rule.isApplicable(task1, task2) && rule.areLexicallyEqual(task1, task2)) { 146 return true; 147 } 148 } 149 150 return false; 151 } 152 153 /** 154 * <p> 155 * TODO: comment 156 * </p> 157 * 158 * @param child1 159 * @param child2 160 * @return 161 */ 162 public boolean areLexicallyEqual(ITask task1, ITask task2) { 163 if (mRuleIndex == null) { 164 throw new IllegalStateException("not initialized"); 165 } 166 167 for (TaskComparisonRule rule : mRuleIndex) { 168 if (rule.isApplicable(task1, task2) && rule.areLexicallyEqual(task1, task2)) { 169 return true; 170 } 171 } 172 173 return false; 174 } 175 176 /** 177 * <p> 178 * TODO: comment 179 * </p> 180 * 181 * @param child1 182 * @param child2 183 * @return 184 */ 185 public boolean areSyntacticallyEqual(ITask task1, ITask task2) { 186 if (mRuleIndex == null) { 187 throw new IllegalStateException("not initialized"); 188 } 189 190 for (TaskComparisonRule rule : mRuleIndex) { 191 if (rule.isApplicable(task1, task2) && rule.areSyntacticallyEqual(task1, task2)) { 192 return true; 193 } 194 } 195 196 return false; 197 } 198 199 /** 200 * <p> 201 * TODO: comment 202 * </p> 203 * 204 * @param child1 205 * @param child2 206 * @return 207 */ 208 public boolean areSemanticallyEqual(ITask task1, ITask task2) { 209 if (mRuleIndex == null) { 210 throw new IllegalStateException("not initialized"); 211 } 212 213 for (TaskComparisonRule rule : mRuleIndex) { 214 if (rule.isApplicable(task1, task2) && rule.areSemanticallyEqual(task1, task2)) { 218 215 return true; 219 216 }
Note: See TracChangeset
for help on using the changeset viewer.