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

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