source: trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/NodeEqualityRuleManager.java @ 655

Last change on this file since 655 was 655, checked in by pharms, 12 years ago
  • removed old copyright file header
  • Property svn:executable set to *
File size: 3.0 KB
Line 
1package de.ugoe.cs.quest.tasktrees.nodeequality;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode;
7
8/**
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>
17 *
18 * @version $Revision: $ $Date: 19.02.2012$
19 * @author 2012, last modified by $Author: patrick$
20 */
21public class NodeEqualityRuleManager {
22
23    /** */
24    // private static Logger LOG = Logger.getLogger(NodeEqualityRuleManager.class.getName());
25
26    /** */
27    private List<NodeComparisonRule> mRuleIndex = null;
28
29    /**
30     * <p>
31     * initializes the node equality rule manager by filling the internal list of comparison rules.
32     * This method must be called before any other method is called on the rule manager.
33     * </p>
34     */
35    public void init() {
36        mRuleIndex = new ArrayList<NodeComparisonRule>();
37        mRuleIndex.add(new NodeIdentityRule());
38        mRuleIndex.add(new IterationComparisonRule(this));
39        mRuleIndex.add(new SequenceComparisonRule(this));
40        mRuleIndex.add(new SelectionComparisonRule(this));
41    }
42
43    /**
44     * <p>
45     * this method performs a comparison of the two provided task tree nodes. It iterates its
46     * internal comparison rules. If the first rule returns a node equality other than null,
47     * this equality is returned. Otherwise the next rule is tried. If no rule returns an equality
48     * <code>NodeEquality.UNEQUAL</code> is returned.
49     * </p>
50     *
51     * @param node1 the first task tree node to be compared
52     * @param node2 the second task tree node to be compared
53     *
54     * @return as described
55     *
56     * @throws IllegalStateException in the case, the {@link #init()} method was not called on the
57     *                               manager before a call to this method.
58     */
59    public NodeEquality applyRules(ITaskTreeNode node1, ITaskTreeNode node2)
60        throws IllegalStateException
61    {
62        if (mRuleIndex == null) {
63            throw new IllegalStateException("not initialized");
64        }
65       
66        // LOG.info("checking for equality of " + node1 + " and " + node2);
67        NodeEquality nodeEquality = null;
68
69        for (NodeComparisonRule rule : mRuleIndex) {
70            nodeEquality = rule.compare(node1, node2);
71
72            if (nodeEquality != null) {
73                // LOG.warning("used rule " + rule + " for equality check");
74                return nodeEquality;
75            }
76        }
77
78        // LOG.warning("no rule could be applied --> handling nodes as unequal");
79
80        return NodeEquality.UNEQUAL;
81    }
82
83}
Note: See TracBrowser for help on using the repository browser.