Ignore:
Timestamp:
04/04/13 16:06:07 (11 years ago)
Author:
pharms
Message:
  • complete refactoring of task tree model with a separation of task models and task instances
  • appropriate adaptation of task tree generation process
  • appropriate adaptation of commands and task tree visualization
Location:
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality
Files:
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/TaskEqualityRuleManager.java

    r1125 r1146  
    1313//   limitations under the License. 
    1414 
    15 package de.ugoe.cs.autoquest.tasktrees.nodeequality; 
     15package de.ugoe.cs.autoquest.tasktrees.taskequality; 
    1616 
    1717import java.util.ArrayList; 
    1818import java.util.List; 
    1919 
    20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 
     20import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
    2121 
    2222/** 
    2323 * <p> 
    24  * The node equality rule manager is capable of comparing task tree nodes based on its internal list 
    25  * of comparison rules. The current list of rules contains the {@link NodeIdentityRule}, the 
     24 * The task equality rule manager is capable of comparing tasks based on its internal list 
     25 * of comparison rules. The current list of rules contains the {@link TaskIdentityRule}, the 
    2626 * {@link IterationComparisonRule}, the {@link SequenceComparisonRule}, and 
    27  * {@link SelectionComparisonRule}. These rules are asked for comparing the two provided task tree 
    28  * nodes in the mentioned order. If a rule returns a node equality other than null, this equality is 
     27 * {@link SelectionComparisonRule}. These rules are asked for comparing the two provided tasks 
     28 * in the mentioned order. If a rule returns a task equality other than null, this equality is 
    2929 * returned. Otherwise the next rule is asked. 
    3030 * </p> 
     
    3333 * @author 2012, last modified by $Author: patrick$ 
    3434 */ 
    35 public class NodeEqualityRuleManager { 
     35public class TaskEqualityRuleManager { 
    3636 
    3737    /** */ 
    38     private List<NodeComparisonRule> mRuleIndex = null; 
    39  
    40     /** 
    41      * <p> 
    42      * initializes the node equality rule manager by filling the internal list of comparison rules. 
     38    private List<TaskComparisonRule> mRuleIndex = null; 
     39 
     40    /** 
     41     * <p> 
     42     * initializes the task equality rule manager by filling the internal list of comparison rules. 
    4343     * This method must be called before any other method is called on the rule manager. 
    4444     * </p> 
    4545     */ 
    4646    public void init() { 
    47         mRuleIndex = new ArrayList<NodeComparisonRule>(); 
    48         mRuleIndex.add(new NodeIdentityRule()); 
     47        mRuleIndex = new ArrayList<TaskComparisonRule>(); 
     48        mRuleIndex.add(new TaskIdentityRule()); 
    4949        mRuleIndex.add(new GUIEventTaskComparisonRule()); 
    5050        mRuleIndex.add(new EventTaskComparisonRule()); 
     
    5252        mRuleIndex.add(new SequenceComparisonRule(this)); 
    5353        mRuleIndex.add(new SelectionComparisonRule(this)); 
    54         mRuleIndex.add(new NodeAndIterationComparisonRule(this)); 
    55         mRuleIndex.add(new NodeAndSelectionComparisonRule(this)); 
    56     } 
    57  
    58     /** 
    59      * <p> 
    60      * this method performs a comparison of the two provided task tree nodes. It iterates its 
    61      * internal comparison rules. If the first rule returns a node equality other than null, 
     54        mRuleIndex.add(new TaskAndIterationComparisonRule(this)); 
     55        mRuleIndex.add(new TaskAndSelectionComparisonRule(this)); 
     56    } 
     57 
     58    /** 
     59     * <p> 
     60     * this method performs a comparison of the two provided tasks. It iterates its internal 
     61     * comparison rules. If the first rule returns a task equality other than null, 
    6262     * this equality is returned. Otherwise the next rule is tried. If no rule returns an equality 
    6363     * <code>NodeEquality.UNEQUAL</code> is returned. 
    6464     * </p> 
    6565     *  
    66      * @param node1 the first task tree node to be compared 
    67      * @param node2 the second task tree node to be compared 
     66     * @param task1 the first task to be compared 
     67     * @param task2 the second task to be compared 
    6868     *  
    6969     * @return as described 
     
    7272     *                               manager before a call to this method. 
    7373     */ 
    74     public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) 
     74    public TaskEquality compare(ITask task1, ITask task2) 
    7575        throws IllegalStateException 
    7676    { 
     
    7979        } 
    8080         
    81         // LOG.info("checking for equality of " + node1 + " and " + node2); 
    82         NodeEquality nodeEquality = null; 
    83  
    84         for (NodeComparisonRule rule : mRuleIndex) { 
    85             if (rule.isApplicable(node1, node2)) { 
    86                 nodeEquality = rule.compare(node1, node2); 
    87                 if (nodeEquality != null) { 
     81        // LOG.info("checking for equality of " + task1 + " and " + task2); 
     82        TaskEquality taskEquality = null; 
     83 
     84        for (TaskComparisonRule rule : mRuleIndex) { 
     85            if (rule.isApplicable(task1, task2)) { 
     86                taskEquality = rule.compare(task1, task2); 
     87                if (taskEquality != null) { 
    8888                    // LOG.warning("used rule " + rule + " for equality check"); 
    89                     return nodeEquality; 
     89                    return taskEquality; 
    9090                } 
    9191            } 
    9292        } 
    9393 
    94         // LOG.warning("no rule could be applied --> handling nodes as unequal"); 
    95  
    96         return NodeEquality.UNEQUAL; 
     94        // LOG.warning("no rule could be applied --> handling tasks as unequal"); 
     95 
     96        return TaskEquality.UNEQUAL; 
    9797    } 
    9898 
     
    107107     * @return 
    108108     */ 
    109     public boolean areAtLeastEqual(ITaskTreeNode node1, 
    110                                    ITaskTreeNode node2, 
    111                                    NodeEquality  equalityLevel) 
    112     { 
     109    public boolean areAtLeastEqual(ITask task1, ITask task2, TaskEquality equalityLevel) { 
    113110        if (equalityLevel == null) { 
    114111            throw new IllegalArgumentException("required equality level must not be null"); 
     
    117114        switch (equalityLevel) { 
    118115            case IDENTICAL: 
    119                 return areIdentical(node1, node2); 
     116                return areIdentical(task1, task2); 
    120117            case LEXICALLY_EQUAL: 
    121                 return areLexicallyEqual(node1, node2); 
     118                return areLexicallyEqual(task1, task2); 
    122119            case SYNTACTICALLY_EQUAL: 
    123                 return areSyntacticallyEqual(node1, node2); 
     120                return areSyntacticallyEqual(task1, task2); 
    124121            case SEMANTICALLY_EQUAL: 
    125                 return areSemanticallyEqual(node1, node2); 
     122                return areSemanticallyEqual(task1, task2); 
    126123            case UNEQUAL: 
    127                 return !areSemanticallyEqual(node1, node2); 
     124                return !areSemanticallyEqual(task1, task2); 
    128125            default: 
    129126                throw new IllegalArgumentException("unknown required equality: " + equalityLevel); 
     
    140137     * @return 
    141138     */ 
    142     public boolean areIdentical(ITaskTreeNode node1, ITaskTreeNode node2) { 
    143         if (mRuleIndex == null) { 
    144             throw new IllegalStateException("not initialized"); 
    145         } 
    146          
    147         for (NodeComparisonRule rule : mRuleIndex) { 
    148             if (rule.isApplicable(node1, node2) && rule.areLexicallyEqual(node1, node2)) { 
    149                  return true; 
    150             } 
    151         } 
    152  
    153         return false; 
    154     } 
    155  
    156     /** 
    157      * <p> 
    158      * TODO: comment 
    159      * </p> 
    160      * 
    161      * @param child1 
    162      * @param child2 
    163      * @return 
    164      */ 
    165     public boolean areLexicallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 
    166         if (mRuleIndex == null) { 
    167             throw new IllegalStateException("not initialized"); 
    168         } 
    169          
    170         for (NodeComparisonRule rule : mRuleIndex) { 
    171             if (rule.isApplicable(node1, node2) && rule.areLexicallyEqual(node1, node2)) { 
    172                  return true; 
    173             } 
    174         } 
    175  
    176         return false; 
    177     } 
    178  
    179     /** 
    180      * <p> 
    181      * TODO: comment 
    182      * </p> 
    183      * 
    184      * @param child1 
    185      * @param child2 
    186      * @return 
    187      */ 
    188     public boolean areSyntacticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 
    189         if (mRuleIndex == null) { 
    190             throw new IllegalStateException("not initialized"); 
    191         } 
    192          
    193         for (NodeComparisonRule rule : mRuleIndex) { 
    194             if (rule.isApplicable(node1, node2) && rule.areSyntacticallyEqual(node1, node2)) { 
    195                  return true; 
    196             } 
    197         } 
    198  
    199         return false; 
    200     } 
    201  
    202     /** 
    203      * <p> 
    204      * TODO: comment 
    205      * </p> 
    206      * 
    207      * @param child1 
    208      * @param child2 
    209      * @return 
    210      */ 
    211     public boolean areSemanticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 
    212         if (mRuleIndex == null) { 
    213             throw new IllegalStateException("not initialized"); 
    214         } 
    215          
    216         for (NodeComparisonRule rule : mRuleIndex) { 
    217             if (rule.isApplicable(node1, node2) && rule.areSemanticallyEqual(node1, node2)) { 
     139    public boolean areIdentical(ITask task1, ITask task2) { 
     140        if (mRuleIndex == null) { 
     141            throw new IllegalStateException("not initialized"); 
     142        } 
     143         
     144        for (TaskComparisonRule rule : mRuleIndex) { 
     145            if (rule.isApplicable(task1, task2) && rule.areLexicallyEqual(task1, task2)) { 
     146                 return true; 
     147            } 
     148        } 
     149 
     150        return false; 
     151    } 
     152 
     153    /** 
     154     * <p> 
     155     * TODO: comment 
     156     * </p> 
     157     * 
     158     * @param child1 
     159     * @param child2 
     160     * @return 
     161     */ 
     162    public boolean areLexicallyEqual(ITask task1, ITask task2) { 
     163        if (mRuleIndex == null) { 
     164            throw new IllegalStateException("not initialized"); 
     165        } 
     166         
     167        for (TaskComparisonRule rule : mRuleIndex) { 
     168            if (rule.isApplicable(task1, task2) && rule.areLexicallyEqual(task1, task2)) { 
     169                 return true; 
     170            } 
     171        } 
     172 
     173        return false; 
     174    } 
     175 
     176    /** 
     177     * <p> 
     178     * TODO: comment 
     179     * </p> 
     180     * 
     181     * @param child1 
     182     * @param child2 
     183     * @return 
     184     */ 
     185    public boolean areSyntacticallyEqual(ITask task1, ITask task2) { 
     186        if (mRuleIndex == null) { 
     187            throw new IllegalStateException("not initialized"); 
     188        } 
     189         
     190        for (TaskComparisonRule rule : mRuleIndex) { 
     191            if (rule.isApplicable(task1, task2) && rule.areSyntacticallyEqual(task1, task2)) { 
     192                 return true; 
     193            } 
     194        } 
     195 
     196        return false; 
     197    } 
     198 
     199    /** 
     200     * <p> 
     201     * TODO: comment 
     202     * </p> 
     203     * 
     204     * @param child1 
     205     * @param child2 
     206     * @return 
     207     */ 
     208    public boolean areSemanticallyEqual(ITask task1, ITask task2) { 
     209        if (mRuleIndex == null) { 
     210            throw new IllegalStateException("not initialized"); 
     211        } 
     212         
     213        for (TaskComparisonRule rule : mRuleIndex) { 
     214            if (rule.isApplicable(task1, task2) && rule.areSemanticallyEqual(task1, task2)) { 
    218215                 return true; 
    219216            } 
Note: See TracChangeset for help on using the changeset viewer.