Ignore:
Timestamp:
04/04/13 16:06:07 (11 years ago)
Author:
pharms
Message:
  • complete refactoring of task tree model with a separation of task models and task instances
  • appropriate adaptation of task tree generation process
  • appropriate adaptation of commands and task tree visualization
Location:
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/taskequality
Files:
2 copied

Legend:

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

    r1125 r1146  
    1313//   limitations under the License. 
    1414 
    15 package de.ugoe.cs.autoquest.tasktrees.nodeequality; 
     15package de.ugoe.cs.autoquest.tasktrees.taskequality; 
    1616 
    1717import java.util.List; 
    1818 
    1919import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 
    20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 
     20import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
    2121 
    2222/** 
    2323 * <p> 
    24  * this node comparison rule is capable of comparing selections. If both selections do not have 
    25  * children, they are treated as identical. If they have children, each child of both selections 
    26  * is compared to each child of the respective other selection. The resulting equality is the most 
    27  * concrete one of all these comparisons. I.e. if all children are at least lexically equal, then 
    28  * the selections are lexically equal. If all children are at least syntactically equal, then the 
    29  * selections are syntactically equal. If all children are at least semantically equal, then the 
    30  * selections are semantically equal. If only one of the selections has children, then the 
    31  * selections are unequal. 
     24 * this task comparison rule is capable of comparing selections. If both selections do not have 
     25 * children, they are treated as lexically equal. If they have children, each child of both 
     26 * selections is compared to each child of the respective other selection. The resulting equality 
     27 * is the most concrete one of all these comparisons. I.e. if all children are at least lexically 
     28 * equal, then the selections are lexically equal. If all children are at least syntactically 
     29 * equal, then the selections are syntactically equal. If all children are at least semantically 
     30 * equal, then the selections are semantically equal. If only one of the selections has children, 
     31 * then the selections are unequal. 
    3232 * </p> 
    3333 *  
     
    3535 * @author 2012, last modified by $Author: patrick$ 
    3636 */ 
    37 public class SelectionComparisonRule implements NodeComparisonRule { 
    38  
    39     /** the rule manager for internally comparing task tree nodes */ 
    40     private NodeEqualityRuleManager mRuleManager; 
    41  
    42     /** 
    43      * <p> 
    44      * simple constructor to provide the rule with the node equality rule manager to be able 
    45      * to perform comparisons of the children of provided task tree nodes 
     37public class SelectionComparisonRule implements TaskComparisonRule { 
     38 
     39    /** the rule manager for internally comparing tasks */ 
     40    private TaskEqualityRuleManager mRuleManager; 
     41 
     42    /** 
     43     * <p> 
     44     * simple constructor to provide the rule with the task equality rule manager to be able 
     45     * to perform comparisons of the children of provided tasks 
    4646     * </p> 
    4747     *  
    48      * @param ruleManager the rule manager for comparing task tree nodes 
    49      */ 
    50     SelectionComparisonRule(NodeEqualityRuleManager ruleManager) { 
     48     * @param ruleManager the rule manager for comparing tasks 
     49     */ 
     50    SelectionComparisonRule(TaskEqualityRuleManager ruleManager) { 
    5151        super(); 
    5252        mRuleManager = ruleManager; 
     
    5454 
    5555    /* (non-Javadoc) 
    56      * @see NodeComparisonRule#isApplicable(ITaskTreeNode, ITaskTreeNode) 
    57      */ 
    58     @Override 
    59     public boolean isApplicable(ITaskTreeNode node1, ITaskTreeNode node2) { 
    60         return (node1 instanceof ISelection) && (node2 instanceof ISelection); 
    61     } 
    62  
    63     /* (non-Javadoc) 
    64      * @see NodeComparisonRule#areLexicallyEqual(ITaskTreeNode, ITaskTreeNode) 
    65      */ 
    66     @Override 
    67     public boolean areLexicallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 
    68         NodeEquality equality = getEquality(node1, node2, NodeEquality.LEXICALLY_EQUAL); 
    69         return (equality != null) && (equality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)); 
    70     } 
    71  
    72     /* (non-Javadoc) 
    73      * @see NodeComparisonRule#areSyntacticallyEqual(ITaskTreeNode, ITaskTreeNode) 
    74      */ 
    75     @Override 
    76     public boolean areSyntacticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 
    77         NodeEquality equality = getEquality(node1, node2, NodeEquality.SYNTACTICALLY_EQUAL); 
    78         return (equality != null) && (equality.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL)); 
    79     } 
    80  
    81     /* (non-Javadoc) 
    82      * @see NodeComparisonRule#areSemanticallyEqual(ITaskTreeNode, ITaskTreeNode) 
    83      */ 
    84     @Override 
    85     public boolean areSemanticallyEqual(ITaskTreeNode node1, ITaskTreeNode node2) { 
    86         NodeEquality equality = getEquality(node1, node2, NodeEquality.SEMANTICALLY_EQUAL); 
    87         return (equality != null) && (equality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)); 
    88     } 
    89  
    90     /* (non-Javadoc) 
    91      * @see NodeComparisonRule#compare(ITaskTreeNode, ITaskTreeNode) 
    92      */ 
    93     @Override 
    94     public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 
    95         return getEquality(node1, node2, null); 
     56     * @see NodeComparisonRule#isApplicable(ITask, ITask) 
     57     */ 
     58    @Override 
     59    public boolean isApplicable(ITask task1, ITask task2) { 
     60        return (task1 instanceof ISelection) && (task2 instanceof ISelection); 
     61    } 
     62 
     63    /* (non-Javadoc) 
     64     * @see NodeComparisonRule#areLexicallyEqual(ITask, ITask) 
     65     */ 
     66    @Override 
     67    public boolean areLexicallyEqual(ITask task1, ITask task2) { 
     68        TaskEquality equality = getEquality(task1, task2, TaskEquality.LEXICALLY_EQUAL); 
     69        return (equality != null) && (equality.isAtLeast(TaskEquality.LEXICALLY_EQUAL)); 
     70    } 
     71 
     72    /* (non-Javadoc) 
     73     * @see NodeComparisonRule#areSyntacticallyEqual(ITask, ITask) 
     74     */ 
     75    @Override 
     76    public boolean areSyntacticallyEqual(ITask task1, ITask task2) { 
     77        TaskEquality equality = getEquality(task1, task2, TaskEquality.SYNTACTICALLY_EQUAL); 
     78        return (equality != null) && (equality.isAtLeast(TaskEquality.SYNTACTICALLY_EQUAL)); 
     79    } 
     80 
     81    /* (non-Javadoc) 
     82     * @see NodeComparisonRule#areSemanticallyEqual(ITask, ITask) 
     83     */ 
     84    @Override 
     85    public boolean areSemanticallyEqual(ITask task1, ITask task2) { 
     86        TaskEquality equality = getEquality(task1, task2, TaskEquality.SEMANTICALLY_EQUAL); 
     87        return (equality != null) && (equality.isAtLeast(TaskEquality.SEMANTICALLY_EQUAL)); 
     88    } 
     89 
     90    /* (non-Javadoc) 
     91     * @see NodeComparisonRule#compare(ITask, ITask) 
     92     */ 
     93    @Override 
     94    public TaskEquality compare(ITask task1, ITask task2) { 
     95        return getEquality(task1, task2, null); 
    9696    } 
    9797 
     
    9999     *  
    100100     */ 
    101     private NodeEquality getEquality(ITaskTreeNode node1, 
    102                                      ITaskTreeNode node2, 
    103                                      NodeEquality  requiredEqualityLevel) 
    104     { 
    105         List<ITaskTreeNode> children1 = node1.getChildren(); 
    106         List<ITaskTreeNode> children2 = node2.getChildren(); 
     101    private TaskEquality getEquality(ITask task1, ITask task2, TaskEquality requiredEqualityLevel) { 
     102        List<ITask> children1 = ((ISelection) task1).getChildren(); 
     103        List<ITask> children2 = ((ISelection) task2).getChildren(); 
    107104 
    108105        // if both selections do not have children, they are lexically equal. If only one of them 
    109106        // has children, they are unequal. 
    110107        if ((children1.size() == 0) && (children2.size() == 0)) { 
    111             return NodeEquality.LEXICALLY_EQUAL; 
     108            return TaskEquality.LEXICALLY_EQUAL; 
    112109        } 
    113110        else if ((children1.size() == 0) || (children2.size() == 0)) { 
    114             return NodeEquality.UNEQUAL; 
    115         } 
    116  
    117         NodeEquality selectionEquality; 
     111            return TaskEquality.UNEQUAL; 
     112        } 
     113 
     114        TaskEquality selectionEquality; 
    118115 
    119116        if (requiredEqualityLevel == null) { 
     
    121118            // do it in both directions to ensure commutative comparison 
    122119            selectionEquality = getCommonEqualityLevel(children1, children2); 
    123             if (selectionEquality != NodeEquality.UNEQUAL) { 
     120            if (selectionEquality != TaskEquality.UNEQUAL) { 
    124121                return selectionEquality.getCommonDenominator 
    125122                    (getCommonEqualityLevel(children2, children1)); 
    126123            } 
    127124            else { 
    128                 return NodeEquality.UNEQUAL; 
     125                return TaskEquality.UNEQUAL; 
    129126            } 
    130127        } 
     
    137134            } 
    138135            else { 
    139                 return NodeEquality.UNEQUAL; 
     136                return TaskEquality.UNEQUAL; 
    140137            } 
    141138        } 
     
    151148     * @param requiredEqualityLevel 
    152149     */ 
    153     private NodeEquality getCommonEqualityLevel(List<ITaskTreeNode> children1, 
    154                                                 List<ITaskTreeNode> children2) 
    155     { 
    156         NodeEquality listEquality = NodeEquality.LEXICALLY_EQUAL; 
     150    private TaskEquality getCommonEqualityLevel(List<ITask> children1, List<ITask> children2) { 
     151        TaskEquality listEquality = TaskEquality.LEXICALLY_EQUAL; 
    157152         
    158         NodeEquality childEquality; 
    159         NodeEquality currentEquality; 
    160         for (ITaskTreeNode child1 : children1) { 
     153        TaskEquality childEquality; 
     154        TaskEquality currentEquality; 
     155        for (ITask child1 : children1) { 
    161156            childEquality = null; 
    162             for (ITaskTreeNode child2 : children2) { 
     157            for (ITask child2 : children2) { 
    163158                currentEquality = callRuleManager(child1, child2, null); 
    164                 if ((currentEquality != null) && (currentEquality != NodeEquality.UNEQUAL)) { 
     159                if ((currentEquality != null) && (currentEquality != TaskEquality.UNEQUAL)) { 
    165160                    if (childEquality == null) { 
    166161                        childEquality = currentEquality; 
     
    170165                    } 
    171166                     
    172                     if (childEquality == NodeEquality.SEMANTICALLY_EQUAL) { 
     167                    if (childEquality == TaskEquality.SEMANTICALLY_EQUAL) { 
    173168                        // as we calculate only the common denominator, we can break up here for 
    174169                        // the current child. We will not improve the denominator anymore 
     
    181176                // we did not find any child in the second list, that is equal to the searched 
    182177                // child 
    183                 return NodeEquality.UNEQUAL; 
     178                return TaskEquality.UNEQUAL; 
    184179            } 
    185180            else { 
     
    200195     * @param requiredEqualityLevel 
    201196     */ 
    202     private boolean checkEqualityLevel(List<ITaskTreeNode> children1, 
    203                                        List<ITaskTreeNode> children2, 
    204                                        NodeEquality        requiredEqualityLevel) 
     197    private boolean checkEqualityLevel(List<ITask> children1, 
     198                                       List<ITask> children2, 
     199                                       TaskEquality requiredEqualityLevel) 
    205200    { 
    206         NodeEquality childEquality; 
    207         NodeEquality currentEquality; 
    208         for (ITaskTreeNode child1 : children1) { 
     201        TaskEquality childEquality; 
     202        TaskEquality currentEquality; 
     203        for (ITask child1 : children1) { 
    209204            childEquality = null; 
    210             for (ITaskTreeNode child2 : children2) { 
     205            for (ITask child2 : children2) { 
    211206                currentEquality = callRuleManager(child1, child2, requiredEqualityLevel); 
    212207                if ((currentEquality != null) && (currentEquality.isAtLeast(requiredEqualityLevel))) 
     
    240235     * @return 
    241236     */ 
    242     private NodeEquality callRuleManager(ITaskTreeNode child1, 
    243                                          ITaskTreeNode child2, 
    244                                          NodeEquality requiredEqualityLevel) 
     237    private TaskEquality callRuleManager(ITask        child1, 
     238                                         ITask        child2, 
     239                                         TaskEquality requiredEqualityLevel) 
    245240    { 
    246241        if (requiredEqualityLevel == null) { 
     
    251246        } 
    252247        else { 
    253             return NodeEquality.UNEQUAL; 
     248            return TaskEquality.UNEQUAL; 
    254249        } 
    255250    } 
Note: See TracChangeset for help on using the changeset viewer.