Changeset 1294 for trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/IterationComparisonRule.java
- Timestamp:
- 08/14/13 17:04:42 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/IterationComparisonRule.java
r1190 r1294 15 15 package de.ugoe.cs.autoquest.tasktrees.taskequality; 16 16 17 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;18 17 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 18 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; 19 19 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence;21 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 21 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 22 22 23 23 /** … … 82 82 83 83 /* (non-Javadoc) 84 * @see NodeComparisonRule#isApplicable(ITask, ITask)84 * @see TaskComparisonRule#isApplicable(ITask, ITask) 85 85 */ 86 86 @Override … … 90 90 91 91 /* (non-Javadoc) 92 * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask)92 * @see TaskComparisonRule#areLexicallyEqual(ITask, ITask) 93 93 */ 94 94 @Override 95 95 public boolean areLexicallyEqual(ITask task1, ITask task2) { 96 ITask child1 = ((IIteration) task1).getMarkedTask();97 ITask child2 = ((IIteration) task2).getMarkedTask();98 99 if (child1 != null) {100 if (child2 == null) {101 return false;102 }103 else {104 // iterations may have 3 different structures.105 // 1. they have one child, which is the iterated one106 // 2. they have a sequence of children, which is iterated107 // 3. they have a selection of different iterated variants (usually the variants108 // are semantically equal)109 // check if the type of children match. If not, return false. If they match,110 // use the equality manager to perform further comparisons111 112 if (((child1 instanceof ISelection) && (child2 instanceof ISelection)) ||113 ((child1 instanceof ISequence) && (child2 instanceof ISequence)) ||114 ((child1 instanceof IEventTask) && (child2 instanceof IEventTask)))115 {116 return getNodeEquality117 (child1, child2).isAtLeast(TaskEquality.LEXICALLY_EQUAL);118 }119 }120 }121 else if (child2 == null) {122 return true;123 }124 125 return false;126 }127 128 /* (non-Javadoc)129 * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask)130 */131 @Override132 public boolean areSyntacticallyEqual(ITask task1, ITask task2) {133 96 ITask child1 = ((IIteration) task1).getMarkedTask(); 134 97 ITask child2 = ((IIteration) task2).getMarkedTask(); … … 146 109 // ignore the type of the children but check them for equality. 147 110 148 return getNodeEquality(child1, child2).isAtLeast(TaskEquality. SYNTACTICALLY_EQUAL);111 return getNodeEquality(child1, child2).isAtLeast(TaskEquality.LEXICALLY_EQUAL); 149 112 } 150 113 } … … 157 120 158 121 /* (non-Javadoc) 159 * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) 122 * @see TaskComparisonRule#areSyntacticallyEqual(ITask, ITask) 123 */ 124 @Override 125 public boolean areSyntacticallyEqual(ITask task1, ITask task2) { 126 return areLexicallyEqual(task1, task2); 127 } 128 129 /* (non-Javadoc) 130 * @see TaskComparisonRule#areSemanticallyEqual(ITask, ITask) 160 131 */ 161 132 @Override … … 165 136 166 137 /* (non-Javadoc) 167 * @see NodeComparisonRule#compare(ITask, ITask)138 * @see TaskComparisonRule#compare(ITask, ITask) 168 139 */ 169 140 @Override … … 203 174 // all other combinations (i.e. sequence with single child and sequence with selection) 204 175 // can not match 176 } 177 178 /* (non-Javadoc) 179 * @see TaskComparisonRule#isApplicable(ITaskInstance, ITaskInstance) 180 */ 181 @Override 182 public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2) { 183 return isApplicable(instance1.getTask(), instance2.getTask()); 184 } 185 186 /* (non-Javadoc) 187 * @see TaskComparisonRule#areLexicallyEqual(ITaskInstance, ITaskInstance) 188 */ 189 @Override 190 public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 191 IIterationInstance iteration1 = (IIterationInstance) instance1; 192 IIterationInstance iteration2 = (IIterationInstance) instance2; 193 194 // if both sequences do not have children, they are equal although this doesn't make sense 195 if ((iteration1.size() == 0) && (iteration2.size() == 0)) { 196 return true; 197 } 198 199 if (iteration1.size() != iteration2.size()) { 200 return false; 201 } 202 203 for (int i = 0; i < iteration1.size(); i++) { 204 ITaskInstance child1 = iteration1.get(i); 205 ITaskInstance child2 = iteration2.get(i); 206 207 TaskEquality taskEquality = 208 callRuleManager(child1, child2, TaskEquality.LEXICALLY_EQUAL); 209 210 if ((taskEquality == null) || (taskEquality == TaskEquality.UNEQUAL)) { 211 return false; 212 } 213 } 214 215 return true; 216 } 217 218 /* (non-Javadoc) 219 * @see TaskComparisonRule#areSyntacticallyEqual(ITaskInstance, ITaskInstance) 220 */ 221 @Override 222 public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 223 return areLexicallyEqual(instance1, instance2); 224 } 225 226 /* (non-Javadoc) 227 * @see TaskComparisonRule#areSemanticallyEqual(ITaskInstance, ITaskInstance) 228 */ 229 @Override 230 public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 231 return areLexicallyEqual(instance1, instance2); 232 } 233 234 /* (non-Javadoc) 235 * @see TaskComparisonRule#compare(ITaskInstance, ITaskInstance) 236 */ 237 @Override 238 public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) { 239 if (areLexicallyEqual(instance1, instance2)) { 240 return TaskEquality.LEXICALLY_EQUAL; 241 } 242 else { 243 return TaskEquality.UNEQUAL; 244 } 205 245 } 206 246 … … 272 312 callRuleManager(task, child, commonDenominatorForAllComparisons); 273 313 274 if ((taskEquality == null) || (taskEquality == TaskEquality.UNEQUAL)) 275 { 314 if ((taskEquality == null) || (taskEquality == TaskEquality.UNEQUAL)) { 276 315 return TaskEquality.UNEQUAL; 277 316 } … … 314 353 } 315 354 } 355 356 /** 357 * <p> 358 * used to to call the task equality rule manager for the comparison of the two provided 359 * children. If no required equality level is provided, than the most concrete equality is 360 * returned. Otherwise, the required equality is returned as long as the children are equal 361 * on that level. 362 * </p> 363 * 364 * @param taskInstance1 the first task instance to be compared 365 * @param taskInstance2 the second task instance to be compared 366 * @param requiredEqualityLevel the equality level to be checked for 367 * 368 * @return the determined equality 369 */ 370 private TaskEquality callRuleManager(ITaskInstance taskInstance1, 371 ITaskInstance taskInstance2, 372 TaskEquality requiredEqualityLevel) 373 { 374 if (requiredEqualityLevel == null) { 375 return TaskEqualityRuleManager.getInstance().compare(taskInstance1, taskInstance2); 376 } 377 else if (TaskEqualityRuleManager.getInstance().areAtLeastEqual 378 (taskInstance1, taskInstance2, requiredEqualityLevel)) 379 { 380 return requiredEqualityLevel; 381 } 382 else { 383 return TaskEquality.UNEQUAL; 384 } 385 } 316 386 }
Note: See TracChangeset
for help on using the changeset viewer.