Ignore:
Timestamp:
08/17/12 08:33:29 (12 years ago)
Author:
pharms
Message:
  • adapted task tree creation stuff to more general event handling
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 //------------------------------------------------------------------------------------------------- 
    21// Module    : $RCSfile: NodeEqualityRuleManager.java,v $ 
    32// Version   : $Revision: 0.0 $  $Author: patrick $  $Date: 19.02.2012 $ 
     
    54// Creation  : 2012 by patrick 
    65// Copyright : Patrick Harms, 2012 
    7 //------------------------------------------------------------------------------------------------- 
     6 
    87package de.ugoe.cs.quest.tasktrees.nodeequality; 
    98 
    109import java.util.ArrayList; 
    1110import java.util.List; 
    12 //import java.util.logging.Logger; 
    1311 
    14 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNode; 
     12import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 
    1513 
    16 //------------------------------------------------------------------------------------------------- 
    1714/** 
    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> 
    1923 *  
    2024 * @version $Revision: $ $Date: 19.02.2012$ 
    2125 * @author 2012, last modified by $Author: patrick$ 
    2226 */ 
    23 //------------------------------------------------------------------------------------------------- 
    24 public class NodeEqualityRuleManager 
    25 { 
     27public class NodeEqualityRuleManager { 
    2628 
    27   /** */ 
    28   //private static Logger LOG = Logger.getLogger(NodeEqualityRuleManager.class.getName()); 
     29    /** */ 
     30    // private static Logger LOG = Logger.getLogger(NodeEqualityRuleManager.class.getName()); 
    2931 
    30   /** */ 
    31   private List<NodeComparisonRule> mRuleIndex = new ArrayList<NodeComparisonRule>(); 
     32    /** */ 
     33    private List<NodeComparisonRule> mRuleIndex = null; 
    3234 
    33   //----------------------------------------------------------------------------------------------- 
    34   /** 
    35    * TODO: comment 
    36    * 
    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    } 
    4648 
    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 
    6267    { 
    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; 
    7087    } 
    71      
    72     //LOG.warning("no rule could be applied --> handling nodes as unequal"); 
    73      
    74     return new NodesUnequal(); 
    75   } 
    7688 
    7789} 
Note: See TracChangeset for help on using the changeset viewer.