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/taskequality
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • 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} 
Note: See TracChangeset for help on using the changeset viewer.