[922] | 1 | package de.ugoe.cs.autoquest.tasktrees.nodeequality; |
---|
[439] | 2 | |
---|
| 3 | import java.util.ArrayList; |
---|
| 4 | import java.util.List; |
---|
| 5 | |
---|
[922] | 6 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; |
---|
[439] | 7 | |
---|
| 8 | /** |
---|
[557] | 9 | * <p> |
---|
| 10 | * The node equality rule manager is capable of comparing task tree nodes based on its internal list |
---|
| 11 | * of comparison rules. The current list of rules contains the {@link NodeIdentityRule}, the |
---|
| 12 | * {@link IterationComparisonRule}, the {@link SequenceComparisonRule}, and |
---|
| 13 | * {@link SelectionComparisonRule}. These rules are asked for comparing the two provided task tree |
---|
| 14 | * nodes in the mentioned order. If a rule returns a node equality other than null, this equality is |
---|
| 15 | * returned. Otherwise the next rule is asked. |
---|
| 16 | * </p> |
---|
[439] | 17 | * |
---|
| 18 | * @version $Revision: $ $Date: 19.02.2012$ |
---|
| 19 | * @author 2012, last modified by $Author: patrick$ |
---|
| 20 | */ |
---|
[557] | 21 | public class NodeEqualityRuleManager { |
---|
[439] | 22 | |
---|
[557] | 23 | /** */ |
---|
| 24 | private List<NodeComparisonRule> mRuleIndex = null; |
---|
[439] | 25 | |
---|
[557] | 26 | /** |
---|
| 27 | * <p> |
---|
| 28 | * initializes the node equality rule manager by filling the internal list of comparison rules. |
---|
| 29 | * This method must be called before any other method is called on the rule manager. |
---|
| 30 | * </p> |
---|
| 31 | */ |
---|
| 32 | public void init() { |
---|
| 33 | mRuleIndex = new ArrayList<NodeComparisonRule>(); |
---|
| 34 | mRuleIndex.add(new NodeIdentityRule()); |
---|
[807] | 35 | mRuleIndex.add(new GUIEventTaskComparisonRule()); |
---|
| 36 | mRuleIndex.add(new EventTaskComparisonRule()); |
---|
[557] | 37 | mRuleIndex.add(new IterationComparisonRule(this)); |
---|
| 38 | mRuleIndex.add(new SequenceComparisonRule(this)); |
---|
| 39 | mRuleIndex.add(new SelectionComparisonRule(this)); |
---|
[816] | 40 | mRuleIndex.add(new NodeAndIterationComparisonRule(this)); |
---|
| 41 | mRuleIndex.add(new NodeAndSelectionComparisonRule(this)); |
---|
[557] | 42 | } |
---|
[439] | 43 | |
---|
[557] | 44 | /** |
---|
| 45 | * <p> |
---|
| 46 | * this method performs a comparison of the two provided task tree nodes. It iterates its |
---|
| 47 | * internal comparison rules. If the first rule returns a node equality other than null, |
---|
| 48 | * this equality is returned. Otherwise the next rule is tried. If no rule returns an equality |
---|
| 49 | * <code>NodeEquality.UNEQUAL</code> is returned. |
---|
| 50 | * </p> |
---|
| 51 | * |
---|
| 52 | * @param node1 the first task tree node to be compared |
---|
| 53 | * @param node2 the second task tree node to be compared |
---|
| 54 | * |
---|
| 55 | * @return as described |
---|
| 56 | * |
---|
| 57 | * @throws IllegalStateException in the case, the {@link #init()} method was not called on the |
---|
| 58 | * manager before a call to this method. |
---|
| 59 | */ |
---|
| 60 | public NodeEquality applyRules(ITaskTreeNode node1, ITaskTreeNode node2) |
---|
| 61 | throws IllegalStateException |
---|
[439] | 62 | { |
---|
[557] | 63 | if (mRuleIndex == null) { |
---|
| 64 | throw new IllegalStateException("not initialized"); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | // LOG.info("checking for equality of " + node1 + " and " + node2); |
---|
| 68 | NodeEquality nodeEquality = null; |
---|
| 69 | |
---|
| 70 | for (NodeComparisonRule rule : mRuleIndex) { |
---|
| 71 | nodeEquality = rule.compare(node1, node2); |
---|
| 72 | |
---|
| 73 | if (nodeEquality != null) { |
---|
| 74 | // LOG.warning("used rule " + rule + " for equality check"); |
---|
| 75 | return nodeEquality; |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | // LOG.warning("no rule could be applied --> handling nodes as unequal"); |
---|
| 80 | |
---|
| 81 | return NodeEquality.UNEQUAL; |
---|
[439] | 82 | } |
---|
| 83 | |
---|
| 84 | } |
---|