Changeset 557 for trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/NodeEqualityRuleManager.java
- Timestamp:
- 08/17/12 08:33:29 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/NodeEqualityRuleManager.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: NodeEqualityRuleManager.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 19.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.nodeequality; 9 8 10 9 import java.util.ArrayList; 11 10 import java.util.List; 12 //import java.util.logging.Logger;13 11 14 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;12 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 15 13 16 //-------------------------------------------------------------------------------------------------17 14 /** 18 * TODO comment 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> 19 23 * 20 24 * @version $Revision: $ $Date: 19.02.2012$ 21 25 * @author 2012, last modified by $Author: patrick$ 22 26 */ 23 //------------------------------------------------------------------------------------------------- 24 public class NodeEqualityRuleManager 25 { 27 public class NodeEqualityRuleManager { 26 28 27 /** */28 //private static Logger LOG = Logger.getLogger(NodeEqualityRuleManager.class.getName());29 /** */ 30 // private static Logger LOG = Logger.getLogger(NodeEqualityRuleManager.class.getName()); 29 31 30 /** */31 private List<NodeComparisonRule> mRuleIndex = new ArrayList<NodeComparisonRule>();32 /** */ 33 private List<NodeComparisonRule> mRuleIndex = null; 32 34 33 //-----------------------------------------------------------------------------------------------34 /**35 * TODO: comment36 *37 */38 //-----------------------------------------------------------------------------------------------39 public void init()40 {41 mRuleIndex.add(new NodeIdentityRule());42 mRuleIndex.add(new IterationComparisonRule(this));43 mRuleIndex.add(new SequenceComparisonRule(this));44 mRuleIndex.add(new SelectionComparisonRule(this));45 }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 } 46 48 47 //----------------------------------------------------------------------------------------------- 48 /** 49 * TODO: comment 50 * 51 * @param node1 52 * @param node2 53 * @return 54 */ 55 //----------------------------------------------------------------------------------------------- 56 public NodeEquality applyRules(TaskTreeNode node1, TaskTreeNode node2) 57 { 58 //LOG.info("checking for equality of " + node1 + " and " + node2); 59 NodeEquality nodeEquality = null; 60 61 for (NodeComparisonRule rule : mRuleIndex) 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 62 67 { 63 nodeEquality = rule.compare(node1, node2); 64 65 if (nodeEquality != null) 66 { 67 //LOG.warning("used rule " + rule + " for equality check"); 68 return nodeEquality; 69 } 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; 70 87 } 71 72 //LOG.warning("no rule could be applied --> handling nodes as unequal");73 74 return new NodesUnequal();75 }76 88 77 89 }
Note: See TracChangeset
for help on using the changeset viewer.