Changeset 1294 for trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/TaskEqualityRuleManager.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/TaskEqualityRuleManager.java
r1190 r1294 19 19 20 20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 21 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 21 22 22 23 /** 23 24 * <p> 24 * The task equality rule manager is capable of comparing tasks based on its internal list25 * of comparison rules. These rules are asked for comparing the two provided tasks. If a rule26 * returns a task equality other than null, this equality is returned. Otherwise the next rule27 * is asked.25 * The task equality rule manager is capable of comparing tasks and task instances based on its 26 * internal list of comparison rules. These rules are asked for comparing the two provided tasks or 27 * task instance. If a rule returns a task equality other than null, this equality is returned. 28 * Otherwise the next rule is asked. 28 29 * </p> 29 30 * 30 * @version $Revision: $ $Date: 19.02.2012$ 31 * @author 2012, last modified by $Author: patrick$ 31 * @author Patrick Harms 32 32 */ 33 33 public class TaskEqualityRuleManager { … … 269 269 } 270 270 271 /** 272 * <p> 273 * this method performs a comparison of the two provided task instances. It iterates its 274 * internal comparison rules. If the first rule returns a task instance equality other than 275 * null, this equality is returned. Otherwise the next rule is tried. If no rule returns an 276 * equality <code>TaskEquality.UNEQUAL</code> is returned. 277 * </p> 278 * 279 * @param instance1 the first task instance to be compared 280 * @param instance2 the second task instance to be compared 281 * 282 * @return as described 283 * 284 * @throws IllegalStateException in the case, the {@link #init()} method was not called on the 285 * manager before a call to this method. 286 */ 287 public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) 288 throws IllegalStateException 289 { 290 if (mRuleIndex == null) { 291 throw new IllegalStateException("not initialized"); 292 } 293 294 // LOG.info("checking for equality of " + instance1 + " and " + instance2); 295 TaskEquality instanceEquality = null; 296 297 for (TaskComparisonRule rule : mRuleIndex) { 298 if (rule.isApplicable(instance1, instance2)) { 299 instanceEquality = rule.compare(instance1, instance2); 300 if (instanceEquality != null) { 301 // LOG.warning("used rule " + rule + " for equality check"); 302 return instanceEquality; 303 } 304 } 305 } 306 307 // LOG.warning("no rule could be applied --> handling tasks as unequal"); 308 309 return TaskEquality.UNEQUAL; 310 } 311 312 /** 313 * <p> 314 * this method compares two task instances with respect to the given equality level and returns 315 * true, if this level is given. 316 * </p> 317 * 318 * @param instance1 the first task instance to be compared 319 * @param instance2 the second task instance to be compared 320 * @param equalityLevel the level of equality to be checked for 321 * 322 * @return as described 323 * 324 * @throws IllegalStateException in the case, the {@link #init()} method was not called on the 325 * manager before a call to this method. 326 */ 327 public boolean areAtLeastEqual(ITaskInstance instance1, 328 ITaskInstance instance2, 329 TaskEquality equalityLevel) 330 { 331 if (equalityLevel == null) { 332 throw new IllegalArgumentException("required equality level must not be null"); 333 } 334 335 switch (equalityLevel) { 336 case IDENTICAL: 337 return areIdentical(instance1, instance2); 338 case LEXICALLY_EQUAL: 339 return areLexicallyEqual(instance1, instance2); 340 case SYNTACTICALLY_EQUAL: 341 return areSyntacticallyEqual(instance1, instance2); 342 case SEMANTICALLY_EQUAL: 343 return areSemanticallyEqual(instance1, instance2); 344 case UNEQUAL: 345 return !areSemanticallyEqual(instance1, instance2); 346 default: 347 throw new IllegalArgumentException("unknown required equality: " + equalityLevel); 348 } 349 } 350 351 /** 352 * <p> 353 * this method checks if the two given task instances are identical. For this, it iterates its 354 * internal comparison rules. If the first rule returns true, than this method returns true 355 * as well. If no rule returns true, this method returns false. 356 * </p> 357 * 358 * @param instance1 the first task instance to be compared 359 * @param instance2 the second task instance to be compared 360 * 361 * @return as described 362 * 363 * @throws IllegalStateException in the case, the {@link #init()} method was not called on the 364 * manager before a call to this method. 365 */ 366 public boolean areIdentical(ITaskInstance instance1, ITaskInstance instance2) { 367 if (mRuleIndex == null) { 368 throw new IllegalStateException("not initialized"); 369 } 370 371 for (TaskComparisonRule rule : mRuleIndex) { 372 if (rule.isApplicable(instance1, instance2) && 373 rule.areLexicallyEqual(instance1, instance2)) 374 { 375 return true; 376 } 377 } 378 379 return false; 380 } 381 382 /** 383 * <p> 384 * this method checks if the two given task instances are lexically equal. For this, it 385 * iterates its internal comparison rules. If the first rule returns true, than this method 386 * returns true, as well. If no rule returns true, this method returns false. 387 * </p> 388 * 389 * @param instance1 the first task instance to be compared 390 * @param instance2 the second task instance to be compared 391 * 392 * @return as described 393 * 394 * @throws IllegalStateException in the case, the {@link #init()} method was not called on the 395 * manager before a call to this method. 396 */ 397 public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 398 if (mRuleIndex == null) { 399 throw new IllegalStateException("not initialized"); 400 } 401 402 for (TaskComparisonRule rule : mRuleIndex) { 403 if (rule.isApplicable(instance1, instance2) && 404 rule.areLexicallyEqual(instance1, instance2)) 405 { 406 return true; 407 } 408 } 409 410 return false; 411 } 412 413 /** 414 * <p> 415 * this method checks if the two given task instances are syntactically equal. For this, it 416 * iterates its internal comparison rules. If the first rule returns true, than this method 417 * returns true, as well. If no rule returns true, this method returns false. 418 * </p> 419 * 420 * @param instance1 the first task instance to be compared 421 * @param instance2 the second task instance to be compared 422 * 423 * @return as described 424 * 425 * @throws IllegalStateException in the case, the {@link #init()} method was not called on the 426 * manager before a call to this method. 427 */ 428 public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 429 if (mRuleIndex == null) { 430 throw new IllegalStateException("not initialized"); 431 } 432 433 for (TaskComparisonRule rule : mRuleIndex) { 434 if (rule.isApplicable(instance1, instance2) && 435 rule.areSyntacticallyEqual(instance1, instance2)) 436 { 437 return true; 438 } 439 } 440 441 return false; 442 } 443 444 /** 445 * <p> 446 * this method checks if the two given task instances are semantically equal. For this, it 447 * iterates its internal comparison rules. If the first rule returns true, than this method 448 * returns true, as well. If no rule returns true, this method returns false. 449 * </p> 450 * 451 * @param instance1 the first task instance to be compared 452 * @param instance2 the second task instance to be compared 453 * 454 * @return as described 455 * 456 * @throws IllegalStateException in the case, the {@link #init()} method was not called on the 457 * manager before a call to this method. 458 */ 459 public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 460 if (mRuleIndex == null) { 461 throw new IllegalStateException("not initialized"); 462 } 463 464 for (TaskComparisonRule rule : mRuleIndex) { 465 if (rule.isApplicable(instance1, instance2) && 466 rule.areSemanticallyEqual(instance1, instance2)) 467 { 468 return true; 469 } 470 } 471 472 return false; 473 } 474 271 475 }
Note: See TracChangeset
for help on using the changeset viewer.