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/IterationComparisonRule.java

    r1125 r1146  
    1313//   limitations under the License. 
    1414 
    15 package de.ugoe.cs.autoquest.tasktrees.nodeequality; 
    16  
    17 import java.util.List; 
     15package de.ugoe.cs.autoquest.tasktrees.taskequality; 
    1816 
    1917import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 
     
    2119import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 
    2220import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
    23 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 
     21import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
    2422 
    2523/** 
     
    8179 * @author 2012, last modified by $Author: patrick$ 
    8280 */ 
    83 public class IterationComparisonRule implements NodeComparisonRule { 
     81public class IterationComparisonRule implements TaskComparisonRule { 
    8482     
    85     /** the rule manager for internally comparing task tree nodes */ 
    86     private NodeEqualityRuleManager mRuleManager; 
     83    /** the rule manager for internally comparing tasks */ 
     84    private TaskEqualityRuleManager mRuleManager; 
    8785 
    8886    /** 
    8987     * <p> 
    90      * simple constructor to provide the rule with the node equality rule manager to be able 
    91      * to perform comparisons of the children of provided task tree nodes 
     88     * simple constructor to provide the rule with the task equality rule manager to be able 
     89     * to perform comparisons of the children of provided tasks 
    9290     * </p> 
    9391     *  
    94      * @param ruleManager the rule manager for comparing task tree nodes 
    95      */ 
    96     IterationComparisonRule(NodeEqualityRuleManager ruleManager) { 
     92     * @param ruleManager the rule manager for comparing tasks 
     93     */ 
     94    IterationComparisonRule(TaskEqualityRuleManager ruleManager) { 
    9795        super(); 
    9896        mRuleManager = ruleManager; 
     
    10098 
    10199    /* (non-Javadoc) 
    102      * @see NodeComparisonRule#isApplicable(ITaskTreeNode, ITaskTreeNode) 
    103      */ 
    104     @Override 
    105     public boolean isApplicable(ITaskTreeNode node1, ITaskTreeNode node2) { 
    106         return (node1 instanceof IIteration) && (node2 instanceof IIteration); 
    107     } 
    108  
    109     /* (non-Javadoc) 
    110      * @see NodeComparisonRule#areLexicallyEqual(ITaskTreeNode, ITaskTreeNode) 
    111      */ 
    112     @Override 
    113     public boolean areLexicallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 
    114         List<ITaskTreeNode> children1 = node1.getChildren(); 
    115         List<ITaskTreeNode> children2 = node2.getChildren(); 
    116          
    117         if (children1.size() == children2.size()) { 
    118             if (children1.size() == 0) { 
    119                 return true; 
     100     * @see NodeComparisonRule#isApplicable(ITask, ITask) 
     101     */ 
     102    @Override 
     103    public boolean isApplicable(ITask task1, ITask task2) { 
     104        return (task1 instanceof IIteration) && (task2 instanceof IIteration); 
     105    } 
     106 
     107    /* (non-Javadoc) 
     108     * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask) 
     109     */ 
     110    @Override 
     111    public boolean areLexicallyEqual(ITask task1, ITask task2) { 
     112        ITask child1 = ((IIteration) task1).getMarkedTask(); 
     113        ITask child2 = ((IIteration) task2).getMarkedTask(); 
     114         
     115        if (child1 != null) { 
     116            if (child2 == null) { 
     117                return false; 
    120118            } 
    121119            else { 
    122                 ITaskTreeNode child1 = children1.get(0); 
    123                 ITaskTreeNode child2 = children2.get(0); 
    124                  
    125120                // iterations may have 3 different structures. 
    126121                // 1. they have one child, which is the iterated one 
     
    136131                { 
    137132                    return getNodeEquality 
    138                         (child1, child2).isAtLeast(NodeEquality.LEXICALLY_EQUAL); 
     133                        (child1, child2).isAtLeast(TaskEquality.LEXICALLY_EQUAL); 
    139134                } 
    140135            } 
    141136        } 
     137        else if (child2 == null) { 
     138            return true; 
     139        } 
    142140         
    143141        return false; 
     
    145143 
    146144    /* (non-Javadoc) 
    147      * @see NodeComparisonRule#areSyntacticallyEqual(ITaskTreeNode, ITaskTreeNode) 
    148      */ 
    149     @Override 
    150     public boolean areSyntacticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 
    151         List<ITaskTreeNode> children1 = node1.getChildren(); 
    152         List<ITaskTreeNode> children2 = node2.getChildren(); 
    153          
    154         if (children1.size() == children2.size()) { 
    155             if (children1.size() == 0) { 
    156                 return true; 
     145     * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask) 
     146     */ 
     147    @Override 
     148    public boolean areSyntacticallyEqual(ITask task1, ITask task2) { 
     149        ITask child1 = ((IIteration) task1).getMarkedTask(); 
     150        ITask child2 = ((IIteration) task2).getMarkedTask(); 
     151         
     152        if (child1 != null) { 
     153            if (child2 == null) { 
     154                return false; 
    157155            } 
    158156            else { 
    159                 ITaskTreeNode child1 = children1.get(0); 
    160                 ITaskTreeNode child2 = children2.get(0); 
    161                  
    162157                // iterations may have 3 different structures. 
    163158                // 1. they have one child, which is the iterated one 
     
    167162                // ignore the type of the children but check them for equality. 
    168163                 
    169                 return getNodeEquality(child1, child2).isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL); 
    170             } 
     164                return getNodeEquality(child1, child2).isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL); 
     165            } 
     166        } 
     167        else if (child2 == null) { 
     168            return true; 
    171169        } 
    172170         
     
    175173 
    176174    /* (non-Javadoc) 
    177      * @see NodeComparisonRule#areSemanticallyEqual(ITaskTreeNode, ITaskTreeNode) 
    178      */ 
    179     @Override 
    180     public boolean areSemanticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 
    181         return compare(node1, node2).isAtLeast(NodeEquality.SEMANTICALLY_EQUAL); 
    182     } 
    183  
    184     /* (non-Javadoc) 
    185      * @see NodeComparisonRule#compare(ITaskTreeNode, ITaskTreeNode) 
    186      */ 
    187     @Override 
    188     public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 
    189         List<ITaskTreeNode> children1 = node1.getChildren(); 
    190         List<ITaskTreeNode> children2 = node2.getChildren(); 
     175     * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) 
     176     */ 
     177    @Override 
     178    public boolean areSemanticallyEqual(ITask task1, ITask task2) { 
     179        return compare(task1, task2).isAtLeast(TaskEquality.SEMANTICALLY_EQUAL); 
     180    } 
     181 
     182    /* (non-Javadoc) 
     183     * @see NodeComparisonRule#compare(ITask, ITask) 
     184     */ 
     185    @Override 
     186    public TaskEquality compare(ITask task1, ITask task2) { 
     187        ITask child1 = ((IIteration) task1).getMarkedTask(); 
     188        ITask child2 = ((IIteration) task2).getMarkedTask(); 
    191189 
    192190        // if both iterations do not have children, they are equal although this doesn't make sense 
    193         if ((children1.size() == 0) && (children2.size() == 0)) { 
    194             return NodeEquality.LEXICALLY_EQUAL; 
    195         } 
    196         else if ((children1.size() == 0) || (children2.size() == 0)) { 
    197             return NodeEquality.UNEQUAL; 
    198         } 
    199  
    200         ITaskTreeNode child1 = children1.get(0); 
    201         ITaskTreeNode child2 = children2.get(0); 
     191        if ((child1 == null) && (child2 == null)) { 
     192            return TaskEquality.LEXICALLY_EQUAL; 
     193        } 
     194        else if ((child1 == null) || (child2 == null)) { 
     195            return TaskEquality.UNEQUAL; 
     196        } 
    202197 
    203198        // iterations may have 3 different structures. 
     
    209204        // the permutations of the three variants in combination must be checked 
    210205 
    211         // check if both nodes are the same variants of iterations and if their children are equal. 
     206        // check if both tasks are the same variants of iterations and if their children are equal. 
    212207        // This condition matches, if both iterations are the same variants of iteration. I.e. three 
    213208        // combinations of the permutation are handled herewith. 
    214         NodeEquality nodeEquality = getNodeEquality(child1, child2); 
    215          
    216         if (nodeEquality != null) { 
    217             return nodeEquality; 
    218         } 
    219  
    220         // compare one iteration with a single node as a child and another one with a selection of 
    221         // semantically equal nodes 
     209        TaskEquality taskEquality = getNodeEquality(child1, child2); 
     210         
     211        if (taskEquality != null) { 
     212            return taskEquality; 
     213        } 
     214 
     215        // compare one iteration with a single task as a child and another one with a selection of 
     216        // semantically equal tasks 
    222217        return selectionChildrenSemanticallyEqualNode(child1, child2); 
    223218         
     
    229224     * TODO update comment 
    230225     */ 
    231     private NodeEquality getNodeEquality(ITaskTreeNode child1, ITaskTreeNode child2) { 
    232         NodeEquality nodeEquality = callRuleManager(child1, child2, null); 
    233  
    234         if (nodeEquality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)) { 
     226    private TaskEquality getNodeEquality(ITask child1, ITask child2) { 
     227        TaskEquality taskEquality = callRuleManager(child1, child2, null); 
     228 
     229        if (taskEquality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL)) { 
    235230            // prevent, that identical is returned, because the iterations itself are not identical 
    236231            // although the iterated tasks are 
    237             if (nodeEquality == NodeEquality.IDENTICAL) { 
    238                 return NodeEquality.LEXICALLY_EQUAL; 
     232            if (taskEquality == TaskEquality.IDENTICAL) { 
     233                return TaskEquality.LEXICALLY_EQUAL; 
    239234            } 
    240235            else { 
    241                 return nodeEquality; 
    242             } 
    243         } 
    244          
    245         return NodeEquality.UNEQUAL; 
     236                return taskEquality; 
     237            } 
     238        } 
     239         
     240        return TaskEquality.UNEQUAL; 
    246241    } 
    247242 
    248243    /** 
    249244     * <p> 
    250      * compares two task tree nodes. One of them must be a selection, the other one can be any task 
    251      * tree node. The method returns a node equality that is not <code>NodeEquality.UNEQUAL</code> 
    252      * if the other node is at least semantically equal to the children of the selection. It 
    253      * returns more concrete equalities, if the equality between the other node and the children 
     245     * compares two tasks. One of them must be a selection, the other one can be any task 
     246     * tree task. The method returns a task equality that is not <code>NodeEquality.UNEQUAL</code> 
     247     * if the other task is at least semantically equal to the children of the selection. It 
     248     * returns more concrete equalities, if the equality between the other task and the children 
    254249     * of the selection is more concrete. 
    255250     * </p>  
    256251     *  
    257      * @param taskTreeNode  the first task tree node to compare 
    258      * @param taskTreeNode2 the second task tree node to compare 
     252     * @param taskTreeNode  the first task to compare 
     253     * @param taskTreeNode2 the second task to compare 
    259254     *  
    260255     * @return as described 
    261256     */ 
    262     private NodeEquality selectionChildrenSemanticallyEqualNode(ITaskTreeNode taskTreeNode, 
    263                                                                 ITaskTreeNode taskTreeNode2) 
    264     { 
     257    private TaskEquality selectionChildrenSemanticallyEqualNode(ITask task1, ITask task2) { 
    265258        ISelection selection = null; 
    266         ITaskTreeNode node = null; 
    267         if (taskTreeNode instanceof ISelection) { 
    268             selection = (ISelection) taskTreeNode; 
    269             node = taskTreeNode2; 
    270         } 
    271         else if (taskTreeNode2 instanceof ISelection) { 
    272             selection = (ISelection) taskTreeNode2; 
    273             node = taskTreeNode; 
     259        ITask task = null; 
     260        if (task1 instanceof ISelection) { 
     261            selection = (ISelection) task1; 
     262            task = task2; 
     263        } 
     264        else if (task2 instanceof ISelection) { 
     265            selection = (ISelection) task2; 
     266            task = task1; 
    274267        } 
    275268        else { 
    276             return NodeEquality.UNEQUAL; 
     269            return TaskEquality.UNEQUAL; 
    277270        } 
    278271 
    279272        // Iterations, where one has a selection and the other one not can at most be syntactically 
    280273        // equal but not identical 
    281         NodeEquality commonDenominatorForAllComparisons = NodeEquality.SYNTACTICALLY_EQUAL; 
    282  
    283         for (ITaskTreeNode child : selection.getChildren()) { 
    284             NodeEquality nodeEquality = 
    285                   callRuleManager(node, child, commonDenominatorForAllComparisons); 
    286  
    287             if ((nodeEquality == null) || (nodeEquality == NodeEquality.UNEQUAL)) 
     274        TaskEquality commonDenominatorForAllComparisons = TaskEquality.SYNTACTICALLY_EQUAL; 
     275 
     276        for (ITask child : selection.getChildren()) { 
     277            TaskEquality taskEquality = 
     278                  callRuleManager(task, child, commonDenominatorForAllComparisons); 
     279 
     280            if ((taskEquality == null) || (taskEquality == TaskEquality.UNEQUAL)) 
    288281            { 
    289                 return NodeEquality.UNEQUAL; 
     282                return TaskEquality.UNEQUAL; 
    290283            } 
    291284             
    292285            commonDenominatorForAllComparisons = 
    293                 commonDenominatorForAllComparisons.getCommonDenominator(nodeEquality); 
     286                commonDenominatorForAllComparisons.getCommonDenominator(taskEquality); 
    294287        } 
    295288 
     
    307300     * @return 
    308301     */ 
    309     private NodeEquality callRuleManager(ITaskTreeNode child1, 
    310                                          ITaskTreeNode child2, 
    311                                          NodeEquality requiredEqualityLevel) 
     302    private TaskEquality callRuleManager(ITask        child1, 
     303                                         ITask        child2, 
     304                                         TaskEquality requiredEqualityLevel) 
    312305    { 
    313306        if (requiredEqualityLevel == null) { 
     
    318311        } 
    319312        else { 
    320             return NodeEquality.UNEQUAL; 
     313            return TaskEquality.UNEQUAL; 
    321314        } 
    322315    } 
Note: See TracChangeset for help on using the changeset viewer.