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
Location:
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees
Files:
10 added
29 edited
2 moved

Legend:

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

    r1154 r1294  
    2121 
    2222import de.ugoe.cs.autoquest.eventcore.Event; 
    23 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
     23import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 
    2424import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; 
    2525import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; 
     
    124124    public void handleNewEvent(Event event) { 
    125125        assertSessionSequence(); 
    126         ITask eventTask = taskFactory.createNewEventTask(event.getType(), event.getTarget()); 
    127         taskBuilder.addExecutedTask(currentSession, taskFactory.createNewTaskInstance(eventTask)); 
     126        String description = event.getType().getName() + " \u21D2 " + event.getTarget(); 
     127        IEventTask eventTask = taskFactory.createNewEventTask(description); 
     128        taskBuilder.addExecutedTask 
     129            (currentSession, taskFactory.createNewTaskInstance(eventTask, event)); 
    128130    } 
    129131 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/EventTaskComparisonRule.java

    r1146 r1294  
    1515package de.ugoe.cs.autoquest.tasktrees.taskequality; 
    1616 
     17import java.util.Collection; 
     18 
    1719import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 
     20import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; 
    1821import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
     22import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
    1923 
    2024/** 
     
    2933     
    3034    /* (non-Javadoc) 
    31      * @see NodeComparisonRule#isApplicable(ITask, ITask) 
     35     * @see TaskComparisonRule#isApplicable(ITask, ITask) 
    3236     */ 
    3337    @Override 
     
    3741 
    3842    /* (non-Javadoc) 
    39      * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask) 
     43     * @see TaskComparisonRule#areLexicallyEqual(ITask, ITask) 
    4044     */ 
    4145    @Override 
    4246    public boolean areLexicallyEqual(ITask task1, ITask task2) { 
    43         IEventTask eventTask1 = (IEventTask) task1; 
    44         IEventTask eventTask2 = (IEventTask) task2; 
     47        Collection<ITaskInstance> taskInstances1 = task1.getInstances(); 
     48        Collection<ITaskInstance> taskInstances2 = task2.getInstances(); 
    4549         
    46         return (eventTask1.getEventType().equals(eventTask2.getEventType()) && 
    47                 eventTask1.getEventTarget().equals(eventTask2.getEventTarget())); 
     50        for (ITaskInstance instance1 : taskInstances1) { 
     51            boolean found = false; 
     52             
     53            for (ITaskInstance instance2 : taskInstances2) { 
     54                if (areLexicallyEqual(instance1, instance2)) { 
     55                    found = true; 
     56                    break; 
     57                } 
     58            } 
     59             
     60            if (!found) { 
     61                return false; 
     62            } 
     63        } 
     64         
     65        return true; 
    4866    } 
    4967 
    5068    /* (non-Javadoc) 
    51      * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask) 
     69     * @see TaskComparisonRule#areSyntacticallyEqual(ITask, ITask) 
    5270     */ 
    5371    @Override 
     
    5775 
    5876    /* (non-Javadoc) 
    59      * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) 
     77     * @see TaskComparisonRule#areSemanticallyEqual(ITask, ITask) 
    6078     */ 
    6179    @Override 
     
    6482    } 
    6583 
     84    /* (non-Javadoc) 
     85     * @see TaskComparisonRule#compare(ITask, ITask) 
     86     */ 
    6687    @Override 
    6788    public TaskEquality compare(ITask task1, ITask task2) { 
     
    7495    } 
    7596 
     97     
     98    /* (non-Javadoc) 
     99     * @see TaskComparisonRule#isApplicable(ITaskInstance, ITaskInstance) 
     100     */ 
     101    @Override 
     102    public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2) { 
     103        return 
     104            (instance1 instanceof IEventTaskInstance) && (instance2 instanceof IEventTaskInstance); 
     105    } 
     106 
     107    /* (non-Javadoc) 
     108     * @see TaskComparisonRule#areLexicallyEqual(ITaskInstance, ITaskInstance) 
     109     */ 
     110    @Override 
     111    public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     112        IEventTaskInstance eventTask1 = (IEventTaskInstance) instance1; 
     113        IEventTaskInstance eventTask2 = (IEventTaskInstance) instance2; 
     114         
     115        return (eventTask1.getEvent().getType().equals(eventTask2.getEvent().getType()) && 
     116                eventTask1.getEvent().getTarget().equals(eventTask2.getEvent().getTarget())); 
     117    } 
     118 
     119    /* (non-Javadoc) 
     120     * @see TaskComparisonRule#areSyntacticallyEqual(ITaskInstance, ITaskInstance) 
     121     */ 
     122    @Override 
     123    public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     124        return areLexicallyEqual(instance1, instance2); 
     125    } 
     126 
     127    /* (non-Javadoc) 
     128     * @see TaskComparisonRule#areSemanticallyEqual(ITaskInstance, ITaskInstance) 
     129     */ 
     130    @Override 
     131    public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     132        return areLexicallyEqual(instance1, instance2); 
     133    } 
     134 
     135    /* (non-Javadoc) 
     136     * @see TaskComparisonRule#compare(ITaskInstance, ITaskInstance) 
     137     */ 
     138    @Override 
     139    public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) { 
     140        if (areLexicallyEqual(instance1, instance2)) { 
     141            return TaskEquality.LEXICALLY_EQUAL; 
     142        } 
     143        else { 
     144            return TaskEquality.UNEQUAL; 
     145        } 
     146    } 
     147 
    76148} 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/GUIEventTaskComparisonRule.java

    r1154 r1294  
    1414 
    1515package de.ugoe.cs.autoquest.tasktrees.taskequality; 
     16 
     17import java.util.Collection; 
    1618 
    1719import de.ugoe.cs.autoquest.eventcore.IEventTarget; 
     
    4143import de.ugoe.cs.autoquest.eventcore.guimodel.IText; 
    4244import de.ugoe.cs.autoquest.eventcore.guimodel.IToolTip; 
    43 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 
     45import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; 
    4446import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
     47import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
    4548 
    4649/** 
     
    6164     
    6265    /* (non-Javadoc) 
    63      * @see NodeComparisonRule#isApplicable(ITask, ITask) 
     66     * @see TaskComparisonRule#isApplicable(ITask, ITask) 
    6467     */ 
    6568    @Override 
    6669    public boolean isApplicable(ITask task1, ITask task2) { 
    67         return 
    68             ((task1 instanceof IEventTask) && (task2 instanceof IEventTask) && 
    69             (((IEventTask) task1).getEventType() instanceof IInteraction) && 
    70             (((IEventTask) task2).getEventType() instanceof IInteraction)); 
    71     } 
    72  
    73     /* (non-Javadoc) 
    74      * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask) 
     70        for (ITaskInstance instance : task1.getInstances()) { 
     71            if ((!(instance instanceof IEventTaskInstance)) || 
     72                (!(((IEventTaskInstance) instance).getEvent().getType() instanceof IInteraction))) 
     73            { 
     74                return false; 
     75            } 
     76        } 
     77         
     78        for (ITaskInstance instance : task2.getInstances()) { 
     79            if ((!(instance instanceof IEventTaskInstance)) || 
     80                (!(((IEventTaskInstance) instance).getEvent().getType() instanceof IInteraction))) 
     81            { 
     82                return false; 
     83            } 
     84        } 
     85         
     86        return true; 
     87    } 
     88 
     89    /* (non-Javadoc) 
     90     * @see TaskComparisonRule#areLexicallyEqual(ITask, ITask) 
    7591     */ 
    7692    @Override 
     
    8197 
    8298    /* (non-Javadoc) 
    83      * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask) 
     99     * @see TaskComparisonRule#areSyntacticallyEqual(ITask, ITask) 
    84100     */ 
    85101    @Override 
     
    90106 
    91107    /* (non-Javadoc) 
    92      * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) 
     108     * @see TaskComparisonRule#areSemanticallyEqual(ITask, ITask) 
    93109     */ 
    94110    @Override 
     
    99115 
    100116    /* (non-Javadoc) 
    101      * @see NodeComparisonRule#compare(ITask, ITask) 
     117     * @see TaskComparisonRule#compare(ITask, ITask) 
    102118     */ 
    103119    @Override 
     
    106122    } 
    107123 
    108     /** 
    109      *  
    110      */ 
    111     private TaskEquality getEquality(ITask task1, ITask task2, TaskEquality requiredEqualityLevel) { 
    112         IEventTask eventTask1 = (IEventTask) task1; 
    113         IEventTask eventTask2 = (IEventTask) task2; 
    114          
    115         if (!eventTask1.getEventTarget().equals(eventTask2.getEventTarget())) { 
     124    /* (non-Javadoc) 
     125     * @see de.ugoe.cs.autoquest.tasktrees.taskequality.TaskComparisonRule#isApplicable(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance) 
     126     */ 
     127    @Override 
     128    public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2) { 
     129        return 
     130            (instance1 instanceof IEventTaskInstance) && 
     131            (instance2 instanceof IEventTaskInstance) && 
     132            (((IEventTaskInstance) instance1).getEvent().getType() instanceof IInteraction) && 
     133            (((IEventTaskInstance) instance1).getEvent().getType() instanceof IInteraction); 
     134    } 
     135 
     136    /* (non-Javadoc) 
     137     * @see de.ugoe.cs.autoquest.tasktrees.taskequality.TaskComparisonRule#areLexicallyEqual(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance) 
     138     */ 
     139    @Override 
     140    public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     141        TaskEquality equality = getEquality(instance1, instance2, TaskEquality.LEXICALLY_EQUAL); 
     142        return (equality != null) && (equality.isAtLeast(TaskEquality.LEXICALLY_EQUAL)); 
     143    } 
     144 
     145    /* (non-Javadoc) 
     146     * @see de.ugoe.cs.autoquest.tasktrees.taskequality.TaskComparisonRule#areSyntacticallyEqual(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance) 
     147     */ 
     148    @Override 
     149    public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     150        TaskEquality equality = getEquality(instance1, instance2, TaskEquality.SYNTACTICALLY_EQUAL); 
     151        return (equality != null) && (equality.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)); 
     152    } 
     153 
     154    /* (non-Javadoc) 
     155     * @see de.ugoe.cs.autoquest.tasktrees.taskequality.TaskComparisonRule#areSemanticallyEqual(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance) 
     156     */ 
     157    @Override 
     158    public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     159        TaskEquality equality = getEquality(instance1, instance2, TaskEquality.SEMANTICALLY_EQUAL); 
     160        return (equality != null) && (equality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL)); 
     161    } 
     162 
     163    /* (non-Javadoc) 
     164     * @see de.ugoe.cs.autoquest.tasktrees.taskequality.TaskComparisonRule#compare(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance) 
     165     */ 
     166    @Override 
     167    public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) { 
     168        return getEquality(instance1, instance2, null); 
     169    } 
     170 
     171    /** 
     172     *  
     173     */ 
     174    private TaskEquality getEquality(ITask         task1, 
     175                                     ITask         task2, 
     176                                     TaskEquality  requiredEqualityLevel) 
     177    { 
     178        Collection<ITaskInstance> taskInstances1 = task1.getInstances(); 
     179        Collection<ITaskInstance> taskInstances2 = task2.getInstances(); 
     180         
     181        TaskEquality checkedEquality = 
     182            requiredEqualityLevel != null ? requiredEqualityLevel : TaskEquality.SEMANTICALLY_EQUAL; 
     183         
     184        TaskEquality commonDenominator = TaskEquality.LEXICALLY_EQUAL; 
     185         
     186        for (ITaskInstance instance1 : taskInstances1) { 
     187            TaskEquality mostConcreteEquality = null; 
     188             
     189            for (ITaskInstance instance2 : taskInstances2) { 
     190                TaskEquality equality = getEquality(instance1, instance2, requiredEqualityLevel); 
     191                 
     192                if ((equality != null) && ((mostConcreteEquality == null) || 
     193                                           (equality.isAtLeast(mostConcreteEquality)))) 
     194                { 
     195                    mostConcreteEquality = equality; 
     196                     
     197                    if (((requiredEqualityLevel != null) && 
     198                         (mostConcreteEquality.isAtLeast(requiredEqualityLevel))) || 
     199                        (mostConcreteEquality.isAtLeast(TaskEquality.LEXICALLY_EQUAL))) 
     200                    { 
     201                        break; 
     202                    } 
     203                } 
     204            } 
     205             
     206            commonDenominator = commonDenominator.getCommonDenominator(mostConcreteEquality); 
     207             
     208            if (!commonDenominator.isAtLeast(checkedEquality)) { 
     209                return TaskEquality.UNEQUAL; 
     210            } 
     211        } 
     212         
     213        return commonDenominator; 
     214    } 
     215 
     216    /** 
     217     *  
     218     */ 
     219    private TaskEquality getEquality(ITaskInstance instance1, 
     220                                     ITaskInstance instance2, 
     221                                     TaskEquality  requiredEqualityLevel) 
     222    { 
     223        IEventTaskInstance eventTask1 = (IEventTaskInstance) instance1; 
     224        IEventTaskInstance eventTask2 = (IEventTaskInstance) instance2; 
     225         
     226        if (!eventTask1.getEvent().getTarget().equals(eventTask2.getEvent().getTarget())) { 
    116227            return TaskEquality.UNEQUAL; 
    117228        } 
    118229         
    119         IInteraction interaction1 = (IInteraction) eventTask1.getEventType(); 
    120         IInteraction interaction2 = (IInteraction) eventTask2.getEventType(); 
     230        IInteraction interaction1 = (IInteraction) eventTask1.getEvent().getType(); 
     231        IInteraction interaction2 = (IInteraction) eventTask2.getEvent().getType(); 
    121232         
    122233        return compareInteractions 
    123             (interaction1, interaction2, eventTask1.getEventTarget(), requiredEqualityLevel); 
     234            (interaction1, interaction2, eventTask1.getEvent().getTarget(), requiredEqualityLevel); 
    124235    } 
    125236 
  • 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} 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/SelectionComparisonRule.java

    r1190 r1294  
    1818 
    1919import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 
     20import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; 
    2021import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
     22import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
    2123 
    2224/** 
     
    3941 
    4042    /* (non-Javadoc) 
    41      * @see NodeComparisonRule#isApplicable(ITask, ITask) 
     43     * @see TaskComparisonRule#isApplicable(ITask, ITask) 
    4244     */ 
    4345    @Override 
     
    4749 
    4850    /* (non-Javadoc) 
    49      * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask) 
     51     * @see TaskComparisonRule#areLexicallyEqual(ITask, ITask) 
    5052     */ 
    5153    @Override 
     
    5658 
    5759    /* (non-Javadoc) 
    58      * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask) 
     60     * @see TaskComparisonRule#areSyntacticallyEqual(ITask, ITask) 
    5961     */ 
    6062    @Override 
     
    6567 
    6668    /* (non-Javadoc) 
    67      * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) 
     69     * @see TaskComparisonRule#areSemanticallyEqual(ITask, ITask) 
    6870     */ 
    6971    @Override 
     
    7476 
    7577    /* (non-Javadoc) 
    76      * @see NodeComparisonRule#compare(ITask, ITask) 
     78     * @see TaskComparisonRule#compare(ITask, ITask) 
    7779     */ 
    7880    @Override 
    7981    public TaskEquality compare(ITask task1, ITask task2) { 
    8082        return getEquality(task1, task2, null); 
     83    } 
     84 
     85    /* (non-Javadoc) 
     86     * @see TaskComparisonRule#isApplicable(ITaskInstance, ITaskInstance) 
     87     */ 
     88    @Override 
     89    public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2) { 
     90        return isApplicable(instance1.getTask(), instance2.getTask()); 
     91    } 
     92 
     93    /* (non-Javadoc) 
     94     * @see TaskComparisonRule#areLexicallyEqual(ITaskInstance, ITaskInstance) 
     95     */ 
     96    @Override 
     97    public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     98        TaskEquality equality = getEquality(instance1, instance2, TaskEquality.LEXICALLY_EQUAL); 
     99        return (equality != null) && (equality.isAtLeast(TaskEquality.LEXICALLY_EQUAL)); 
     100    } 
     101 
     102    /* (non-Javadoc) 
     103     * @see TaskComparisonRule#areSyntacticallyEqual(ITaskInstance, ITaskInstance) 
     104     */ 
     105    @Override 
     106    public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     107        TaskEquality equality = getEquality(instance1, instance2, TaskEquality.SYNTACTICALLY_EQUAL); 
     108        return (equality != null) && (equality.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)); 
     109    } 
     110 
     111    /* (non-Javadoc) 
     112     * @see TaskComparisonRule#areSemanticallyEqual(ITaskInstance, ITaskInstance) 
     113     */ 
     114    @Override 
     115    public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     116        TaskEquality equality = getEquality(instance1, instance2, TaskEquality.SEMANTICALLY_EQUAL); 
     117        return (equality != null) && (equality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL)); 
     118    } 
     119 
     120    /* (non-Javadoc) 
     121     * @see TaskComparisonRule#compare(ITaskInstance, ITaskInstance) 
     122     */ 
     123    @Override 
     124    public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) { 
     125        return getEquality(instance1, instance2, null); 
    81126    } 
    82127 
     
    107152        } 
    108153 
    109         TaskEquality selectionEquality; 
    110  
    111154        if (requiredEqualityLevel == null) { 
    112155            // calculate the common equality level for all children of both selections. 
    113156            // do it in both directions to ensure commutative comparison 
    114             selectionEquality = getCommonEqualityLevel(children1, children2); 
    115             if (selectionEquality != TaskEquality.UNEQUAL) { 
    116                 return selectionEquality.getCommonDenominator 
    117                     (getCommonEqualityLevel(children2, children1)); 
    118             } 
    119             else { 
    120                 return TaskEquality.UNEQUAL; 
    121             } 
     157            return getMostConcreteEqualityLevel(children1, children2); 
    122158        } 
    123159        else { 
    124160            // we are searching for a specific equality 
    125             if (checkEqualityLevel(children1, children2, requiredEqualityLevel) && 
    126                 checkEqualityLevel(children2, children1, requiredEqualityLevel)) 
    127             { 
     161            if (checkEqualityLevel(children1, children2, requiredEqualityLevel)) { 
    128162                return requiredEqualityLevel; 
    129163            } 
     
    136170    /** 
    137171     * <p> 
    138      * determines the common equality level for all tasks in the first list compared to all 
    139      * tasks in the second list. If for one task in the first list, there is no equal task in the 
    140      * second list, the method return unequality.  
     172     * determines the most concrete equality level for all tasks in the first list compared to all 
     173     * tasks in the second list. It is sufficient, if there is one task in one list for which there 
     174     * exist an equal task in the other list. 
    141175     * </p> 
    142176     * 
     
    144178     * @param children2 the second list to be compared 
    145179     *  
    146      * @return the common task equality identified for all tasks in the first list with respect to 
    147      *         the second list 
    148      */ 
    149     private TaskEquality getCommonEqualityLevel(List<ITask> children1, List<ITask> children2) { 
    150         TaskEquality listEquality = TaskEquality.LEXICALLY_EQUAL; 
    151          
     180     * @return the most concrete task equality identified for all tasks in the first list with 
     181     *         respect to the second list 
     182     */ 
     183    private TaskEquality getMostConcreteEqualityLevel(List<ITask> children1, List<ITask> children2) 
     184    { 
    152185        TaskEquality childEquality; 
    153186        TaskEquality currentEquality; 
     
    164197                    } 
    165198                     
    166                     if (childEquality == TaskEquality.SEMANTICALLY_EQUAL) { 
    167                         // as we calculate only the common denominator, we can break up here for 
    168                         // the current child. We will not improve the denominator anymore 
    169                         break; 
     199                    if (childEquality.isAtLeast(TaskEquality.LEXICALLY_EQUAL)) { 
     200                        // as we calculate the most concrete equality, we can break up here 
     201                        return TaskEquality.LEXICALLY_EQUAL; 
    170202                    } 
    171203                } 
    172204            } 
    173              
    174             if (childEquality == null) { 
    175                 // we did not find any child in the second list, that is equal to the searched 
    176                 // child 
    177                 return TaskEquality.UNEQUAL; 
    178             } 
    179             else { 
    180                 listEquality = listEquality.getCommonDenominator(childEquality); 
    181             } 
    182         } 
    183  
    184         return listEquality; 
    185     } 
    186  
    187     /** 
    188      * <p> 
    189      * ensures for the two given lists, that for each task in the first list there is a task 
     205        } 
     206 
     207        // as the comparison should be commutative, we do not need to check, if in list 2 there is 
     208        // a child equal to one in list 1 
     209        return TaskEquality.UNEQUAL; 
     210    } 
     211 
     212    /** 
     213     * <p> 
     214     * ensures for the two given lists, that for at least one task in the first list there is a task 
    190215     * in the second list being on the given level equal to the task in the first list. 
    191216     * </p>  
     
    195220     * @param requiredEqualityLevel the equality level to be checked for 
    196221     *  
    197      * @return true if each task in the first list has an equal task in the second list when 
    198      *         considering the given equality level, false else. 
     222     * @return true if there is a task in the first list that has an equal task in the second list 
     223     *         when considering the given equality level, false else. 
    199224     */ 
    200225    private boolean checkEqualityLevel(List<ITask>  children1, 
     
    202227                                       TaskEquality requiredEqualityLevel) 
    203228    { 
    204         TaskEquality childEquality; 
    205229        TaskEquality currentEquality; 
    206230        for (ITask child1 : children1) { 
    207             childEquality = null; 
    208231            for (ITask child2 : children2) { 
    209232                currentEquality = callRuleManager(child1, child2, requiredEqualityLevel); 
     
    212235                    // we found at least one equal child with sufficient equality in the 
    213236                    // second list. So be can break up for this child. 
    214                     childEquality = currentEquality; 
    215                     break; 
     237                    return true; 
    216238                } 
    217239            } 
    218              
    219             if (childEquality == null) { 
    220                 // we did not find any child in the second list, that is equal to the searched 
    221                 // child 
    222                 return false; 
    223             } 
    224         } 
    225  
    226         // for all children, we found an equality  
    227         return true; 
     240        } 
     241 
     242        return false; 
    228243    } 
    229244 
     
    259274    } 
    260275 
     276    /** 
     277     * <p> 
     278     * compares two selection instances with each other checking for the provided required level of 
     279     * equality. If this level is ensured, the method immediately returns. The more concrete 
     280     * the required equality level, the more checks this method performs. 
     281     * </p> 
     282     *  
     283     * @param taskInstance1         the first task instance to be compared 
     284     * @param taskInstance2         the second task instance to be compared 
     285     * @param requiredEqualityLevel the equality level to be checked for 
     286     *  
     287     * @return the determined equality. 
     288     */ 
     289    private TaskEquality getEquality(ITaskInstance taskInstance1, 
     290                                     ITaskInstance taskInstance2, 
     291                                     TaskEquality  requiredEqualityLevel) 
     292    { 
     293        ITaskInstance child1 = ((ISelectionInstance) taskInstance1).getChild(); 
     294        ITaskInstance child2 = ((ISelectionInstance) taskInstance2).getChild(); 
     295 
     296        // if both selections do not have children, they are lexically equal. If only one of them 
     297        // has children, they are unequal. 
     298        if ((child1 == null) && (child2 == null)) { 
     299            return TaskEquality.LEXICALLY_EQUAL; 
     300        } 
     301        else if ((child1 == null) || (child2 == null)) { 
     302            return TaskEquality.UNEQUAL; 
     303        } 
     304 
     305        TaskEquality equality = callRuleManager(child1, child2, requiredEqualityLevel); 
     306         
     307        if (equality == TaskEquality.IDENTICAL) { 
     308            // two different selection instances can be at most lexically equal even if their 
     309            // children are identical 
     310            return TaskEquality.LEXICALLY_EQUAL; 
     311        } 
     312        else { 
     313            return equality; 
     314        } 
     315    } 
     316 
     317    /** 
     318     * <p> 
     319     * used to to call the task equality rule manager for the comparison of the two provided 
     320     * children. If no required equality level is provided, than the most concrete equality is 
     321     * returned. Otherwise, the required equality is returned as long as the children are equal 
     322     * on that level. 
     323     * </p>  
     324     *  
     325     * @param taskInstance1         the first task instance to be compared 
     326     * @param taskInstance2         the second task instance to be compared 
     327     * @param requiredEqualityLevel the equality level to be checked for 
     328     *  
     329     * @return the determined equality 
     330     */ 
     331    private TaskEquality callRuleManager(ITaskInstance taskInstance1, 
     332                                         ITaskInstance taskInstance2, 
     333                                         TaskEquality  requiredEqualityLevel) 
     334    { 
     335        if (requiredEqualityLevel == null) { 
     336            return TaskEqualityRuleManager.getInstance().compare(taskInstance1, taskInstance2); 
     337        } 
     338        else if (TaskEqualityRuleManager.getInstance().areAtLeastEqual 
     339                     (taskInstance1, taskInstance2, requiredEqualityLevel)) 
     340        { 
     341            return requiredEqualityLevel; 
     342        } 
     343        else { 
     344            return TaskEquality.UNEQUAL; 
     345        } 
     346    } 
    261347} 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/SequenceComparisonRule.java

    r1190 r1294  
    1818 
    1919import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
     20import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance; 
    2021import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
     22import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
    2123 
    2224/** 
     
    3436 
    3537    /* (non-Javadoc) 
    36      * @see NodeComparisonRule#isApplicable(ITask, ITask) 
     38     * @see TaskComparisonRule#isApplicable(ITask, ITask) 
    3739     */ 
    3840    @Override 
     
    4244 
    4345    /* (non-Javadoc) 
    44      * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask) 
     46     * @see TaskComparisonRule#areLexicallyEqual(ITask, ITask) 
    4547     */ 
    4648    @Override 
     
    5153 
    5254    /* (non-Javadoc) 
    53      * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask) 
     55     * @see TaskComparisonRule#areSyntacticallyEqual(ITask, ITask) 
    5456     */ 
    5557    @Override 
     
    6062 
    6163    /* (non-Javadoc) 
    62      * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) 
     64     * @see TaskComparisonRule#areSemanticallyEqual(ITask, ITask) 
    6365     */ 
    6466    @Override 
     
    6971 
    7072    /* (non-Javadoc) 
    71      * @see NodeComparisonRule#compare(ITask, ITask) 
     73     * @see TaskComparisonRule#compare(ITask, ITask) 
    7274     */ 
    7375    @Override 
    7476    public TaskEquality compare(ITask task1, ITask task2) { 
    7577        return getEquality(task1, task2, null); 
     78    } 
     79 
     80    /* (non-Javadoc) 
     81     * @see TaskComparisonRule#isApplicable(ITaskInstance, ITaskInstance) 
     82     */ 
     83    @Override 
     84    public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2) { 
     85        return isApplicable(instance1.getTask(), instance2.getTask()); 
     86    } 
     87 
     88    /* (non-Javadoc) 
     89     * @see TaskComparisonRule#areLexicallyEqual(ITaskInstance, ITaskInstance) 
     90     */ 
     91    @Override 
     92    public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     93        TaskEquality equality = getEquality(instance1, instance2, TaskEquality.LEXICALLY_EQUAL); 
     94        return (equality != null) && (equality.isAtLeast(TaskEquality.LEXICALLY_EQUAL)); 
     95    } 
     96 
     97    /* (non-Javadoc) 
     98     * @see TaskComparisonRule#areSyntacticallyEqual(ITaskInstance, ITaskInstance) 
     99     */ 
     100    @Override 
     101    public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     102        TaskEquality equality = getEquality(instance1, instance2, TaskEquality.SYNTACTICALLY_EQUAL); 
     103        return (equality != null) && (equality.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)); 
     104    } 
     105 
     106    /* (non-Javadoc) 
     107     * @see TaskComparisonRule#areSemanticallyEqual(ITaskInstance, ITaskInstance) 
     108     */ 
     109    @Override 
     110    public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     111        TaskEquality equality = getEquality(instance1, instance2, TaskEquality.SEMANTICALLY_EQUAL); 
     112        return (equality != null) && (equality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL)); 
     113    } 
     114 
     115    /* (non-Javadoc) 
     116     * @see TaskComparisonRule#compare(ITaskInstance, ITaskInstance) 
     117     */ 
     118    @Override 
     119    public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) { 
     120        return getEquality(instance1, instance2, null); 
    76121    } 
    77122 
     
    149194        } 
    150195    } 
     196 
     197    /** 
     198     * <p> 
     199     * compares two sequence instances with each other checking for the provided required level of 
     200     * equality. If this level is ensured, the method immediately returns. The more concrete 
     201     * the required equality level, the more checks this method performs. 
     202     * </p> 
     203     *  
     204     * @param taskInstance1         the first task instance to be compared 
     205     * @param taskInstance2         the second task instance to be compared 
     206     * @param requiredEqualityLevel the equality level to be checked for 
     207     *  
     208     * @return the determined equality. 
     209     */ 
     210    private TaskEquality getEquality(ITaskInstance taskInstance1, 
     211                                     ITaskInstance taskInstance2, 
     212                                     TaskEquality  requiredEqualityLevel) 
     213    { 
     214        ISequenceInstance sequence1 = (ISequenceInstance) taskInstance1; 
     215        ISequenceInstance sequence2 = (ISequenceInstance) taskInstance2; 
     216 
     217        // if both sequences do not have children, they are equal although this doesn't make sense 
     218        if ((sequence1.size() == 0) && (sequence2.size() == 0)) { 
     219            return TaskEquality.LEXICALLY_EQUAL; 
     220        } 
     221 
     222        if (sequence1.size() != sequence2.size()) { 
     223            return TaskEquality.UNEQUAL; 
     224        } 
     225 
     226        TaskEquality resultingEquality = TaskEquality.LEXICALLY_EQUAL; 
     227        for (int i = 0; i < sequence1.size(); i++) { 
     228            ITaskInstance child1 = sequence1.get(i); 
     229            ITaskInstance child2 = sequence2.get(i); 
     230 
     231            TaskEquality taskEquality = callRuleManager(child1, child2, requiredEqualityLevel); 
     232 
     233            if ((taskEquality == null) || (taskEquality == TaskEquality.UNEQUAL)) { 
     234                return TaskEquality.UNEQUAL; 
     235            } 
     236             
     237            resultingEquality = resultingEquality.getCommonDenominator(taskEquality); 
     238        } 
     239 
     240        return resultingEquality; 
     241    } 
     242     
     243    /** 
     244     * <p> 
     245     * used to to call the task equality rule manager for the comparison of the two provided 
     246     * children. If no required equality level is provided, than the most concrete equality is 
     247     * returned. Otherwise, the required equality is returned as long as the children are equal 
     248     * on that level. 
     249     * </p>  
     250     *  
     251     * @param taskInstance1         the first task instance to be compared 
     252     * @param taskInstance2         the second task instance to be compared 
     253     * @param requiredEqualityLevel the equality level to be checked for 
     254     *  
     255     * @return the determined equality 
     256     */ 
     257    private TaskEquality callRuleManager(ITaskInstance taskInstance1, 
     258                                         ITaskInstance taskInstance2, 
     259                                         TaskEquality  requiredEqualityLevel) 
     260    { 
     261        if (requiredEqualityLevel == null) { 
     262            return TaskEqualityRuleManager.getInstance().compare(taskInstance1, taskInstance2); 
     263        } 
     264        else if (TaskEqualityRuleManager.getInstance().areAtLeastEqual 
     265                     (taskInstance1, taskInstance2, requiredEqualityLevel)) 
     266        { 
     267            return requiredEqualityLevel; 
     268        } 
     269        else { 
     270            return TaskEquality.UNEQUAL; 
     271        } 
     272    } 
    151273} 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/TaskAndIterationComparisonRule.java

    r1190 r1294  
    1616 
    1717import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 
     18import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; 
    1819import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
     20import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
    1921 
    2022/** 
     
    3335     
    3436    /* (non-Javadoc) 
    35      * @see NodeComparisonRule#isApplicable(ITask, ITask) 
     37     * @see TaskComparisonRule#isApplicable(ITask, ITask) 
    3638     */ 
    3739    @Override 
     
    4244 
    4345    /* (non-Javadoc) 
    44      * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask) 
     46     * @see TaskComparisonRule#areLexicallyEqual(ITask, ITask) 
    4547     */ 
    4648    @Override 
     
    5153 
    5254    /* (non-Javadoc) 
    53      * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask) 
     55     * @see TaskComparisonRule#areSyntacticallyEqual(ITask, ITask) 
    5456     */ 
    5557    @Override 
     
    6062 
    6163    /* (non-Javadoc) 
    62      * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) 
     64     * @see TaskComparisonRule#areSemanticallyEqual(ITask, ITask) 
    6365     */ 
    6466    @Override 
     
    6971 
    7072    /* (non-Javadoc) 
    71      * @see NodeComparisonRule#compare(ITask, ITask) 
     73     * @see TaskComparisonRule#compare(ITask, ITask) 
    7274     */ 
    7375    @Override 
    7476    public TaskEquality compare(ITask task1, ITask task2) { 
    7577        return getEquality(task1, task2, null); 
     78    } 
     79 
     80    /* (non-Javadoc) 
     81     * @see TaskComparisonRule#isApplicable(ITaskInstance, ITaskInstance) 
     82     */ 
     83    @Override 
     84    public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2) { 
     85        return isApplicable(instance1.getTask(), instance2.getTask()); 
     86    } 
     87 
     88    /* (non-Javadoc) 
     89     * @see TaskComparisonRule#areLexicallyEqual(ITaskInstance, ITaskInstance) 
     90     */ 
     91    @Override 
     92    public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     93        TaskEquality equality = getEquality(instance1, instance2, TaskEquality.LEXICALLY_EQUAL); 
     94        return (equality != null) && (equality.isAtLeast(TaskEquality.LEXICALLY_EQUAL)); 
     95    } 
     96 
     97    /* (non-Javadoc) 
     98     * @see TaskComparisonRule#areSyntacticallyEqual(ITaskInstance, ITaskInstance) 
     99     */ 
     100    @Override 
     101    public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     102        TaskEquality equality = getEquality(instance1, instance2, TaskEquality.SYNTACTICALLY_EQUAL); 
     103        return (equality != null) && (equality.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)); 
     104    } 
     105 
     106    /* (non-Javadoc) 
     107     * @see TaskComparisonRule#areSemanticallyEqual(ITaskInstance, ITaskInstance) 
     108     */ 
     109    @Override 
     110    public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     111        TaskEquality equality = getEquality(instance1, instance2, TaskEquality.SEMANTICALLY_EQUAL); 
     112        return (equality != null) && (equality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL)); 
     113    } 
     114 
     115    /* (non-Javadoc) 
     116     * @see TaskComparisonRule#compare(ITaskInstance, ITaskInstance) 
     117     */ 
     118    @Override 
     119    public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) { 
     120        return getEquality(instance1, instance2, null); 
    76121    } 
    77122 
     
    167212        } 
    168213    } 
     214 
     215    /** 
     216     * <p> 
     217     * compares two task instances with each other checking for the provided required level of 
     218     * equality. One of the task instances must be a iteration, the other one not. If this is not 
     219     * the case, the method returns null. The returned equality level is at most lexical equality 
     220     * as the iteration can not be identical to something not being a iteration. 
     221     * </p> 
     222     *  
     223     * @param taskInstance1         the first task instance to be compared 
     224     * @param taskInstance2         the second task instance to be compared 
     225     * @param requiredEqualityLevel the equality level to be checked for 
     226     *  
     227     * @return the determined equality. 
     228     */ 
     229    private TaskEquality getEquality(ITaskInstance taskInstance1, 
     230                                     ITaskInstance taskInstance2, 
     231                                     TaskEquality  requiredEqualityLevel) 
     232    { 
     233        IIterationInstance iteration = null; 
     234        ITaskInstance task = null; 
     235         
     236        if (taskInstance1 instanceof IIterationInstance) { 
     237            if (taskInstance2 instanceof IIterationInstance) { 
     238                // the rule is not responsible for two iterations 
     239                return null; 
     240            } 
     241             
     242            iteration = (IIterationInstance) taskInstance1; 
     243            task = taskInstance2; 
     244        } 
     245        else if (taskInstance2 instanceof IIterationInstance) { 
     246            if (taskInstance1 instanceof IIterationInstance) { 
     247                // the rule is not responsible for two iterations 
     248                return null; 
     249            } 
     250             
     251            iteration = (IIterationInstance) taskInstance2; 
     252            task = taskInstance1; 
     253        } 
     254        else { 
     255            return null; 
     256        } 
     257 
     258        // now, that we found the iteration and the task, lets compare the children of the iteration 
     259        // with the task. 
     260         
     261        if (iteration.size() < 1) { 
     262            return null; 
     263        } 
     264 
     265        TaskEquality mostConcreteNodeEquality = null; 
     266         
     267        for (ITaskInstance child : iteration) { 
     268            TaskEquality taskEquality = callRuleManager(child, task, requiredEqualityLevel); 
     269             
     270            if (taskEquality != TaskEquality.UNEQUAL) { 
     271                if (mostConcreteNodeEquality == null) { 
     272                    mostConcreteNodeEquality = taskEquality; 
     273                } 
     274                else if (mostConcreteNodeEquality.isAtLeast(taskEquality)) { 
     275                    mostConcreteNodeEquality = taskEquality; 
     276                     
     277                } 
     278                 
     279                if ((requiredEqualityLevel != null) && 
     280                    (mostConcreteNodeEquality.isAtLeast(requiredEqualityLevel))) 
     281                { 
     282                    // if we found one child of the selection that is as equal as required, then 
     283                    // we can consider the selection to be sufficiently equal to the other task. 
     284                    // So we break up checking further children. 
     285                    break; 
     286                } 
     287            } 
     288        } 
     289         
     290        // although the subtask may be identical to the task, we can not return identical, as 
     291        // the selection is not identical to the task, but at most lexically equal 
     292        if (mostConcreteNodeEquality == TaskEquality.IDENTICAL) { 
     293            return TaskEquality.LEXICALLY_EQUAL; 
     294        } 
     295        else { 
     296            return mostConcreteNodeEquality; 
     297        } 
     298 
     299    } 
     300     
     301    /** 
     302     * <p> 
     303     * used to to call the task equality rule manager for the comparison of the two provided 
     304     * children. If no required equality level is provided, than the most concrete equality is 
     305     * returned. Otherwise, the required equality is returned as long as the children are equal 
     306     * on that level. 
     307     * </p>  
     308     *  
     309     * @param taskInstance1         the first task instance to be compared 
     310     * @param taskInstance2         the second task instance to be compared 
     311     * @param requiredEqualityLevel the equality level to be checked for 
     312     *  
     313     * @return the determined equality 
     314     */ 
     315    private TaskEquality callRuleManager(ITaskInstance taskInstance1, 
     316                                         ITaskInstance taskInstance2, 
     317                                         TaskEquality  requiredEqualityLevel) 
     318    { 
     319        if (requiredEqualityLevel == null) { 
     320            return TaskEqualityRuleManager.getInstance().compare(taskInstance1, taskInstance2); 
     321        } 
     322        else if (TaskEqualityRuleManager.getInstance().areAtLeastEqual 
     323                     (taskInstance1, taskInstance2, requiredEqualityLevel)) 
     324        { 
     325            return requiredEqualityLevel; 
     326        } 
     327        else { 
     328            return TaskEquality.UNEQUAL; 
     329        } 
     330    } 
    169331} 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/TaskAndSelectionComparisonRule.java

    r1190 r1294  
    1818 
    1919import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 
     20import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; 
    2021import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
     22import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
    2123 
    2224/** 
     
    3436     
    3537    /* (non-Javadoc) 
    36      * @see NodeComparisonRule#isApplicable(ITask, ITask) 
     38     * @see TaskComparisonRule#isApplicable(ITask, ITask) 
    3739     */ 
    3840    @Override 
     
    4345 
    4446    /* (non-Javadoc) 
    45      * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask) 
     47     * @see TaskComparisonRule#areLexicallyEqual(ITask, ITask) 
    4648     */ 
    4749    @Override 
     
    5254 
    5355    /* (non-Javadoc) 
    54      * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask) 
     56     * @see TaskComparisonRule#areSyntacticallyEqual(ITask, ITask) 
    5557     */ 
    5658    @Override 
     
    6163 
    6264    /* (non-Javadoc) 
    63      * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) 
     65     * @see TaskComparisonRule#areSemanticallyEqual(ITask, ITask) 
    6466     */ 
    6567    @Override 
     
    7072 
    7173    /* (non-Javadoc) 
    72      * @see NodeComparisonRule#compare(ITask, ITask) 
     74     * @see TaskComparisonRule#compare(ITask, ITask) 
    7375     */ 
    7476    @Override 
     
    7779    } 
    7880     
     81    /* (non-Javadoc) 
     82     * @see TaskComparisonRule#isApplicable(ITaskInstance, ITaskInstance) 
     83     */ 
     84    @Override 
     85    public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2) { 
     86        return isApplicable(instance1.getTask(), instance2.getTask()); 
     87    } 
     88 
     89    /* (non-Javadoc) 
     90     * @see TaskComparisonRule#areLexicallyEqual(ITaskInstance, ITaskInstance) 
     91     */ 
     92    @Override 
     93    public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     94        TaskEquality equality = getEquality(instance1, instance2, TaskEquality.LEXICALLY_EQUAL); 
     95        return (equality != null) && (equality.isAtLeast(TaskEquality.LEXICALLY_EQUAL)); 
     96    } 
     97 
     98    /* (non-Javadoc) 
     99     * @see TaskComparisonRule#areSyntacticallyEqual(ITaskInstance, ITaskInstance) 
     100     */ 
     101    @Override 
     102    public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     103        TaskEquality equality = getEquality(instance1, instance2, TaskEquality.SYNTACTICALLY_EQUAL); 
     104        return (equality != null) && (equality.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)); 
     105    } 
     106 
     107    /* (non-Javadoc) 
     108     * @see TaskComparisonRule#areSemanticallyEqual(ITaskInstance, ITaskInstance) 
     109     */ 
     110    @Override 
     111    public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     112        TaskEquality equality = getEquality(instance1, instance2, TaskEquality.SEMANTICALLY_EQUAL); 
     113        return (equality != null) && (equality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL)); 
     114    } 
     115 
     116    /* (non-Javadoc) 
     117     * @see TaskComparisonRule#compare(ITaskInstance, ITaskInstance) 
     118     */ 
     119    @Override 
     120    public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) { 
     121        return getEquality(instance1, instance2, null); 
     122    } 
     123 
    79124    /** 
    80125     * <p> 
     
    191236        } 
    192237    } 
     238 
     239    /** 
     240     * <p> 
     241     * compares two task instances with each other checking for the provided required level of 
     242     * equality. One of the task instances must be a selection, the other one not. If this is not 
     243     * the case, the method returns null. The returned equality level is at most lexical equality 
     244     * as the selection can not be identical to something not being a selection. 
     245     * </p> 
     246     *  
     247     * @param taskInstance1         the first task instance to be compared 
     248     * @param taskInstance2         the second task instance to be compared 
     249     * @param requiredEqualityLevel the equality level to be checked for 
     250     *  
     251     * @return the determined equality. 
     252     */ 
     253    private TaskEquality getEquality(ITaskInstance taskInstance1, 
     254                                     ITaskInstance taskInstance2, 
     255                                     TaskEquality  requiredEqualityLevel) 
     256    { 
     257        ISelectionInstance selection = null; 
     258        ITaskInstance task = null; 
     259         
     260        if (taskInstance1 instanceof ISelectionInstance) { 
     261            if (taskInstance2 instanceof ISelectionInstance) { 
     262                // the rule is not responsible for two selections 
     263                return null; 
     264            } 
     265             
     266            selection = (ISelectionInstance) taskInstance1; 
     267            task = taskInstance2; 
     268        } 
     269        else if (taskInstance2 instanceof ISelectionInstance) { 
     270            if (taskInstance1 instanceof ISelectionInstance) { 
     271                // the rule is not responsible for two selections 
     272                return null; 
     273            } 
     274             
     275            selection = (ISelectionInstance) taskInstance2; 
     276            task = taskInstance1; 
     277        } 
     278        else { 
     279            return null; 
     280        } 
     281 
     282        // now, that we found the selection and the task, lets compare the child of the selection 
     283        // with the task. 
     284        ITaskInstance child = selection.getChild(); 
     285         
     286        if (child == null) { 
     287            return null; 
     288        } 
     289 
     290        TaskEquality taskEquality = callRuleManager(child, task, requiredEqualityLevel); 
     291 
     292        // although the subtask may be identical to the task, we can not return identical, as 
     293        // the selection is not identical to the task, but at most lexically equal 
     294        if (taskEquality == TaskEquality.IDENTICAL) { 
     295            return TaskEquality.LEXICALLY_EQUAL; 
     296        } 
     297        else { 
     298            return taskEquality; 
     299        } 
     300 
     301    } 
     302     
     303    /** 
     304     * <p> 
     305     * used to to call the task equality rule manager for the comparison of the two provided 
     306     * children. If no required equality level is provided, than the most concrete equality is 
     307     * returned. Otherwise, the required equality is returned as long as the children are equal 
     308     * on that level. 
     309     * </p>  
     310     *  
     311     * @param taskInstance1         the first task instance to be compared 
     312     * @param taskInstance2         the second task instance to be compared 
     313     * @param requiredEqualityLevel the equality level to be checked for 
     314     *  
     315     * @return the determined equality 
     316     */ 
     317    private TaskEquality callRuleManager(ITaskInstance taskInstance1, 
     318                                         ITaskInstance taskInstance2, 
     319                                         TaskEquality  requiredEqualityLevel) 
     320    { 
     321        if (requiredEqualityLevel == null) { 
     322            return TaskEqualityRuleManager.getInstance().compare(taskInstance1, taskInstance2); 
     323        } 
     324        else if (TaskEqualityRuleManager.getInstance().areAtLeastEqual 
     325                     (taskInstance1, taskInstance2, requiredEqualityLevel)) 
     326        { 
     327            return requiredEqualityLevel; 
     328        } 
     329        else { 
     330            return TaskEquality.UNEQUAL; 
     331        } 
     332    } 
    193333} 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/TaskComparisonRule.java

    r1146 r1294  
    1616 
    1717import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
     18import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
    1819 
    1920/** 
    2021 * <p> 
    21  * A task comparison rule is used by the {@link TaskEqualityRuleManager} to compare tasks with 
    22  * each other. It provides several methods to be called for a comparison. 
     22 * A task comparison rule is used by the {@link TaskEqualityRuleManager} to compare tasks and 
     23 * task instances with each other. It provides several methods to be called for a comparison. 
    2324 * </p> 
    2425 *  
     
    9091    public TaskEquality compare(ITask task1, ITask task2); 
    9192 
     93    /** 
     94     * <p> 
     95     * checks if the rule is applicable for comparing the two provided task instances 
     96     * </p> 
     97     *  
     98     * @param instance1 the first task instance to compare 
     99     * @param instance2 the second task instance to compare 
     100     *  
     101     * @return true, if the rule is applicable, false else 
     102     */ 
     103    public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2); 
     104 
     105    /** 
     106     * <p> 
     107     * checks, if the provided task instances are lexically equal 
     108     * </p> 
     109     *  
     110     * @param instance1 the first task instance to compare 
     111     * @param instance2 the second task instance to compare 
     112     *  
     113     * @return true, if the tasks are equal, false else 
     114     */ 
     115    public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2); 
     116 
     117    /** 
     118     * <p> 
     119     * checks, if the provided task instances are syntactically equal 
     120     * </p> 
     121     *  
     122     * @param instance1 the first task instance to compare 
     123     * @param instance2 the second task instance to compare 
     124     *  
     125     * @return true, if the tasks are equal, false else 
     126     */ 
     127    public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2); 
     128 
     129    /** 
     130     * <p> 
     131     * checks, if the provided task instances are semantically equal 
     132     * </p> 
     133     *  
     134     * @param instance1 the first task instance to compare 
     135     * @param instance2 the second task instance to compare 
     136     *  
     137     * @return true, if the tasks are equal, false else 
     138     */ 
     139    public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2); 
     140 
     141    /** 
     142     * <p> 
     143     * compares two task instances with each other. The result of the method is either a task 
     144     * instance equality or null. If it is null, it means, that the rule is not able to correctly 
     145     * compare the two given task instances 
     146     * </p> 
     147     *  
     148     * @param instance1 the first task instance to compare 
     149     * @param instance2 the second task instance to compare 
     150     *  
     151     * @return as described 
     152     */ 
     153    public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2); 
     154 
    92155} 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/TaskEqualityRuleManager.java

    r1190 r1294  
    1919 
    2020import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
     21import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
    2122 
    2223/** 
    2324 * <p> 
    24  * The task equality rule manager is capable of comparing tasks based on its internal list 
    25  * of comparison rules. These rules are asked for comparing the two provided tasks. If a rule 
    26  * returns a task equality other than null, this equality is returned. Otherwise the next rule 
    27  * is asked. 
     25 * The task equality rule manager is capable of comparing tasks and task instances based on its 
     26 * internal list of comparison rules. These rules are asked for comparing the two provided tasks or 
     27 * task instance. If a rule returns a task equality other than null, this equality is returned. 
     28 * Otherwise the next rule is asked. 
    2829 * </p> 
    2930 *  
    30  * @version $Revision: $ $Date: 19.02.2012$ 
    31  * @author 2012, last modified by $Author: patrick$ 
     31 * @author Patrick Harms 
    3232 */ 
    3333public class TaskEqualityRuleManager { 
     
    269269    } 
    270270 
     271    /** 
     272     * <p> 
     273     * this method performs a comparison of the two provided task instances. It iterates its 
     274     * internal comparison rules. If the first rule returns a task instance equality other than 
     275     * null, this equality is returned. Otherwise the next rule is tried. If no rule returns an 
     276     * equality <code>TaskEquality.UNEQUAL</code> is returned. 
     277     * </p> 
     278     *  
     279     * @param instance1 the first task instance to be compared 
     280     * @param instance2 the second task instance to be compared 
     281     *  
     282     * @return as described 
     283     *  
     284     * @throws IllegalStateException in the case, the {@link #init()} method was not called on the 
     285     *                               manager before a call to this method. 
     286     */ 
     287    public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) 
     288        throws IllegalStateException 
     289    { 
     290        if (mRuleIndex == null) { 
     291            throw new IllegalStateException("not initialized"); 
     292        } 
     293         
     294        // LOG.info("checking for equality of " + instance1 + " and " + instance2); 
     295        TaskEquality instanceEquality = null; 
     296 
     297        for (TaskComparisonRule rule : mRuleIndex) { 
     298            if (rule.isApplicable(instance1, instance2)) { 
     299                instanceEquality = rule.compare(instance1, instance2); 
     300                if (instanceEquality != null) { 
     301                    // LOG.warning("used rule " + rule + " for equality check"); 
     302                    return instanceEquality; 
     303                } 
     304            } 
     305        } 
     306 
     307        // LOG.warning("no rule could be applied --> handling tasks as unequal"); 
     308 
     309        return TaskEquality.UNEQUAL; 
     310    } 
     311 
     312    /** 
     313     * <p> 
     314     * this method compares two task instances with respect to the given equality level and returns 
     315     * true, if this level is given. 
     316     * </p> 
     317     *  
     318     * @param instance1     the first task instance to be compared 
     319     * @param instance2     the second task instance to be compared 
     320     * @param equalityLevel the level of equality to be checked for 
     321     *  
     322     * @return as described 
     323     *  
     324     * @throws IllegalStateException in the case, the {@link #init()} method was not called on the 
     325     *                               manager before a call to this method. 
     326     */ 
     327    public boolean areAtLeastEqual(ITaskInstance        instance1, 
     328                                   ITaskInstance        instance2, 
     329                                   TaskEquality equalityLevel) 
     330    { 
     331        if (equalityLevel == null) { 
     332            throw new IllegalArgumentException("required equality level must not be null"); 
     333        } 
     334         
     335        switch (equalityLevel) { 
     336            case IDENTICAL: 
     337                return areIdentical(instance1, instance2); 
     338            case LEXICALLY_EQUAL: 
     339                return areLexicallyEqual(instance1, instance2); 
     340            case SYNTACTICALLY_EQUAL: 
     341                return areSyntacticallyEqual(instance1, instance2); 
     342            case SEMANTICALLY_EQUAL: 
     343                return areSemanticallyEqual(instance1, instance2); 
     344            case UNEQUAL: 
     345                return !areSemanticallyEqual(instance1, instance2); 
     346            default: 
     347                throw new IllegalArgumentException("unknown required equality: " + equalityLevel); 
     348        } 
     349    } 
     350 
     351    /** 
     352     * <p> 
     353     * this method checks if the two given task instances are identical. For this, it iterates its 
     354     * internal comparison rules. If the first rule returns true, than this method returns true 
     355     * as well. If no rule returns true, this method returns false. 
     356     * </p> 
     357     *  
     358     * @param instance1 the first task instance to be compared 
     359     * @param instance2 the second task instance to be compared 
     360     *  
     361     * @return as described 
     362     *  
     363     * @throws IllegalStateException in the case, the {@link #init()} method was not called on the 
     364     *                               manager before a call to this method. 
     365     */ 
     366    public boolean areIdentical(ITaskInstance instance1, ITaskInstance instance2) { 
     367        if (mRuleIndex == null) { 
     368            throw new IllegalStateException("not initialized"); 
     369        } 
     370         
     371        for (TaskComparisonRule rule : mRuleIndex) { 
     372            if (rule.isApplicable(instance1, instance2) && 
     373                rule.areLexicallyEqual(instance1, instance2)) 
     374            { 
     375                return true; 
     376            } 
     377        } 
     378 
     379        return false; 
     380    } 
     381 
     382    /** 
     383     * <p> 
     384     * this method checks if the two given task instances are lexically equal. For this, it 
     385     * iterates its internal comparison rules. If the first rule returns true, than this method 
     386     * returns true, as well. If no rule returns true, this method returns false. 
     387     * </p> 
     388     *  
     389     * @param instance1 the first task instance to be compared 
     390     * @param instance2 the second task instance to be compared 
     391     *  
     392     * @return as described 
     393     *  
     394     * @throws IllegalStateException in the case, the {@link #init()} method was not called on the 
     395     *                               manager before a call to this method. 
     396     */ 
     397    public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     398        if (mRuleIndex == null) { 
     399            throw new IllegalStateException("not initialized"); 
     400        } 
     401         
     402        for (TaskComparisonRule rule : mRuleIndex) { 
     403            if (rule.isApplicable(instance1, instance2) && 
     404                rule.areLexicallyEqual(instance1, instance2)) 
     405            { 
     406                return true; 
     407            } 
     408        } 
     409 
     410        return false; 
     411    } 
     412 
     413    /** 
     414     * <p> 
     415     * this method checks if the two given task instances are syntactically equal. For this, it 
     416     * iterates its internal comparison rules. If the first rule returns true, than this method 
     417     * returns true, as well. If no rule returns true, this method returns false. 
     418     * </p> 
     419     *  
     420     * @param instance1 the first task instance to be compared 
     421     * @param instance2 the second task instance to be compared 
     422     *  
     423     * @return as described 
     424     *  
     425     * @throws IllegalStateException in the case, the {@link #init()} method was not called on the 
     426     *                               manager before a call to this method. 
     427     */ 
     428    public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     429        if (mRuleIndex == null) { 
     430            throw new IllegalStateException("not initialized"); 
     431        } 
     432         
     433        for (TaskComparisonRule rule : mRuleIndex) { 
     434            if (rule.isApplicable(instance1, instance2) && 
     435                rule.areSyntacticallyEqual(instance1, instance2)) 
     436            { 
     437                return true; 
     438            } 
     439        } 
     440 
     441        return false; 
     442    } 
     443 
     444    /** 
     445     * <p> 
     446     * this method checks if the two given task instances are semantically equal. For this, it 
     447     * iterates its internal comparison rules. If the first rule returns true, than this method 
     448     * returns true, as well. If no rule returns true, this method returns false. 
     449     * </p> 
     450     *  
     451     * @param instance1 the first task instance to be compared 
     452     * @param instance2 the second task instance to be compared 
     453     *  
     454     * @return as described 
     455     *  
     456     * @throws IllegalStateException in the case, the {@link #init()} method was not called on the 
     457     *                               manager before a call to this method. 
     458     */ 
     459    public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     460        if (mRuleIndex == null) { 
     461            throw new IllegalStateException("not initialized"); 
     462        } 
     463         
     464        for (TaskComparisonRule rule : mRuleIndex) { 
     465            if (rule.isApplicable(instance1, instance2) && 
     466                rule.areSemanticallyEqual(instance1, instance2)) 
     467            { 
     468                 return true; 
     469            } 
     470        } 
     471 
     472        return false; 
     473    } 
     474 
    271475} 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/TaskIdentityRule.java

    r1146 r1294  
    1616 
    1717import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
     18import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
    1819 
    1920/** 
    2021 * <p> 
    2122 * This comparison rule returns <code>TaskEquality.IDENTICAL</code> if the comparison of the two 
    22  * tasks using the <code>==</code> operator or the <code>equals</code> method return true. 
    23  * Else it returns null to denote, that it can not compare the tasks. 
     23 * tasks using the <code>==</code> operator returns true. Else it returns null to denote, that 
     24 * it can not compare the tasks. 
    2425 * </p> 
    2526 *  
     
    3031 
    3132    /* (non-Javadoc) 
    32      * @see NodeComparisonRule#isApplicable(ITask, ITask) 
     33     * @see TaskComparisonRule#isApplicable(ITask, ITask) 
    3334     */ 
    3435    @Override 
     
    3839 
    3940    /* (non-Javadoc) 
    40      * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask) 
     41     * @see TaskComparisonRule#areLexicallyEqual(ITask, ITask) 
    4142     */ 
    4243    @Override 
     
    4647 
    4748    /* (non-Javadoc) 
    48      * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask) 
     49     * @see TaskComparisonRule#areSyntacticallyEqual(ITask, ITask) 
    4950     */ 
    5051    @Override 
     
    5455 
    5556    /* (non-Javadoc) 
    56      * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) 
     57     * @see TaskComparisonRule#areSemanticallyEqual(ITask, ITask) 
    5758     */ 
    5859    @Override 
     
    6263 
    6364    /* (non-Javadoc) 
    64      * @see NodeComparisonRule#compare(ITask, ITask) 
     65     * @see TaskComparisonRule#compare(ITask, ITask) 
    6566     */ 
    6667    @Override 
     
    7475    } 
    7576 
     77    /* (non-Javadoc) 
     78     * @see TaskComparisonRule#isApplicable(ITaskInstance, ITaskInstance) 
     79     */ 
     80    @Override 
     81    public boolean isApplicable(ITaskInstance instance1, ITaskInstance instance2) { 
     82        return (instance1.getTask() == instance2.getTask()); 
     83    } 
     84 
     85    /* (non-Javadoc) 
     86     * @see TaskComparisonRule#areLexicallyEqual(ITaskInstance, ITaskInstance) 
     87     */ 
     88    @Override 
     89    public boolean areLexicallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     90        return (instance1.getTask() == instance2.getTask()); 
     91    } 
     92 
     93    /* (non-Javadoc) 
     94     * @see TaskComparisonRule#areSyntacticallyEqual(ITaskInstance, ITaskInstance) 
     95     */ 
     96    @Override 
     97    public boolean areSyntacticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     98        return (instance1.getTask() == instance2.getTask()); 
     99    } 
     100 
     101    /* (non-Javadoc) 
     102     * @see TaskComparisonRule#areSemanticallyEqual(ITaskInstance, ITaskInstance) 
     103     */ 
     104    @Override 
     105    public boolean areSemanticallyEqual(ITaskInstance instance1, ITaskInstance instance2) { 
     106        return (instance1.getTask() == instance2.getTask()); 
     107    } 
     108 
     109    /* (non-Javadoc) 
     110     * @see TaskComparisonRule#compare(ITaskInstance, ITaskInstance) 
     111     */ 
     112    @Override 
     113    public TaskEquality compare(ITaskInstance instance1, ITaskInstance instance2) { 
     114        if (isApplicable(instance1, instance2)) { 
     115            return TaskEquality.IDENTICAL; 
     116        } 
     117        else { 
     118            return null; 
     119        } 
     120    } 
     121 
    76122} 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/ITaskInstanceScopeRule.java

    r1219 r1294  
    1515package de.ugoe.cs.autoquest.tasktrees.temporalrelation; 
    1616 
    17 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; 
     17import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
    1818 
    1919/** 
    2020 * <p> 
    21  * a task instance list scope rule is able to detected temporal relationships between a list of task 
    22  * instances provided to the {@link #apply(ITaskInstanceList)} method. A rule creates temporal 
     21 * a task instance scope rule is able to detected temporal relationships between the children of 
     22 * a task instance provided to the {@link #apply(ITaskInstance)} method. A rule creates temporal 
    2323 * relationships between the task instances, i.e. substructures in the task tree, if 
    2424 * it detects a temporal relationship and instantiates the temporal relationships accordingly. 
     
    2727 * @author Patrick Harms 
    2828 */ 
    29 interface ITaskInstanceListScopeRule extends ITemporalRelationshipRule { 
     29interface ITaskInstanceScopeRule extends ITemporalRelationshipRule { 
    3030 
    3131  /** 
    3232   * <p> 
    33    * applies the rule to the given task instance list. The returned rule application result is null, 
     33   * applies the rule to the given task instance. The returned rule application result is null, 
    3434   * if the rule can not be applied, i.e. it does not detect a temporal relationship. It returns a 
    3535   * rule application result with a status {@link RuleApplicationStatus#RULE_APPLICATION_FINISHED} 
     
    3737   * </p> 
    3838   *  
    39    * @param taskInstances the list of task instances to apply the rule on 
     39   * @param taskInstance the task instances to apply the rule on 
    4040   *                     
    4141   * @return the rule application result as described. 
    4242   */ 
    43   RuleApplicationResult apply(ITaskInstanceList taskInstances); 
     43  RuleApplicationResult apply(ITaskInstance taskInstance); 
    4444   
    4545} 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/ITemporalRelationshipRule.java

    r1284 r1294  
    1919 * a temporal relationship rule is the main interface for all rules applied for generating 
    2020 * temporal relationships in a task tree. It is just a marker interface. More important are the 
    21  * sub interfaces {@link ISessionScopeRule} and {@link ITaskInstanceListScopeRule}. 
     21 * sub interfaces {@link ISessionScopeRule} and {@link ITaskInstanceScopeRule}. 
    2222 * </p> 
    2323 *  
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/RuleUtils.java

    r1281 r1294  
    1515package de.ugoe.cs.autoquest.tasktrees.temporalrelation; 
    1616 
    17 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
     17import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
     18import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance; 
    1819import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; 
    1920import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
     
    5556                                               int               startIndex, 
    5657                                               int               endIndex, 
    57                                                ITask             model, 
     58                                               ISequence         model, 
    5859                                               ITaskFactory      taskFactory, 
    5960                                               ITaskBuilder      taskBuilder) 
    6061    { 
    61         ITaskInstance subsequence = taskFactory.createNewTaskInstance(model); 
     62        ISequenceInstance subsequence = taskFactory.createNewTaskInstance(model); 
    6263 
    6364        for (int i = startIndex; i <= endIndex; i++) { 
     
    8384     * @return the replacement for the range 
    8485     */ 
    85     static ITaskInstance createNewSubSequenceInRange(ITaskInstanceList parent, 
    86                                                      int               startIndex, 
    87                                                      int               endIndex, 
    88                                                      ITask             model, 
    89                                                      ITaskFactory      taskFactory, 
    90                                                      ITaskBuilder      taskBuilder) 
     86    static ISequenceInstance createNewSubSequenceInRange(ITaskInstanceList parent, 
     87                                                         int               startIndex, 
     88                                                         int               endIndex, 
     89                                                         ISequence         model, 
     90                                                         ITaskFactory      taskFactory, 
     91                                                         ITaskBuilder      taskBuilder) 
    9192    { 
    92         ITaskInstance subsequence = taskFactory.createNewTaskInstance(model); 
     93        ISequenceInstance subsequence = taskFactory.createNewTaskInstance(model); 
    9394 
    9495        for (int i = startIndex; i <= endIndex; i++) { 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRule.java

    r1287 r1294  
    2626import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality; 
    2727import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 
     28import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; 
    2829import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 
     30import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; 
    2931import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
     32import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance; 
    3033import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
    3134import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; 
     
    159162        SymbolMap<ITaskInstance, ITask> uniqueTasks = 
    160163            preparationTaskHandlingStrategy.createSymbolMap(); 
    161         TaskComparator comparator = preparationTaskHandlingStrategy.getTaskComparator(); 
     164        TaskInstanceComparator comparator = preparationTaskHandlingStrategy.getTaskComparator(); 
    162165         
    163166        int unifiedTasks = 0; 
     
    235238    { 
    236239        Map<ITask, IIteration> iterations = new HashMap<ITask, IIteration>(); 
    237         Map<IIteration, List<ITaskInstance>> iterationInstances = 
    238                 new HashMap<IIteration, List<ITaskInstance>>(); 
     240        Map<IIteration, List<IIterationInstance>> iterationInstances = 
     241                new HashMap<IIteration, List<IIterationInstance>>(); 
    239242             
    240243        for (ITask iteratedTask : iteratedTasks) { 
    241244            IIteration iteration = taskFactory.createNewIteration(); 
    242245            iterations.put(iteratedTask, iteration); 
    243             iterationInstances.put(iteration, new LinkedList<ITaskInstance>()); 
    244         } 
    245          
    246         ITaskInstance iterationInstance = null; 
     246            iterationInstances.put(iteration, new LinkedList<IIterationInstance>()); 
     247        } 
     248         
     249        IIterationInstance iterationInstance = null; 
    247250         
    248251        for (IUserSession session : sessions) { 
     
    275278        } 
    276279         
    277         for (Map.Entry<IIteration, List<ITaskInstance>> entry : iterationInstances.entrySet()) { 
     280        for (Map.Entry<IIteration, List<IIterationInstance>> entry : iterationInstances.entrySet()) 
     281        { 
    278282            harmonizeIterationInstancesModel(entry.getKey(), entry.getValue()); 
    279283        } 
     
    283287     * 
    284288     */ 
    285     private void harmonizeIterationInstancesModel(IIteration          iteration, 
    286                                                   List<ITaskInstance> iterationInstances) 
     289    private void harmonizeIterationInstancesModel(IIteration               iteration, 
     290                                                  List<IIterationInstance> iterationInstances) 
    287291    { 
    288292        List<ITask> iteratedTaskVariants = new LinkedList<ITask>(); 
    289         TaskComparator comparator = preparationTaskHandlingStrategy.getTaskComparator(); 
     293        TaskInstanceComparator comparator = preparationTaskHandlingStrategy.getTaskComparator(); 
    290294         
    291295        // merge the lexically different variants of iterated task to a unique list  
    292         for (ITaskInstance iterationInstance : iterationInstances) { 
     296        for (IIterationInstance iterationInstance : iterationInstances) { 
    293297            for (ITaskInstance executionVariant : iterationInstance) { 
    294298                ITask candidate = executionVariant.getTask(); 
     
    323327            taskBuilder.setMarkedTask(iteration, selection); 
    324328             
    325             for (ITaskInstance instance : iterationInstances) { 
     329            for (IIterationInstance instance : iterationInstances) { 
    326330                for (int i = 0; i < instance.size(); i++) { 
    327                     ITaskInstance selectionInstance = taskFactory.createNewTaskInstance(selection); 
    328                     taskBuilder.addChild(selectionInstance, instance.get(i)); 
     331                    ISelectionInstance selectionInstance = 
     332                        taskFactory.createNewTaskInstance(selection); 
     333                    taskBuilder.setChild(selectionInstance, instance.get(i)); 
    329334                    taskBuilder.setTaskInstance(instance, i, selectionInstance); 
    330335                } 
     
    490495                Console.traceln(Level.FINEST, "replacing " + sequence.getId() + ": " + task); 
    491496 
    492                 List<ITaskInstance> sequenceInstances = 
     497                List<ISequenceInstance> sequenceInstances = 
    493498                    replaceTaskOccurrences(task, appData.getSessions(), sequence); 
    494499                 
     
    510515     * 
    511516     */ 
    512     private void harmonizeSequenceInstancesModel(ISequence           sequence, 
    513                                                  List<ITaskInstance> sequenceInstances, 
    514                                                  int                 sequenceLength) 
     517    private void harmonizeSequenceInstancesModel(ISequence               sequence, 
     518                                                 List<ISequenceInstance> sequenceInstances, 
     519                                                 int                     sequenceLength) 
    515520    { 
    516         TaskComparator comparator = preparationTaskHandlingStrategy.getTaskComparator(); 
     521        TaskInstanceComparator comparator = preparationTaskHandlingStrategy.getTaskComparator(); 
    517522         
    518523        // ensure for each subtask that lexically different variants are preserved 
     
    520525            List<ITask> subTaskVariants = new LinkedList<ITask>(); 
    521526             
    522             for (ITaskInstance sequenceInstance : sequenceInstances) { 
     527            for (ISequenceInstance sequenceInstance : sequenceInstances) { 
    523528                ITask candidate = sequenceInstance.get(subTaskIndex).getTask(); 
    524529                 
     
    556561                taskBuilder.addChild(sequence, selection); 
    557562                 
    558                 for (ITaskInstance instance : sequenceInstances) { 
    559                     ITaskInstance selectionInstance = 
     563                for (ISequenceInstance instance : sequenceInstances) { 
     564                    ISelectionInstance selectionInstance = 
    560565                        taskFactory.createNewTaskInstance(selection); 
    561                     taskBuilder.addChild(selectionInstance, instance.get(subTaskIndex)); 
     566                    taskBuilder.setChild(selectionInstance, instance.get(subTaskIndex)); 
    562567                    taskBuilder.setTaskInstance(instance, subTaskIndex, selectionInstance); 
    563568                } 
     
    572577     * @param tree 
    573578     */ 
    574     private List<ITaskInstance> replaceTaskOccurrences(List<ITaskInstance> task, 
    575                                                        List<IUserSession>  sessions, 
    576                                                        ISequence           temporalTaskModel) 
     579    private List<ISequenceInstance> replaceTaskOccurrences(List<ITaskInstance> task, 
     580                                                           List<IUserSession>  sessions, 
     581                                                           ISequence           temporalTaskModel) 
    577582    { 
    578         List<ITaskInstance> sequenceInstances = new LinkedList<ITaskInstance>(); 
     583        List<ISequenceInstance> sequenceInstances = new LinkedList<ISequenceInstance>(); 
    579584         
    580585        for (IUserSession session : sessions) { 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskHandlingStrategy.java

    r1285 r1294  
    4242     *  
    4343     */ 
    44     private TaskComparator comparator; 
     44    private TaskInstanceComparator comparator; 
    4545 
    4646    /** 
     
    5858        } 
    5959        else { 
    60             comparator = new TaskComparator(this.consideredEquality); 
     60            comparator = new TaskInstanceComparator(this.consideredEquality); 
    6161        } 
    6262    } 
     
    7777     * @return 
    7878     */ 
    79     public TaskComparator getTaskComparator() { 
     79    public TaskInstanceComparator getTaskComparator() { 
    8080        return comparator; 
    8181    } 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskIdentityComparator.java

    r1285 r1294  
    2121 * TODO comment 
    2222 */ 
    23 class TaskIdentityComparator extends TaskComparator { 
     23class TaskIdentityComparator extends TaskInstanceComparator { 
    2424 
    2525    /**  */ 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskInstanceComparator.java

    r1285 r1294  
    2828 * TODO comment 
    2929 */ 
    30 class TaskComparator implements SymbolComparator<ITaskInstance> { 
     30class TaskInstanceComparator implements SymbolComparator<ITaskInstance> { 
    3131     
    3232    /**  */ 
     
    5454     * 
    5555     */ 
    56     public TaskComparator(TaskEquality minimalNodeEquality) { 
     56    public TaskInstanceComparator(TaskEquality minimalNodeEquality) { 
    5757        this.minimalNodeEquality = minimalNodeEquality; 
    5858        init(); 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskSymbolBucketedMap.java

    r1285 r1294  
    2727 
    2828import de.ugoe.cs.autoquest.eventcore.IEventType; 
    29 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 
    30 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 
    31 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 
    32 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
    33 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
     29import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; 
     30import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; 
     31import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; 
     32import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance; 
    3433import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
    3534import de.ugoe.cs.autoquest.usageprofiles.SymbolMap; 
     
    8180     * </p> 
    8281     */ 
    83     private TaskComparator comparator; 
     82    private TaskInstanceComparator comparator; 
    8483 
    8584    /** 
     
    117116     * @throws IllegalArgumentException if the provided comparator is null 
    118117     */ 
    119     public TaskSymbolBucketedMap(TaskComparator comparator) { 
     118    public TaskSymbolBucketedMap(TaskInstanceComparator comparator) { 
    120119        if (comparator == null) { 
    121120            throw new IllegalArgumentException("comparator must not be null"); 
     
    400399        // other = hashCode of name of event type 
    401400         
    402         ITask task = taskInstance.getTask(); 
    403          
    404         if (task instanceof IEventTask) { 
     401        if (taskInstance instanceof IEventTaskInstance) { 
    405402            // event tasks are most likely equal to those of the event type with the same name, 
    406403            // Afterwards, they may be equal to iterations, optionals, other event tasks, 
    407404            // selections, and finally the rest. 
    408             IEventType eventType = ((IEventTask) task).getEventType(); 
     405            IEventType eventType = ((IEventTaskInstance) taskInstance).getEvent().getType(); 
    409406            return new int[] { eventType.getName().hashCode(), 2, 3, 4, 1 };                        
    410407        } 
    411         else if (task instanceof ISequence) { 
     408        else if (taskInstance instanceof ISequenceInstance) { 
    412409            return new int[] { 0, 2, 3, 1 };                        
    413410        } 
    414         else if (task instanceof ISelection) { 
     411        else if (taskInstance instanceof ISelectionInstance) { 
    415412            return new int[] { 1, 4, 2, 3 };                        
    416413        } 
    417         else if (task instanceof IIteration) { 
     414        else if (taskInstance instanceof IIterationInstance) { 
    418415            return new int[] { 2, 1, 4 };                        
    419416        } 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TemporalRelationshipRuleManager.java

    r1189 r1294  
    2626import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; 
    2727import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
    28 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; 
    2928import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 
    3029import de.ugoe.cs.util.console.Console; 
     
    3837 * between tasks which are not only a major sequence. I.e. through the application of the 
    3938 * rules iterations and selections of tasks are detected. Which kind of temporal relations 
    40  * between tasks are detected depends on the {@link ITaskInstanceListScopeRule}s known to 
     39 * between tasks are detected depends on the {@link ITaskInstanceScopeRule}s known to 
    4140 * this class. 
    4241 * </p> 
    43  * <p>The class holds references to the appropriate {@link ITaskInstanceListScopeRule}s and calls 
    44  * their {@link ITaskInstanceListScopeRule#apply(ITask, ITaskBuilder, ITaskFactory, boolean)} 
     42 * <p>The class holds references to the appropriate {@link ITaskInstanceScopeRule}s and calls 
     43 * their {@link ITaskInstanceScopeRule#apply(ITask, ITaskBuilder, ITaskFactory, boolean)} 
    4544 * method for each task in the task tree it is needed for. The general behavior of this class is 
    4645 * the following: 
     
    5655 *   <li> 
    5756 *     the class iterates its internal list of rules and calls their 
    58  *     {@link ITaskInstanceListScopeRule#apply(ITask, ITaskBuilder, ITaskFactory, boolean)} 
     57 *     {@link ITaskInstanceScopeRule#apply(ITask, ITaskBuilder, ITaskFactory, boolean)} 
    5958 *     method. 
    6059 *   </li> 
     
    115114     * </p> 
    116115     */ 
    117     private ITaskInstanceListScopeRule[] taskScopeRules; 
     116    private ITaskInstanceScopeRule[] taskScopeRules; 
    118117 
    119118    /** 
     
    166165        //treeScopeRules.add(new DefaultGuiElementSequenceDetectionRule(frameFilter)); 
    167166 
    168         taskScopeRules = new ITaskInstanceListScopeRule[] { 
     167        taskScopeRules = new ITaskInstanceScopeRule[] { 
    169168            //new SequenceOnGuiElementDetectionRule(taskFactory, taskTreeBuilder), 
    170169            //new EventSequenceOnSameTargetDetectionRule(taskFactory, taskTreeBuilder), 
     
    262261     *                     on the recursion depth of calling this method. 
    263262     */ 
    264     private int applyRules(ITaskInstanceListScopeRule[] rules, 
    265                            ITaskInstanceList            taskInstances, 
     263    private int applyRules(ITaskInstanceScopeRule[] rules, 
     264                           ITaskInstance                taskInstance, 
    266265                           String                       logIndent) 
    267266    { 
    268         Console.traceln(Level.FINER, logIndent + "applying rules for " + taskInstances.size() + 
    269                         " task instances"); 
     267        Console.traceln(Level.FINER, logIndent + "applying rules on " + taskInstance); 
    270268 
    271269        int noOfRuleApplications = 0; 
    272270 
    273         for (ITaskInstanceListScopeRule rule : rules) { 
     271        for (ITaskInstanceScopeRule rule : rules) { 
    274272            RuleApplicationResult result; 
    275273            do { 
    276274                Console.traceln 
    277                     (Level.FINER, logIndent + "trying rule " + rule + " on " + taskInstances); 
    278                 result = rule.apply(taskInstances); 
     275                    (Level.FINER, logIndent + "trying rule " + rule + " on " + taskInstance); 
     276                result = rule.apply(taskInstance); 
    279277 
    280278                if ((result != null) && 
     
    282280                { 
    283281                    Console.traceln 
    284                         (Level.FINE, logIndent + "applied rule " + rule + " on " + taskInstances); 
     282                        (Level.FINE, logIndent + "applied rule " + rule + " on " + taskInstance); 
    285283                    noOfRuleApplications++; 
    286284                     
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeifc/IEventTask.java

    r1180 r1294  
    1515package de.ugoe.cs.autoquest.tasktrees.treeifc; 
    1616 
    17 import de.ugoe.cs.autoquest.eventcore.IEventTarget; 
    18 import de.ugoe.cs.autoquest.eventcore.IEventType; 
    19  
    2017/** 
    2118 * <p> 
    2219 * Event tasks represent single events. They have no children and are therefore the leaf nodes of 
    23  * a task model. They provide information about the event they represent. This includes the event 
    24  * type and the target. 
     20 * a task model. They provide information about the event they represent as a String description. 
     21 * They do not refer to events, as they may represented several semantically equal but lexically 
     22 * different events. Their description carries as much information as required to show the 
     23 * level of distinction. 
    2524 * </p> 
    2625 *  
     
    2928public interface IEventTask extends ITask { 
    3029     
    31     /** 
    32      * <p> 
    33      * return the type of the event represented by this task 
    34      * </p> 
    35      *  
    36      * @return as described 
    37      */ 
    38     public IEventType getEventType(); 
    39  
    40     /** 
    41      * <p> 
    42      * return the target of the event represented by this task 
    43      * </p> 
    44      *  
    45      * @return as described 
    46      */ 
    47     public IEventTarget getEventTarget(); 
    48  
    4930    /** 
    5031     * <p> 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeifc/ITask.java

    r1180 r1294  
    1616 
    1717import java.io.Serializable; 
     18import java.util.Collection; 
    1819 
    1920/** 
     
    4950     */ 
    5051    public String getDescription(); 
     52 
     53    /** 
     54     * <p> 
     55     * returns a collection of all observed instances of this task 
     56     * </p> 
     57     *  
     58     * @return as described 
     59     */ 
     60    public Collection<ITaskInstance> getInstances(); 
    5161 
    5262    /** 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeifc/ITaskBuilder.java

    r1197 r1294  
    2626    /** 
    2727     * <p> 
    28      * adds a child to a task instance. May ensure, that the child is a valid child considering 
     28     * adds a child to a sequence instance. May ensure, that the child is a valid child considering 
    2929     * the task model of the parent. In that case, an IllegalArgumentException is thrown. 
    3030     * </p> 
    3131     *  
    32      * @param taskInstance the instance of add the child to 
    33      * @param child        the child to be added 
    34      *  
    35      * @throws IllegalArgumentException as described 
    36      */ 
    37     void addChild(ITaskInstance taskInstance, ITaskInstance child) throws IllegalArgumentException; 
     32     * @param instance the instance of add the child to 
     33     * @param child    the child to be added 
     34     *  
     35     * @throws IllegalArgumentException as described 
     36     */ 
     37    void addChild(ISequenceInstance instance, ITaskInstance child) throws IllegalArgumentException; 
     38 
     39    /** 
     40     * <p> 
     41     * adds a child to an iteration instance. May ensure, that the child is a valid child 
     42     * considering the task model of the parent. In that case, an IllegalArgumentException is 
     43     * thrown. 
     44     * </p> 
     45     *  
     46     * @param instance the instance of add the child to 
     47     * @param child    the child to be added 
     48     *  
     49     * @throws IllegalArgumentException as described 
     50     */ 
     51    void addChild(IIterationInstance instance, ITaskInstance child) throws IllegalArgumentException; 
     52 
     53    /** 
     54     * <p> 
     55     * sets the child of a selection instance. May ensure, that the child is a valid child 
     56     * considering the task model of the parent. In that case, an IllegalArgumentException is 
     57     * thrown. 
     58     * </p> 
     59     *  
     60     * @param instance the instance of add the child to 
     61     * @param child    the child to be added 
     62     *  
     63     * @throws IllegalArgumentException as described 
     64     */ 
     65    void setChild(ISelectionInstance instance, ITaskInstance child) throws IllegalArgumentException; 
     66 
     67    /** 
     68     * <p> 
     69     * sets the child of an optional instance. May ensure, that the child is a valid child 
     70     * considering the task model of the parent. In that case, an IllegalArgumentException is 
     71     * thrown. 
     72     * </p> 
     73     *  
     74     * @param instance the instance of add the child to 
     75     * @param child    the child to be added 
     76     *  
     77     * @throws IllegalArgumentException as described 
     78     */ 
     79    void setChild(IOptionalInstance instance, ITaskInstance child) throws IllegalArgumentException; 
    3880 
    3981    /** 
     
    215257    void replaceChild(ISelection parent, ITask oldChild, ITask newChild); 
    216258 
    217     /** 
    218      * <p> 
    219      * sets the description of a task 
    220      * </p> 
    221      *  
    222      * @param task        the task to set the description of 
    223      * @param description the new description of the task 
    224      */ 
    225     void setDescription(ITask task, String description); 
    226  
    227259} 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeifc/ITaskFactory.java

    r1191 r1294  
    1717import java.util.List; 
    1818 
    19 import de.ugoe.cs.autoquest.eventcore.IEventTarget; 
    20 import de.ugoe.cs.autoquest.eventcore.IEventType; 
     19import de.ugoe.cs.autoquest.eventcore.Event; 
    2120 
    2221/** 
     
    3130    /** 
    3231     * <p> 
    33      * creates a new event task with the given type and target 
     32     * creates a new event task with the given description 
    3433     * </p> 
    3534     *  
    36      * @param eventType   the type of the event represented by the task 
    37      * @param eventTarget the target of the event represented by the task 
     35     * @param description the description for the represented events 
    3836     *  
    3937     * @return the event task 
    4038     */ 
    41     IEventTask createNewEventTask(IEventType eventType, IEventTarget eventTarget); 
     39    IEventTask createNewEventTask(String description); 
    4240 
    4341    /** 
     
    7977    /** 
    8078     * <p> 
    81      * creates a new task instance with the given task as its model 
     79     * creates a new task instance with the given task as its model representing the provided event 
    8280     * </p> 
    8381     *  
    84      * @param task the model of the task instance to be created 
     82     * @param task  the model of the task instance to be created 
     83     * @param event the event represented by the task instance 
    8584     *  
    8685     * @return the task instance 
    8786     */ 
    88     ITaskInstance createNewTaskInstance(ITask task); 
     87    IEventTaskInstance createNewTaskInstance(IEventTask task, Event event); 
    8988 
    9089    /** 
    9190     * <p> 
    92      * creates a new empty task instance list 
     91     * creates a new task instance with the given sequence as its model 
    9392     * </p> 
    9493     *  
    95      * @return the task instance list 
     94     * @param sequence the model of the task instance to be created 
     95     *  
     96     * @return the task instance 
    9697     */ 
    97     ITaskInstanceList createNewTaskInstanceList(); 
     98    ISequenceInstance createNewTaskInstance(ISequence sequence); 
     99 
     100    /** 
     101     * <p> 
     102     * creates a new task instance with the given iteration as its model 
     103     * </p> 
     104     *  
     105     * @param iteration the model of the task instance to be created 
     106     *  
     107     * @return the task instance 
     108     */ 
     109    IIterationInstance createNewTaskInstance(IIteration iteration); 
     110 
     111    /** 
     112     * <p> 
     113     * creates a new task instance with the given optional as its model 
     114     * </p> 
     115     *  
     116     * @param optional the model of the task instance to be created 
     117     *  
     118     * @return the task instance 
     119     */ 
     120    IOptionalInstance createNewTaskInstance(IOptional optional); 
     121 
     122    /** 
     123     * <p> 
     124     * creates a new task instance with the given selection as its model 
     125     * </p> 
     126     *  
     127     * @param selection the model of the task instance to be created 
     128     *  
     129     * @return the task instance 
     130     */ 
     131    ISelectionInstance createNewTaskInstance(ISelection selection); 
    98132 
    99133    /** 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeifc/ITaskInstance.java

    r1177 r1294  
    1515package de.ugoe.cs.autoquest.tasktrees.treeifc; 
    1616 
    17 import java.util.List; 
     17import java.io.Serializable; 
    1818 
    1919/** 
    2020 * <p> 
    2121 * a task instance represents the execution of a specific task within a user session. A task 
    22  * instance is always related to the task that was executed. A task instance may have children 
    23  * but only if its related task allows to have children. For example, if the represented task is 
    24  * a sequence then task instance has children and these are instances of the tasks being the 
    25  * children of the related sequence. 
    26  * </p> 
    27  * <p> 
    28  * An instance of a sequence has the same number of children as the related sequence. An instance 
    29  * of a selection has only one child which is an instance of exactly one variant contained in the 
    30  * related selection. An instance of an iteration has zero or more instances of the same task 
    31  * as children where the task is the child of the related iteration. An instance of an optional 
    32  * has zero or one child where the task related to child is the child of the optional. A task 
    33  * instance related to an event task does not have children. 
     22 * instance is always related to the task that was executed. 
    3423 * </p> 
    3524 *  
    3625 * @author Patrick Harms 
    3726 */ 
    38 public interface ITaskInstance extends ITaskInstanceList { 
    39  
    40     /** 
    41      * <p> 
    42      * returns the children of the task instance if any. See class description for how many 
    43      * children can be expected. May return null. 
    44      * </p> 
    45      *  
    46      * @return as described 
    47      */ 
    48     public List<ITaskInstance> getChildren(); 
     27public interface ITaskInstance extends Serializable, Cloneable { 
    4928 
    5029    /** 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeifc/ITaskInstanceList.java

    r1177 r1294  
    1919/** 
    2020 * <p> 
    21  * represents a serializable, clonable, iterable representation of a read only list of task 
     21 * represents a serializable and iterable representation of a read only list of task 
    2222 * instances. The list is ordered. It does not provide methods for changing it. 
    2323 * </p> 
     
    2525 * @author Patrick Harms 
    2626 */ 
    27 public interface ITaskInstanceList extends Serializable, Cloneable, Iterable<ITaskInstance> { 
     27public interface ITaskInstanceList extends Serializable, Iterable<ITaskInstance> { 
    2828 
    2929    /** 
     
    4848    public int size(); 
    4949 
    50     /** 
    51      * <p> 
    52      * clones a task instance list by creating exact clones of each contained instance in their 
    53      * order 
    54      * </p> 
    55      *  
    56      * @return a clone of the task instance list 
    57      */ 
    58     public ITaskInstanceList clone(); 
    59    
    6050} 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/EventTask.java

    r1255 r1294  
    1515package de.ugoe.cs.autoquest.tasktrees.treeimpl; 
    1616 
    17 import de.ugoe.cs.autoquest.eventcore.IEventTarget; 
    18 import de.ugoe.cs.autoquest.eventcore.IEventType; 
    1917import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 
    2018import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskVisitor; 
     
    3937    /** 
    4038     * <p> 
    41      * the type of the represented event 
    42      * </p>  
    43      */ 
    44     private IEventType eventType; 
    45  
    46     /** 
    47      * <p> 
    48      * the target of the represented event 
    49      * </p>  
    50      */ 
    51     private IEventTarget eventTarget; 
    52  
    53     /** 
    54      * <p> 
    55      * simple constructor initializing this task with an event type and an event target 
     39     * simple constructor initializing this task with a description for the represented events 
    5640     * </p> 
    5741     *  
    58      * @param eventType   the type of the represented event 
    59      * @param eventTarget the target of the represented event 
     42     * @param description a description for the represented events 
    6043     */ 
    61     EventTask(IEventType eventType, IEventTarget eventTarget) { 
    62         super.setDescription(eventType.toString() + " \u21D2 " + eventTarget); 
    63         this.eventType = eventType; 
    64         this.eventTarget = eventTarget; 
    65     } 
    66  
    67     /* (non-Javadoc) 
    68      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask#getEventType() 
    69      */ 
    70     @Override 
    71     public IEventType getEventType() { 
    72         return eventType; 
    73     } 
    74  
    75     /* (non-Javadoc) 
    76      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask#getEventTarget() 
    77      */ 
    78     @Override 
    79     public IEventTarget getEventTarget() { 
    80         return eventTarget; 
     44    EventTask(String description) { 
     45        super.setDescription(description); 
    8146    } 
    8247 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/Task.java

    r1215 r1294  
    1515package de.ugoe.cs.autoquest.tasktrees.treeimpl; 
    1616 
     17import java.util.Collection; 
     18import java.util.Collections; 
     19import java.util.HashSet; 
     20 
    1721import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
     22import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
    1823import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskVisitor; 
    1924 
     
    5661     */ 
    5762    private String description; 
     63     
     64    /** 
     65     * <p> 
     66     * the instances of this task 
     67     * </p> 
     68     */ 
     69    private Collection<ITaskInstance> instances = new HashSet<ITaskInstance>(); 
    5870 
    5971    /** 
     
    97109    public String getDescription() { 
    98110        return description; 
     111    } 
     112 
     113    /* (non-Javadoc) 
     114     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#getInstances() 
     115     */ 
     116    @Override 
     117    public Collection<ITaskInstance> getInstances() { 
     118        return Collections.unmodifiableCollection(instances); 
    99119    } 
    100120 
     
    163183    } 
    164184 
     185    /** 
     186     * <p> 
     187     * internally used to add an instance to this task 
     188     * </p> 
     189     *  
     190     * @param instance the instance belonging to this task 
     191     */ 
     192    void addInstance(ITaskInstance instance) { 
     193        this.instances.add(instance); 
     194    } 
     195     
    165196    /* (non-Javadoc) 
    166197     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#accept(ITaskVisitor) 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskBuilder.java

    r1216 r1294  
    1717import java.util.List; 
    1818 
    19 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 
    2019import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 
     20import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; 
    2121import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 
     22import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance; 
    2223import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 
     24import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; 
    2325import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
     26import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance; 
    2427import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
    2528import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; 
     
    4144 
    4245    /* (non-Javadoc) 
    43      * @see ITaskBuilder#addChild(ITaskInstance,ITaskInstance) 
    44      */ 
    45     @Override 
    46     public void addChild(ITaskInstance parent, ITaskInstance child) throws IllegalArgumentException 
    47     { 
    48         if (!(parent instanceof TaskInstance)) { 
    49             throw new IllegalArgumentException 
    50                 ("illegal type of task instance provided: " + parent.getClass()); 
     46     * @see ITaskBuilder#addChild(ISequenceInstance, ITaskInstance) 
     47     */ 
     48    @Override 
     49    public void addChild(ISequenceInstance instance, ITaskInstance child) 
     50        throws IllegalArgumentException 
     51    { 
     52        if (!(instance instanceof SequenceInstance)) { 
     53            throw new IllegalArgumentException 
     54                ("illegal type of sequence instance provided: " + instance.getClass()); 
    5155        } 
    5256 
    5357        if (!(child instanceof TaskInstance)) { 
    5458            throw new IllegalArgumentException 
    55                 ("illegal type of task instance provided: " + parent.getClass()); 
    56         } 
    57          
    58         // check, that the correct number of children for the distinct types are added 
    59         ITask task = parent.getTask(); 
    60          
    61         if (task instanceof IEventTask) { 
    62             throw new IllegalArgumentException 
    63                 ("can not add children to a task instance of an event task"); 
    64         } 
    65         else if (task instanceof ISelection) { 
    66             if (parent.getChildren().size() > 0) { 
    67                 throw new IllegalArgumentException 
    68                     ("the instance of a selection must have at most one child"); 
     59                ("illegal type of task instance provided: " + child.getClass()); 
     60        } 
     61         
     62        /*IStructuringTemporalRelationship parentTask = 
     63            (IStructuringTemporalRelationship) parent.getTask(); 
     64         
     65        for (ITask parentTaskChild : parentTask.getChildren()) { 
     66            if (parentTaskChild.equals(child.getTask())) { 
     67                foundChildTask = true; 
     68                break; 
    6969            } 
    7070        } 
    71         else if (task instanceof IOptional) { 
    72             if (parent.getChildren().size() > 1) { 
    73                 throw new IllegalArgumentException 
    74                     ("the instance of an optional must have at most one child"); 
    75             } 
    76         } 
    77         /*else if (task instanceof IIteration) { 
    78             for (ITaskInstance childInstance : parent.getChildren()) { 
    79                 if (!childInstance.getTask().equals(child.getTask())) { 
    80                     throw new IllegalArgumentException 
    81                         ("all children of an instance of an iteration must have exactly the " + 
    82                          "same type"); 
    83                 } 
    84             } 
    85         } 
    86          
    87         boolean foundChildTask = false; 
    88         if (parent.getTask() instanceof IStructuringTemporalRelationship) { 
    89             IStructuringTemporalRelationship parentTask = 
    90                 (IStructuringTemporalRelationship) parent.getTask(); 
    91          
    92             for (ITask parentTaskChild : parentTask.getChildren()) { 
    93                 if (parentTaskChild.equals(child.getTask())) { 
    94                     foundChildTask = true; 
    95                     break; 
    96                 } 
    97             } 
    98         } 
    99         else if (parent.getTask() instanceof IMarkingTemporalRelationship) { 
    100             IMarkingTemporalRelationship parentTask = 
    101                 (IMarkingTemporalRelationship) parent.getTask(); 
    102              
    103             foundChildTask = parentTask.getMarkedTask() != null ? 
    104                 parentTask.getMarkedTask().equals(child.getTask()) : false; 
    105         } 
    106          
     71             
    10772        if (!foundChildTask) { 
    10873            throw new IllegalArgumentException 
     
    11176        }*/ 
    11277 
    113         // finally, after all checks are positive, add the child 
    114         ((TaskInstance) parent).addChild(child); 
     78        ((SequenceInstance) instance).addChild(child); 
     79    } 
     80 
     81    /* (non-Javadoc) 
     82     * @see ITaskBuilder#addChild(ISequenceInstance, int, ITaskInstance) 
     83     */ 
     84    public void addChild(ISequenceInstance instance, int index, ITaskInstance child) 
     85        throws IllegalArgumentException 
     86    { 
     87        if (!(instance instanceof SequenceInstance)) { 
     88            throw new IllegalArgumentException 
     89                ("illegal type of sequence instance provided: " + instance.getClass()); 
     90        } 
     91 
     92        if (!(child instanceof TaskInstance)) { 
     93            throw new IllegalArgumentException 
     94                ("illegal type of task instance provided: " + child.getClass()); 
     95        } 
     96         
     97        /*IStructuringTemporalRelationship parentTask = 
     98            (IStructuringTemporalRelationship) parent.getTask(); 
     99         
     100        for (ITask parentTaskChild : parentTask.getChildren()) { 
     101            if (parentTaskChild.equals(child.getTask())) { 
     102                foundChildTask = true; 
     103                break; 
     104            } 
     105        } 
     106             
     107        if (!foundChildTask) { 
     108            throw new IllegalArgumentException 
     109                ("the task of the child instance to be added does not belong to the children " + 
     110                 "of the task of the parent instance"); 
     111        }*/ 
     112 
     113        ((SequenceInstance) instance).addChild(index, child); 
     114    } 
     115 
     116    /* (non-Javadoc) 
     117     * @see ITaskBuilder#addChild(IIterationInstance, ITaskInstance) 
     118     */ 
     119    @Override 
     120    public void addChild(IIterationInstance instance, ITaskInstance child) 
     121        throws IllegalArgumentException 
     122    { 
     123        if (!(instance instanceof IterationInstance)) { 
     124            throw new IllegalArgumentException 
     125                ("illegal type of iteration instance provided: " + instance.getClass()); 
     126        } 
     127 
     128        if (!(child instanceof TaskInstance)) { 
     129            throw new IllegalArgumentException 
     130                ("illegal type of task instance provided: " + child.getClass()); 
     131        } 
     132         
     133        /*IStructuringTemporalRelationship parentTask = 
     134            (IStructuringTemporalRelationship) parent.getTask(); 
     135         
     136        IMarkingTemporalRelationship parentTask = 
     137            (IMarkingTemporalRelationship) parent.getTask(); 
     138             
     139        foundChildTask = parentTask.getMarkedTask() != null ? 
     140            parentTask.getMarkedTask().equals(child.getTask()) : false; 
     141             
     142        if (!foundChildTask) { 
     143            throw new IllegalArgumentException 
     144                ("the task of the child instance to be added does not belong to the children " + 
     145                 "of the task of the parent instance"); 
     146        }*/ 
     147 
     148        ((IterationInstance) instance).addChild(child); 
     149    } 
     150 
     151    /* (non-Javadoc) 
     152     * @see ITaskBuilder#addChild(IIterationInstance, int, ITaskInstance) 
     153     */ 
     154    public void addChild(IIterationInstance instance, int index, ITaskInstance child) 
     155        throws IllegalArgumentException 
     156    { 
     157        if (!(instance instanceof IterationInstance)) { 
     158            throw new IllegalArgumentException 
     159                ("illegal type of iteration instance provided: " + instance.getClass()); 
     160        } 
     161 
     162        if (!(child instanceof TaskInstance)) { 
     163            throw new IllegalArgumentException 
     164                ("illegal type of task instance provided: " + child.getClass()); 
     165        } 
     166         
     167        /*IStructuringTemporalRelationship parentTask = 
     168            (IStructuringTemporalRelationship) parent.getTask(); 
     169         
     170        IMarkingTemporalRelationship parentTask = 
     171            (IMarkingTemporalRelationship) parent.getTask(); 
     172             
     173        foundChildTask = parentTask.getMarkedTask() != null ? 
     174            parentTask.getMarkedTask().equals(child.getTask()) : false; 
     175             
     176        if (!foundChildTask) { 
     177            throw new IllegalArgumentException 
     178                ("the task of the child instance to be added does not belong to the children " + 
     179                 "of the task of the parent instance"); 
     180        }*/ 
     181 
     182        ((IterationInstance) instance).addChild(index, child); 
     183    } 
     184 
     185    /* (non-Javadoc) 
     186     * @see ITaskBuilder#setChild(ISelectionInstance, ITaskInstance) 
     187     */ 
     188    @Override 
     189    public void setChild(ISelectionInstance instance, ITaskInstance child) 
     190        throws IllegalArgumentException 
     191    { 
     192        if (!(instance instanceof SelectionInstance)) { 
     193            throw new IllegalArgumentException 
     194                ("illegal type of sequence instance provided: " + instance.getClass()); 
     195        } 
     196 
     197        if (!(child instanceof TaskInstance)) { 
     198            throw new IllegalArgumentException 
     199                ("illegal type of task instance provided: " + child.getClass()); 
     200        } 
     201         
     202        /*IStructuringTemporalRelationship parentTask = 
     203            (IStructuringTemporalRelationship) parent.getTask(); 
     204         
     205        for (ITask parentTaskChild : parentTask.getChildren()) { 
     206            if (parentTaskChild.equals(child.getTask())) { 
     207                foundChildTask = true; 
     208                break; 
     209            } 
     210        } 
     211             
     212        if (!foundChildTask) { 
     213            throw new IllegalArgumentException 
     214                ("the task of the child instance to be added does not belong to the children " + 
     215                 "of the task of the parent instance"); 
     216        }*/ 
     217 
     218        ((SelectionInstance) instance).setChild(child); 
     219    } 
     220 
     221    /* (non-Javadoc) 
     222     * @see ITaskBuilder#setChild(IOptionalInstance, ITaskInstance) 
     223     */ 
     224    @Override 
     225    public void setChild(IOptionalInstance instance, ITaskInstance child) 
     226        throws IllegalArgumentException 
     227    { 
     228        if (!(instance instanceof OptionalInstance)) { 
     229            throw new IllegalArgumentException 
     230                ("illegal type of optional instance provided: " + instance.getClass()); 
     231        } 
     232 
     233        if (!(child instanceof TaskInstance)) { 
     234            throw new IllegalArgumentException 
     235                ("illegal type of task instance provided: " + child.getClass()); 
     236        } 
     237         
     238        /*IStructuringTemporalRelationship parentTask = 
     239            (IStructuringTemporalRelationship) parent.getTask(); 
     240         
     241        IMarkingTemporalRelationship parentTask = 
     242            (IMarkingTemporalRelationship) parent.getTask(); 
     243             
     244        foundChildTask = parentTask.getMarkedTask() != null ? 
     245            parentTask.getMarkedTask().equals(child.getTask()) : false; 
     246             
     247        if (!foundChildTask) { 
     248            throw new IllegalArgumentException 
     249                ("the task of the child instance to be added does not belong to the children " + 
     250                 "of the task of the parent instance"); 
     251        }*/ 
     252 
     253        ((OptionalInstance) instance).setChild(child); 
    115254    } 
    116255 
     
    134273 
    135274    /* (non-Javadoc) 
     275     * @see ITaskBuilder#addExecutedTask(IUserSession, int, ITaskInstance) 
     276     */ 
     277    public void addExecutedTask(IUserSession session, int index, ITaskInstance taskInstance) { 
     278        if (!(session instanceof UserSession)) { 
     279            throw new IllegalArgumentException 
     280                ("illegal type of session provided: " + session.getClass()); 
     281        } 
     282 
     283        if (!(taskInstance instanceof TaskInstance)) { 
     284            throw new IllegalArgumentException 
     285                ("illegal type of task instance provided: " + taskInstance.getClass()); 
     286        } 
     287         
     288        ((UserSession) session).addExecutedTask(index, taskInstance); 
     289    } 
     290 
     291    /* (non-Javadoc) 
    136292     * @see ITaskBuilder#addTaskInstance(ITaskInstanceList, ITaskInstance) 
    137293     */ 
    138294    @Override 
    139295    public void addTaskInstance(ITaskInstanceList taskInstanceList, ITaskInstance taskInstance) { 
    140         if (taskInstanceList instanceof TaskInstance) { 
    141             ((TaskInstance) taskInstanceList).addChild(taskInstance); 
     296        if (taskInstanceList instanceof SequenceInstance) { 
     297            addChild((SequenceInstance) taskInstanceList, taskInstance); 
     298        } 
     299        else if (taskInstanceList instanceof IterationInstance) { 
     300            addChild((IterationInstance) taskInstanceList, taskInstance); 
    142301        } 
    143302        else if (taskInstanceList instanceof UserSession) { 
    144             ((UserSession) taskInstanceList).addExecutedTask(taskInstance); 
     303            addExecutedTask((UserSession) taskInstanceList, taskInstance); 
    145304        } 
    146305        else { 
     
    158317                                ITaskInstance     taskInstance) 
    159318    { 
    160         if (taskInstanceList instanceof TaskInstance) { 
    161             ((TaskInstance) taskInstanceList).addChild(index, taskInstance); 
     319        if (taskInstanceList instanceof SequenceInstance) { 
     320            addChild((SequenceInstance) taskInstanceList, index, taskInstance); 
     321        } 
     322        else if (taskInstanceList instanceof IterationInstance) { 
     323            addChild((IterationInstance) taskInstanceList, index, taskInstance); 
    162324        } 
    163325        else if (taskInstanceList instanceof UserSession) { 
    164             ((UserSession) taskInstanceList).addExecutedTask(index, taskInstance); 
     326            addExecutedTask((UserSession) taskInstanceList, index, taskInstance); 
    165327        } 
    166328        else { 
     
    178340                                ITaskInstance     taskInstance) 
    179341    { 
    180         if (taskInstanceList instanceof TaskInstance) { 
    181             ((TaskInstance) taskInstanceList).removeChild(index); 
    182             ((TaskInstance) taskInstanceList).addChild(index, taskInstance); 
    183         } 
    184         else if (taskInstanceList instanceof UserSession) { 
    185             ((UserSession) taskInstanceList).removeExecutedTask(index); 
    186             ((UserSession) taskInstanceList).addExecutedTask(index, taskInstance); 
    187         } 
    188         else { 
    189             throw new IllegalArgumentException 
    190                 ("illegal type of task instance list provided: " + taskInstanceList.getClass()); 
    191         } 
     342        removeTaskInstance(taskInstanceList, index); 
     343        addTaskInstance(taskInstanceList, index, taskInstance); 
    192344    } 
    193345 
     
    334486    @Override 
    335487    public void removeTaskInstance(ITaskInstanceList taskInstanceList, int index) { 
    336         if (taskInstanceList instanceof TaskInstance) { 
    337             ((TaskInstance) taskInstanceList).removeChild(index); 
     488        if (taskInstanceList instanceof SequenceInstance) { 
     489            ((SequenceInstance) taskInstanceList).removeChild(index); 
     490        } 
     491        else if (taskInstanceList instanceof IterationInstance) { 
     492            ((IterationInstance) taskInstanceList).removeChild(index); 
    338493        } 
    339494        else if (taskInstanceList instanceof UserSession) { 
     
    369524    } 
    370525 
    371     /* (non-Javadoc) 
    372      * @see ITaskBuilder#setDescription(ITask, java.lang.String) 
    373      */ 
    374     @Override 
    375     public void setDescription(ITask parent, String description) { 
    376         if (!(parent instanceof Task)) { 
    377             throw new IllegalArgumentException 
    378                 ("illegal type of task provided: " + parent.getClass()); 
    379         } 
    380  
    381         ((Task) parent).setDescription(description); 
    382     } 
    383  
    384526    /** 
    385527     * <p> 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskFactory.java

    r1216 r1294  
    1717import java.util.List; 
    1818 
    19 import de.ugoe.cs.autoquest.eventcore.IEventTarget; 
    20 import de.ugoe.cs.autoquest.eventcore.IEventType; 
     19import de.ugoe.cs.autoquest.eventcore.Event; 
    2120import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 
     21import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; 
    2222import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 
     23import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; 
    2324import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 
     25import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance; 
    2426import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 
     27import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; 
    2528import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
    26 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
    27 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
    28 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; 
     29import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance; 
    2930import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; 
    3031import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; 
     
    4344 
    4445    /* (non-Javadoc) 
    45      * @see ITaskFactory#createNewEventTask(IEventType, IEventTarget) 
     46     * @see ITaskFactory#createNewEventTask(String) 
    4647     */ 
    4748    @Override 
    48     public IEventTask createNewEventTask(IEventType eventType, IEventTarget eventTarget) { 
    49         return new EventTask(eventType, eventTarget); 
     49    public IEventTask createNewEventTask(String description) { 
     50        return new EventTask(description); 
    5051    } 
    5152 
     
    8384 
    8485    /* (non-Javadoc) 
    85      * @see ITaskFactory#createNewTaskInstance(ITask) 
     86     * @see ITaskFactory#createNewTaskInstance(IEventTask, Event) 
    8687     */ 
    8788    @Override 
    88     public ITaskInstance createNewTaskInstance(ITask task) { 
    89         return new TaskInstance(task); 
     89    public IEventTaskInstance createNewTaskInstance(IEventTask task, Event event) { 
     90        if (!(task instanceof EventTask)) { 
     91            throw new IllegalArgumentException 
     92                ("illegal type of event task provided: " + task.getClass()); 
     93        } 
     94         
     95        EventTaskInstance instance = new EventTaskInstance(task, event); 
     96        ((EventTask) task).addInstance(instance); 
     97         
     98        return instance; 
    9099    } 
    91100 
    92101    /* (non-Javadoc) 
    93      * @see ITaskFactory#createNewTaskInstanceList() 
     102     * @see ITaskFactory#createNewTaskInstance(ISequence) 
    94103     */ 
    95104    @Override 
    96     public ITaskInstanceList createNewTaskInstanceList() { 
    97         return new TaskInstance(new Sequence()); 
     105    public ISequenceInstance createNewTaskInstance(ISequence sequence) { 
     106        if (!(sequence instanceof Sequence)) { 
     107            throw new IllegalArgumentException 
     108                ("illegal type of sequence provided: " + sequence.getClass()); 
     109        } 
     110         
     111        SequenceInstance instance = new SequenceInstance(sequence); 
     112        ((Sequence) sequence).addInstance(instance); 
     113         
     114        return instance; 
     115    } 
     116 
     117    /* (non-Javadoc) 
     118     * @see ITaskFactory#createNewTaskInstance(IIteration) 
     119     */ 
     120    @Override 
     121    public IIterationInstance createNewTaskInstance(IIteration iteration) { 
     122        if (!(iteration instanceof Iteration)) { 
     123            throw new IllegalArgumentException 
     124                ("illegal type of iteration provided: " + iteration.getClass()); 
     125        } 
     126         
     127        IterationInstance instance = new IterationInstance(iteration); 
     128        ((Iteration) iteration).addInstance(instance); 
     129         
     130        return instance; 
     131    } 
     132 
     133    /* (non-Javadoc) 
     134     * @see ITaskFactory#createNewTaskInstance(IOptional) 
     135     */ 
     136    @Override 
     137    public IOptionalInstance createNewTaskInstance(IOptional optional) { 
     138        if (!(optional instanceof Optional)) { 
     139            throw new IllegalArgumentException 
     140                ("illegal type of optional provided: " + optional.getClass()); 
     141        } 
     142         
     143        OptionalInstance instance = new OptionalInstance(optional); 
     144        ((Optional) optional).addInstance(instance); 
     145         
     146        return instance; 
     147    } 
     148 
     149    /* (non-Javadoc) 
     150     * @see ITaskFactory#createNewTaskInstance(ISelection) 
     151     */ 
     152    @Override 
     153    public ISelectionInstance createNewTaskInstance(ISelection selection) { 
     154        if (!(selection instanceof Selection)) { 
     155            throw new IllegalArgumentException 
     156                ("illegal type of optional provided: " + selection.getClass()); 
     157        } 
     158         
     159        SelectionInstance instance = new SelectionInstance(selection); 
     160        ((Selection) selection).addInstance(instance); 
     161         
     162        return instance; 
    98163    } 
    99164 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskInstance.java

    r1255 r1294  
    1414 
    1515package de.ugoe.cs.autoquest.tasktrees.treeimpl; 
    16  
    17 import java.util.Collections; 
    18 import java.util.Iterator; 
    19 import java.util.LinkedList; 
    20 import java.util.List; 
    2116 
    2217import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
     
    6459    /** 
    6560     * <p> 
    66      * the children of this task instance which are task instances, as well 
    67      * </p> 
    68      */ 
    69     private List<ITaskInstance> children; 
    70  
    71     /** 
    72      * <p> 
    7361     * instantiated the task instance with the task that is instantiated by the instance. It also 
    7462     * assigns a unique id to the instance using {@link #getNewId()}. 
     
    10290    public ITask getTask() { 
    10391        return task; 
    104     } 
    105  
    106     /* (non-Javadoc) 
    107      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance#getChildren() 
    108      */ 
    109     public synchronized List<ITaskInstance> getChildren() { 
    110         if (children == null) { 
    111             children = new LinkedList<ITaskInstance>(); 
    112         } 
    113  
    114         return Collections.unmodifiableList(children); 
    115     } 
    116  
    117     /* (non-Javadoc) 
    118      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#get(int) 
    119      */ 
    120     @Override 
    121     public ITaskInstance get(int index) { 
    122         if (children == null) { 
    123             throw new IndexOutOfBoundsException(Integer.toString(index)); 
    124         } 
    125         else { 
    126             return children.get(index); 
    127         } 
    128     } 
    129  
    130     /* (non-Javadoc) 
    131      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#size() 
    132      */ 
    133     @Override 
    134     public int size() { 
    135         if (children == null) { 
    136             return 0; 
    137         } 
    138         else { 
    139             return children.size(); 
    140         } 
    141     } 
    142  
    143     /* (non-Javadoc) 
    144      * @see java.lang.Iterable#iterator() 
    145      */ 
    146     @Override 
    147     public Iterator<ITaskInstance> iterator() { 
    148         return getChildren().iterator(); 
    14992    } 
    15093 
     
    203146        try { 
    204147            clone = (TaskInstance) super.clone(); 
    205  
    206             if (children != null) { 
    207                 clone.children = new LinkedList<ITaskInstance>(); 
    208  
    209                 for (ITaskInstance child : children) { 
    210                     clone.children.add(child.clone()); 
    211                 } 
    212             } 
    213  
    214148        } 
    215149        catch (CloneNotSupportedException e) { 
     
    219153 
    220154        return clone; 
    221     } 
    222  
    223     /** 
    224      * <p> 
    225      * used to add a child to this task instance 
    226      * </p> 
    227      *  
    228      * @param child the new child of this instance 
    229      */ 
    230     synchronized void addChild(ITaskInstance child) { 
    231         if (children == null) { 
    232             children = new LinkedList<ITaskInstance>(); 
    233         } 
    234  
    235         children.add(child); 
    236     } 
    237  
    238     /** 
    239      * <p> 
    240      * used to add a child to this task instance at a specific position 
    241      * </p> 
    242      *  
    243      * @param index the position of the new child in the list of children 
    244      * @param child the new child of this instance 
    245      */ 
    246     synchronized void addChild(int index, ITaskInstance child) { 
    247         if (children == null) { 
    248             children = new LinkedList<ITaskInstance>(); 
    249         } 
    250  
    251         children.add(index, child); 
    252     } 
    253  
    254     /** 
    255      * <p> 
    256      * removes a child from this task instance at a specific position 
    257      * </p> 
    258      *  
    259      * @param index the position of the child to be removed 
    260      *  
    261      * @return the child remove from the children of this instance 
    262      */ 
    263     synchronized ITaskInstance removeChild(int index) { 
    264         if (children != null) { 
    265             return children.remove(index); 
    266         } 
    267         else { 
    268             throw new IllegalArgumentException 
    269                 ("this task instance does not have children that can be removed"); 
    270         } 
    271155    } 
    272156 
Note: See TracChangeset for help on using the changeset viewer.