Ignore:
Timestamp:
08/14/13 17:04:42 (11 years ago)
Author:
pharms
Message:
  • rework of task model to move event instance stuff to task instances
  • introduction of sequence, selection, iteration and optional instances
File:
1 edited

Legend:

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

    r1190 r1294  
    1515package de.ugoe.cs.autoquest.tasktrees.taskequality; 
    1616 
    17 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 
    1817import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 
     18import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; 
    1919import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 
    20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
    2120import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
     21import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
    2222 
    2323/** 
     
    8282     
    8383    /* (non-Javadoc) 
    84      * @see NodeComparisonRule#isApplicable(ITask, ITask) 
     84     * @see TaskComparisonRule#isApplicable(ITask, ITask) 
    8585     */ 
    8686    @Override 
     
    9090 
    9191    /* (non-Javadoc) 
    92      * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask) 
     92     * @see TaskComparisonRule#areLexicallyEqual(ITask, ITask) 
    9393     */ 
    9494    @Override 
    9595    public boolean areLexicallyEqual(ITask task1, ITask task2) { 
    96         ITask child1 = ((IIteration) task1).getMarkedTask(); 
    97         ITask child2 = ((IIteration) task2).getMarkedTask(); 
    98          
    99         if (child1 != null) { 
    100             if (child2 == null) { 
    101                 return false; 
    102             } 
    103             else { 
    104                 // iterations may have 3 different structures. 
    105                 // 1. they have one child, which is the iterated one 
    106                 // 2. they have a sequence of children, which is iterated 
    107                 // 3. they have a selection of different iterated variants (usually the variants 
    108                 //    are semantically equal) 
    109                 // check if the type of children match. If not, return false. If they match, 
    110                 // use the equality manager to perform further comparisons 
    111                  
    112                 if (((child1 instanceof ISelection) && (child2 instanceof ISelection)) || 
    113                     ((child1 instanceof ISequence) && (child2 instanceof ISequence)) || 
    114                     ((child1 instanceof IEventTask) && (child2 instanceof IEventTask))) 
    115                 { 
    116                     return getNodeEquality 
    117                         (child1, child2).isAtLeast(TaskEquality.LEXICALLY_EQUAL); 
    118                 } 
    119             } 
    120         } 
    121         else if (child2 == null) { 
    122             return true; 
    123         } 
    124          
    125         return false; 
    126     } 
    127  
    128     /* (non-Javadoc) 
    129      * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask) 
    130      */ 
    131     @Override 
    132     public boolean areSyntacticallyEqual(ITask task1, ITask task2) { 
    13396        ITask child1 = ((IIteration) task1).getMarkedTask(); 
    13497        ITask child2 = ((IIteration) task2).getMarkedTask(); 
     
    146109                // ignore the type of the children but check them for equality. 
    147110                 
    148                 return getNodeEquality(child1, child2).isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL); 
     111                return getNodeEquality(child1, child2).isAtLeast(TaskEquality.LEXICALLY_EQUAL); 
    149112            } 
    150113        } 
     
    157120 
    158121    /* (non-Javadoc) 
    159      * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) 
     122     * @see TaskComparisonRule#areSyntacticallyEqual(ITask, ITask) 
     123     */ 
     124    @Override 
     125    public boolean areSyntacticallyEqual(ITask task1, ITask task2) { 
     126        return areLexicallyEqual(task1, task2); 
     127    } 
     128 
     129    /* (non-Javadoc) 
     130     * @see TaskComparisonRule#areSemanticallyEqual(ITask, ITask) 
    160131     */ 
    161132    @Override 
     
    165136 
    166137    /* (non-Javadoc) 
    167      * @see NodeComparisonRule#compare(ITask, ITask) 
     138     * @see TaskComparisonRule#compare(ITask, ITask) 
    168139     */ 
    169140    @Override 
     
    203174        // all other combinations (i.e. sequence with single child and sequence with selection) 
    204175        // can not match 
     176    } 
     177 
     178    /* (non-Javadoc) 
     179     * @see TaskComparisonRule#isApplicable(ITaskInstance, ITaskInstance) 
     180     */ 
     181    @Override 
     182    public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2) { 
     183        return isApplicable(instance1.getTask(), instance2.getTask()); 
     184    } 
     185 
     186    /* (non-Javadoc) 
     187     * @see TaskComparisonRule#areLexicallyEqual(ITaskInstance, ITaskInstance) 
     188     */ 
     189    @Override 
     190    public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     191        IIterationInstance iteration1 = (IIterationInstance) instance1; 
     192        IIterationInstance iteration2 = (IIterationInstance) instance2; 
     193 
     194        // if both sequences do not have children, they are equal although this doesn't make sense 
     195        if ((iteration1.size() == 0) && (iteration2.size() == 0)) { 
     196            return true; 
     197        } 
     198 
     199        if (iteration1.size() != iteration2.size()) { 
     200            return false; 
     201        } 
     202 
     203        for (int i = 0; i < iteration1.size(); i++) { 
     204            ITaskInstance child1 = iteration1.get(i); 
     205            ITaskInstance child2 = iteration2.get(i); 
     206 
     207            TaskEquality taskEquality = 
     208                callRuleManager(child1, child2, TaskEquality.LEXICALLY_EQUAL); 
     209 
     210            if ((taskEquality == null) || (taskEquality == TaskEquality.UNEQUAL)) { 
     211                return false; 
     212            } 
     213        } 
     214 
     215        return true; 
     216    } 
     217 
     218    /* (non-Javadoc) 
     219     * @see TaskComparisonRule#areSyntacticallyEqual(ITaskInstance, ITaskInstance) 
     220     */ 
     221    @Override 
     222    public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     223        return areLexicallyEqual(instance1, instance2); 
     224    } 
     225 
     226    /* (non-Javadoc) 
     227     * @see TaskComparisonRule#areSemanticallyEqual(ITaskInstance, ITaskInstance) 
     228     */ 
     229    @Override 
     230    public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     231        return areLexicallyEqual(instance1, instance2); 
     232    } 
     233 
     234    /* (non-Javadoc) 
     235     * @see TaskComparisonRule#compare(ITaskInstance, ITaskInstance) 
     236     */ 
     237    @Override 
     238    public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) { 
     239        if (areLexicallyEqual(instance1, instance2)) { 
     240            return TaskEquality.LEXICALLY_EQUAL; 
     241        } 
     242        else { 
     243            return TaskEquality.UNEQUAL; 
     244        } 
    205245    } 
    206246 
     
    272312                  callRuleManager(task, child, commonDenominatorForAllComparisons); 
    273313 
    274             if ((taskEquality == null) || (taskEquality == TaskEquality.UNEQUAL)) 
    275             { 
     314            if ((taskEquality == null) || (taskEquality == TaskEquality.UNEQUAL)) { 
    276315                return TaskEquality.UNEQUAL; 
    277316            } 
     
    314353        } 
    315354    } 
     355     
     356    /** 
     357     * <p> 
     358     * used to to call the task equality rule manager for the comparison of the two provided 
     359     * children. If no required equality level is provided, than the most concrete equality is 
     360     * returned. Otherwise, the required equality is returned as long as the children are equal 
     361     * on that level. 
     362     * </p>  
     363     *  
     364     * @param taskInstance1         the first task instance to be compared 
     365     * @param taskInstance2         the second task instance to be compared 
     366     * @param requiredEqualityLevel the equality level to be checked for 
     367     *  
     368     * @return the determined equality 
     369     */ 
     370    private TaskEquality callRuleManager(ITaskInstance taskInstance1, 
     371                                         ITaskInstance taskInstance2, 
     372                                         TaskEquality  requiredEqualityLevel) 
     373    { 
     374        if (requiredEqualityLevel == null) { 
     375            return TaskEqualityRuleManager.getInstance().compare(taskInstance1, taskInstance2); 
     376        } 
     377        else if (TaskEqualityRuleManager.getInstance().areAtLeastEqual 
     378                     (taskInstance1, taskInstance2, requiredEqualityLevel)) 
     379        { 
     380            return requiredEqualityLevel; 
     381        } 
     382        else { 
     383            return TaskEquality.UNEQUAL; 
     384        } 
     385    } 
    316386} 
Note: See TracChangeset for help on using the changeset viewer.