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:
1 copied
1 moved

Legend:

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

    r1129 r1146  
    1313//   limitations under the License. 
    1414 
    15 package de.ugoe.cs.autoquest.tasktrees.temporalrelation; 
     15package de.ugoe.cs.autoquest.tasktrees.taskequality; 
    1616 
    1717import java.util.HashMap; 
    1818 
    19 import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEquality; 
    20 import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEqualityRuleManager; 
    21 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 
     19import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
     20import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
    2221import de.ugoe.cs.autoquest.usageprofiles.SymbolComparator; 
    2322import de.ugoe.cs.util.StopWatch; 
     
    3029 * @author Patrick Harms 
    3130 */ 
    32 public class TaskTreeNodeComparator implements SymbolComparator<ITaskTreeNode> { 
     31public class TaskComparator implements SymbolComparator<ITaskInstance> { 
    3332     
    3433    /** 
    3534     * <p> 
    36      * the node equality manager needed for comparing task tree nodes with each other 
     35     * the task equality manager needed for comparing tasks with each other 
    3736     * </p> 
    3837     */ 
    39     private NodeEqualityRuleManager nodeEqualityRuleManager; 
     38    private TaskEqualityRuleManager taskEqualityRuleManager; 
    4039 
    4140    /** 
    4241     * <p> 
    43      * the minimal node equality two identified sublists need to have to consider them as equal 
    44      * and to create an iteration for 
     42     * the minimal task equality two identified sublists need to have to consider them as equal 
    4543     * </p> 
    4644     */ 
    47     private NodeEquality minimalNodeEquality; 
    48  
     45    private TaskEquality minimalNodeEquality; 
     46 
     47    /** */ 
    4948    private Comparer comparer; 
    5049 
     50    /** */ 
    5151    private Comparer lexicalComparer; 
    5252 
     53    /** */ 
    5354    private StopWatch stopWatch = new StopWatch(); 
    5455     
     56    /** */ 
    5557    private HashMap<Long, Boolean> equalityBuffer = new HashMap<Long, Boolean>(); 
    5658 
     59    /** */ 
    5760    private HashMap<Long, Boolean> lexicalEqualityBuffer; 
    5861 
    5962    /** 
    60      * <p> 
    61      * TODO: comment 
    62      * </p> 
    63      * 
    64      * @param nodeEqualityRuleManager 
    65      * @param minimalNodeEquality 
    66      */ 
    67     public TaskTreeNodeComparator(NodeEqualityRuleManager nodeEqualityRuleManager, 
    68                                   NodeEquality            minimalNodeEquality) 
     63     * 
     64     */ 
     65    public TaskComparator(TaskEqualityRuleManager taskEqualityRuleManager, 
     66                                  TaskEquality            minimalNodeEquality) 
    6967    { 
    7068        super(); 
    71         this.nodeEqualityRuleManager = nodeEqualityRuleManager; 
     69        this.taskEqualityRuleManager = taskEqualityRuleManager; 
    7270        this.minimalNodeEquality = minimalNodeEquality; 
    7371         
    74         if (minimalNodeEquality == NodeEquality.LEXICALLY_EQUAL) { 
     72        if (minimalNodeEquality == TaskEquality.LEXICALLY_EQUAL) { 
    7573            comparer = new LexicalComparer(); 
    7674        } 
    77         else if (minimalNodeEquality == NodeEquality.SYNTACTICALLY_EQUAL) { 
     75        else if (minimalNodeEquality == TaskEquality.SYNTACTICALLY_EQUAL) { 
    7876            comparer = new SyntacticalComparer(); 
    7977        } 
    80         else if (minimalNodeEquality == NodeEquality.SEMANTICALLY_EQUAL) { 
     78        else if (minimalNodeEquality == TaskEquality.SEMANTICALLY_EQUAL) { 
    8179            comparer = new SemanticalComparer(); 
    8280        } 
     
    8583        } 
    8684         
    87         if (minimalNodeEquality == NodeEquality.LEXICALLY_EQUAL) { 
     85        if (minimalNodeEquality == TaskEquality.LEXICALLY_EQUAL) { 
    8886            lexicalComparer = comparer; 
    8987            lexicalEqualityBuffer = equalityBuffer; 
     
    9997     */ 
    10098    @Override 
    101     public boolean equals(ITaskTreeNode symbol1, ITaskTreeNode symbol2) { 
    102         //String id = "compare " + symbol1.getClass().getSimpleName() + " " + 
    103         //    symbol2.getClass().getSimpleName(); 
     99    public boolean equals(ITaskInstance taskInstance1, ITaskInstance taskInstance2) { 
     100        return equals(taskInstance1.getTask(), taskInstance2.getTask()); 
     101    }         
     102 
     103    /** 
     104     *  
     105     */ 
     106    public boolean equals(ITask task1, ITask task2) { 
     107        //String id = "compare " + taskInstance1.getClass().getSimpleName() + " " + 
     108        //    taskInstance2.getClass().getSimpleName(); 
    104109        //String id = "compare"; 
    105110        //stopWatch.start(id); 
     
    107112        Boolean result; 
    108113         
    109         if (symbol1 != symbol2) { 
    110             long key = ((long) System.identityHashCode(symbol1)) << 32; 
    111             key += System.identityHashCode(symbol2); 
     114        if (task1 != task2) { 
     115            long key = ((long) System.identityHashCode(task1)) << 32; 
     116            key += System.identityHashCode(task2); 
    112117             
    113118            result = equalityBuffer.get(key); 
    114119             
    115120            if (result == null) { 
    116                 result = comparer.compare(symbol1, symbol2); 
     121                result = comparer.compare(task1, task2); 
    117122                equalityBuffer.put(key, result); 
    118123            } 
     
    123128        //stopWatch.stop(id); 
    124129         
    125         /*boolean result2 = nodeEqualityRuleManager.areAtLeastEqual(symbol1, symbol2, minimalNodeEquality); 
     130        /*boolean result2 = taskEqualityRuleManager.areAtLeastEqual(symbol1, symbol2, minimalNodeEquality); 
    126131        if (result != result2) { 
    127132            throw new IllegalStateException("implementation error"); 
     
    132137 
    133138    /** 
    134      * <p> 
    135      * TODO: comment 
    136      * </p> 
    137      * 
    138      * @return 
     139     * 
     140     */ 
     141    public boolean haveLexicallyEqualTasks(ITaskInstance taskInstance1, 
     142                                           ITaskInstance taskInstance2) 
     143    { 
     144        return areLexicallyEqual(taskInstance1.getTask(), taskInstance2.getTask()); 
     145    } 
     146         
     147 
     148    /** 
     149     * 
     150     */ 
     151    public boolean areLexicallyEqual(ITask task1, ITask task2) { 
     152        Boolean result; 
     153         
     154        if (task1 != task2) { 
     155            long key = ((long) System.identityHashCode(task1)) << 32; 
     156            key += System.identityHashCode(task2); 
     157             
     158            result = lexicalEqualityBuffer.get(key); 
     159             
     160            if (result == null) { 
     161                result = lexicalComparer.compare(task1, task2); 
     162                lexicalEqualityBuffer.put(key, result); 
     163            } 
     164        } 
     165        else { 
     166            result = true; 
     167        } 
     168         
     169        return result; 
     170    } 
     171 
     172    /** 
     173     * 
    139174     */ 
    140175    StopWatch getStopWatch() { 
     
    143178 
    144179    /** 
    145      * <p> 
    146      * TODO: comment 
    147      * </p> 
    148      * 
    149      * @param node1 
    150      * @param node2 
    151      * @return 
    152      */ 
    153     boolean areLexicallyEqual(ITaskTreeNode symbol1, ITaskTreeNode symbol2) { 
    154         Boolean result; 
    155          
    156         if (symbol1 != symbol2) { 
    157             long key = ((long) System.identityHashCode(symbol1)) << 32; 
    158             key += System.identityHashCode(symbol2); 
    159              
    160             result = lexicalEqualityBuffer.get(key); 
    161              
    162             if (result == null) { 
    163                 result = lexicalComparer.compare(symbol1, symbol2); 
    164                 lexicalEqualityBuffer.put(key, result); 
    165             } 
    166         } 
    167         else { 
    168             result = true; 
    169         } 
    170          
    171         return result; 
    172     } 
    173  
    174     /** 
    175      * <p> 
    176      * TODO: comment 
    177      * </p> 
    178      * 
    179      * @return 
    180      */ 
    181     NodeEquality getConsideredNodeEquality() { 
     180     * 
     181     */ 
     182    TaskEquality getConsideredNodeEquality() { 
    182183        return minimalNodeEquality; 
    183184    } 
     
    190191         *  
    191192         */ 
    192         boolean compare(ITaskTreeNode node1, ITaskTreeNode node2); 
     193        boolean compare(ITask task1, ITask task2); 
    193194    } 
    194195 
     
    201202         *  
    202203         */ 
    203         public boolean compare(ITaskTreeNode node1, ITaskTreeNode node2) { 
    204             return nodeEqualityRuleManager.areLexicallyEqual(node1, node2); 
     204        public boolean compare(ITask task1, ITask task2) { 
     205            return taskEqualityRuleManager.areLexicallyEqual(task1, task2); 
    205206        } 
    206207    } 
     
    214215         *  
    215216         */ 
    216         public boolean compare(ITaskTreeNode node1, ITaskTreeNode node2) { 
    217             return nodeEqualityRuleManager.areSyntacticallyEqual(node1, node2); 
     217        public boolean compare(ITask task1, ITask task2) { 
     218            return taskEqualityRuleManager.areSyntacticallyEqual(task1, task2); 
    218219        } 
    219220    } 
     
    227228         *  
    228229         */ 
    229         public boolean compare(ITaskTreeNode node1, ITaskTreeNode node2) { 
    230             return nodeEqualityRuleManager.areSemanticallyEqual(node1, node2); 
     230        public boolean compare(ITask task1, ITask task2) { 
     231            return taskEqualityRuleManager.areSemanticallyEqual(task1, task2); 
    231232        } 
    232233    } 
     
    240241         *  
    241242         */ 
    242         public boolean compare(ITaskTreeNode node1, ITaskTreeNode node2) { 
    243             return nodeEqualityRuleManager.areAtLeastEqual(node1, node2, minimalNodeEquality); 
     243        public boolean compare(ITask task1, ITask task2) { 
     244            return taskEqualityRuleManager.areAtLeastEqual(task1, task2, minimalNodeEquality); 
    244245        } 
    245246    } 
Note: See TracChangeset for help on using the changeset viewer.