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

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality/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} 
Note: See TracChangeset for help on using the changeset viewer.