Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/ITaskInstanceListScopeRule.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/ITaskInstanceListScopeRule.java	(revision 1287)
+++ 	(revision )
@@ -1,45 +1,0 @@
-//   Copyright 2012 Georg-August-Universität Göttingen, Germany
-//
-//   Licensed under the Apache License, Version 2.0 (the "License");
-//   you may not use this file except in compliance with the License.
-//   You may obtain a copy of the License at
-//
-//       http://www.apache.org/licenses/LICENSE-2.0
-//
-//   Unless required by applicable law or agreed to in writing, software
-//   distributed under the License is distributed on an "AS IS" BASIS,
-//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//   See the License for the specific language governing permissions and
-//   limitations under the License.
-
-package de.ugoe.cs.autoquest.tasktrees.temporalrelation;
-
-import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList;
-
-/**
- * <p>
- * a task instance list scope rule is able to detected temporal relationships between a list of task
- * instances provided to the {@link #apply(ITaskInstanceList)} method. A rule creates temporal
- * relationships between the task instances, i.e. substructures in the task tree, if
- * it detects a temporal relationship and instantiates the temporal relationships accordingly.
- * </p>
- * 
- * @author Patrick Harms
- */
-interface ITaskInstanceListScopeRule extends ITemporalRelationshipRule {
-
-  /**
-   * <p>
-   * applies the rule to the given task instance list. The returned rule application result is null,
-   * if the rule can not be applied, i.e. it does not detect a temporal relationship. It returns a
-   * rule application result with a status {@link RuleApplicationStatus#RULE_APPLICATION_FINISHED}
-   * if the rule was applied. The result contains all newly created parent tasks and task instances.
-   * </p>
-   * 
-   * @param taskInstances the list of task instances to apply the rule on
-   *                    
-   * @return the rule application result as described.
-   */
-  RuleApplicationResult apply(ITaskInstanceList taskInstances);
-  
-}
Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/ITaskInstanceScopeRule.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/ITaskInstanceScopeRule.java	(revision 1294)
+++ trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/ITaskInstanceScopeRule.java	(revision 1294)
@@ -0,0 +1,45 @@
+//   Copyright 2012 Georg-August-Universität Göttingen, Germany
+//
+//   Licensed under the Apache License, Version 2.0 (the "License");
+//   you may not use this file except in compliance with the License.
+//   You may obtain a copy of the License at
+//
+//       http://www.apache.org/licenses/LICENSE-2.0
+//
+//   Unless required by applicable law or agreed to in writing, software
+//   distributed under the License is distributed on an "AS IS" BASIS,
+//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//   See the License for the specific language governing permissions and
+//   limitations under the License.
+
+package de.ugoe.cs.autoquest.tasktrees.temporalrelation;
+
+import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
+
+/**
+ * <p>
+ * a task instance scope rule is able to detected temporal relationships between the children of
+ * a task instance provided to the {@link #apply(ITaskInstance)} method. A rule creates temporal
+ * relationships between the task instances, i.e. substructures in the task tree, if
+ * it detects a temporal relationship and instantiates the temporal relationships accordingly.
+ * </p>
+ * 
+ * @author Patrick Harms
+ */
+interface ITaskInstanceScopeRule extends ITemporalRelationshipRule {
+
+  /**
+   * <p>
+   * applies the rule to the given task instance. The returned rule application result is null,
+   * if the rule can not be applied, i.e. it does not detect a temporal relationship. It returns a
+   * rule application result with a status {@link RuleApplicationStatus#RULE_APPLICATION_FINISHED}
+   * if the rule was applied. The result contains all newly created parent tasks and task instances.
+   * </p>
+   * 
+   * @param taskInstance the task instances to apply the rule on
+   *                    
+   * @return the rule application result as described.
+   */
+  RuleApplicationResult apply(ITaskInstance taskInstance);
+  
+}
Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/ITemporalRelationshipRule.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/ITemporalRelationshipRule.java	(revision 1287)
+++ trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/ITemporalRelationshipRule.java	(revision 1294)
@@ -19,5 +19,5 @@
  * a temporal relationship rule is the main interface for all rules applied for generating
  * temporal relationships in a task tree. It is just a marker interface. More important are the
- * sub interfaces {@link ISessionScopeRule} and {@link ITaskInstanceListScopeRule}.
+ * sub interfaces {@link ISessionScopeRule} and {@link ITaskInstanceScopeRule}.
  * </p>
  * 
Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/RuleUtils.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/RuleUtils.java	(revision 1287)
+++ trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/RuleUtils.java	(revision 1294)
@@ -15,5 +15,6 @@
 package de.ugoe.cs.autoquest.tasktrees.temporalrelation;
 
-import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
@@ -55,9 +56,9 @@
                                                int               startIndex,
                                                int               endIndex,
-                                               ITask             model,
+                                               ISequence         model,
                                                ITaskFactory      taskFactory,
                                                ITaskBuilder      taskBuilder)
     {
-        ITaskInstance subsequence = taskFactory.createNewTaskInstance(model);
+        ISequenceInstance subsequence = taskFactory.createNewTaskInstance(model);
 
         for (int i = startIndex; i <= endIndex; i++) {
@@ -83,12 +84,12 @@
      * @return the replacement for the range
      */
-    static ITaskInstance createNewSubSequenceInRange(ITaskInstanceList parent,
-                                                     int               startIndex,
-                                                     int               endIndex,
-                                                     ITask             model,
-                                                     ITaskFactory      taskFactory,
-                                                     ITaskBuilder      taskBuilder)
+    static ISequenceInstance createNewSubSequenceInRange(ITaskInstanceList parent,
+                                                         int               startIndex,
+                                                         int               endIndex,
+                                                         ISequence         model,
+                                                         ITaskFactory      taskFactory,
+                                                         ITaskBuilder      taskBuilder)
     {
-        ITaskInstance subsequence = taskFactory.createNewTaskInstance(model);
+        ISequenceInstance subsequence = taskFactory.createNewTaskInstance(model);
 
         for (int i = startIndex; i <= endIndex; i++) {
Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRule.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRule.java	(revision 1287)
+++ trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRule.java	(revision 1294)
@@ -26,6 +26,9 @@
 import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder;
@@ -159,5 +162,5 @@
         SymbolMap<ITaskInstance, ITask> uniqueTasks =
             preparationTaskHandlingStrategy.createSymbolMap();
-        TaskComparator comparator = preparationTaskHandlingStrategy.getTaskComparator();
+        TaskInstanceComparator comparator = preparationTaskHandlingStrategy.getTaskComparator();
         
         int unifiedTasks = 0;
@@ -235,14 +238,14 @@
     {
         Map<ITask, IIteration> iterations = new HashMap<ITask, IIteration>();
-        Map<IIteration, List<ITaskInstance>> iterationInstances =
-                new HashMap<IIteration, List<ITaskInstance>>();
+        Map<IIteration, List<IIterationInstance>> iterationInstances =
+                new HashMap<IIteration, List<IIterationInstance>>();
             
         for (ITask iteratedTask : iteratedTasks) {
             IIteration iteration = taskFactory.createNewIteration();
             iterations.put(iteratedTask, iteration);
-            iterationInstances.put(iteration, new LinkedList<ITaskInstance>());
-        }
-        
-        ITaskInstance iterationInstance = null;
+            iterationInstances.put(iteration, new LinkedList<IIterationInstance>());
+        }
+        
+        IIterationInstance iterationInstance = null;
         
         for (IUserSession session : sessions) {
@@ -275,5 +278,6 @@
         }
         
-        for (Map.Entry<IIteration, List<ITaskInstance>> entry : iterationInstances.entrySet()) {
+        for (Map.Entry<IIteration, List<IIterationInstance>> entry : iterationInstances.entrySet())
+        {
             harmonizeIterationInstancesModel(entry.getKey(), entry.getValue());
         }
@@ -283,12 +287,12 @@
      *
      */
-    private void harmonizeIterationInstancesModel(IIteration          iteration,
-                                                  List<ITaskInstance> iterationInstances)
+    private void harmonizeIterationInstancesModel(IIteration               iteration,
+                                                  List<IIterationInstance> iterationInstances)
     {
         List<ITask> iteratedTaskVariants = new LinkedList<ITask>();
-        TaskComparator comparator = preparationTaskHandlingStrategy.getTaskComparator();
+        TaskInstanceComparator comparator = preparationTaskHandlingStrategy.getTaskComparator();
         
         // merge the lexically different variants of iterated task to a unique list 
-        for (ITaskInstance iterationInstance : iterationInstances) {
+        for (IIterationInstance iterationInstance : iterationInstances) {
             for (ITaskInstance executionVariant : iterationInstance) {
                 ITask candidate = executionVariant.getTask();
@@ -323,8 +327,9 @@
             taskBuilder.setMarkedTask(iteration, selection);
             
-            for (ITaskInstance instance : iterationInstances) {
+            for (IIterationInstance instance : iterationInstances) {
                 for (int i = 0; i < instance.size(); i++) {
-                    ITaskInstance selectionInstance = taskFactory.createNewTaskInstance(selection);
-                    taskBuilder.addChild(selectionInstance, instance.get(i));
+                    ISelectionInstance selectionInstance =
+                        taskFactory.createNewTaskInstance(selection);
+                    taskBuilder.setChild(selectionInstance, instance.get(i));
                     taskBuilder.setTaskInstance(instance, i, selectionInstance);
                 }
@@ -490,5 +495,5 @@
                 Console.traceln(Level.FINEST, "replacing " + sequence.getId() + ": " + task);
 
-                List<ITaskInstance> sequenceInstances =
+                List<ISequenceInstance> sequenceInstances =
                     replaceTaskOccurrences(task, appData.getSessions(), sequence);
                 
@@ -510,9 +515,9 @@
      *
      */
-    private void harmonizeSequenceInstancesModel(ISequence           sequence,
-                                                 List<ITaskInstance> sequenceInstances,
-                                                 int                 sequenceLength)
+    private void harmonizeSequenceInstancesModel(ISequence               sequence,
+                                                 List<ISequenceInstance> sequenceInstances,
+                                                 int                     sequenceLength)
     {
-        TaskComparator comparator = preparationTaskHandlingStrategy.getTaskComparator();
+        TaskInstanceComparator comparator = preparationTaskHandlingStrategy.getTaskComparator();
         
         // ensure for each subtask that lexically different variants are preserved
@@ -520,5 +525,5 @@
             List<ITask> subTaskVariants = new LinkedList<ITask>();
             
-            for (ITaskInstance sequenceInstance : sequenceInstances) {
+            for (ISequenceInstance sequenceInstance : sequenceInstances) {
                 ITask candidate = sequenceInstance.get(subTaskIndex).getTask();
                 
@@ -556,8 +561,8 @@
                 taskBuilder.addChild(sequence, selection);
                 
-                for (ITaskInstance instance : sequenceInstances) {
-                    ITaskInstance selectionInstance =
+                for (ISequenceInstance instance : sequenceInstances) {
+                    ISelectionInstance selectionInstance =
                         taskFactory.createNewTaskInstance(selection);
-                    taskBuilder.addChild(selectionInstance, instance.get(subTaskIndex));
+                    taskBuilder.setChild(selectionInstance, instance.get(subTaskIndex));
                     taskBuilder.setTaskInstance(instance, subTaskIndex, selectionInstance);
                 }
@@ -572,9 +577,9 @@
      * @param tree
      */
-    private List<ITaskInstance> replaceTaskOccurrences(List<ITaskInstance> task,
-                                                       List<IUserSession>  sessions,
-                                                       ISequence           temporalTaskModel)
+    private List<ISequenceInstance> replaceTaskOccurrences(List<ITaskInstance> task,
+                                                           List<IUserSession>  sessions,
+                                                           ISequence           temporalTaskModel)
     {
-        List<ITaskInstance> sequenceInstances = new LinkedList<ITaskInstance>();
+        List<ISequenceInstance> sequenceInstances = new LinkedList<ISequenceInstance>();
         
         for (IUserSession session : sessions) {
Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskComparator.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskComparator.java	(revision 1287)
+++ 	(revision )
@@ -1,254 +1,0 @@
-//   Copyright 2012 Georg-August-Universität Göttingen, Germany
-//
-//   Licensed under the Apache License, Version 2.0 (the "License");
-//   you may not use this file except in compliance with the License.
-//   You may obtain a copy of the License at
-//
-//       http://www.apache.org/licenses/LICENSE-2.0
-//
-//   Unless required by applicable law or agreed to in writing, software
-//   distributed under the License is distributed on an "AS IS" BASIS,
-//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//   See the License for the specific language governing permissions and
-//   limitations under the License.
-
-package de.ugoe.cs.autoquest.tasktrees.temporalrelation;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.util.HashMap;
-
-import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality;
-import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEqualityRuleManager;
-import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
-import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
-import de.ugoe.cs.autoquest.usageprofiles.SymbolComparator;
-
-/**
- * TODO comment
- */
-class TaskComparator implements SymbolComparator<ITaskInstance> {
-    
-    /**  */
-    private static final long serialVersionUID = 1L;
-    
-    /** */
-    private static final int MAX_BUFFER_SIZE = 2 * 1024 * 1024;
-
-    /** */
-    private TaskEquality minimalNodeEquality;
-
-    /** */
-    private transient Comparer comparer;
-
-    /** */
-    private transient Comparer lexicalComparer;
-
-    /** */
-    private transient HashMap<Long, Boolean> equalityBuffer = new HashMap<Long, Boolean>();
-
-    /** */
-    private transient HashMap<Long, Boolean> lexicalEqualityBuffer;
-
-    /**
-     *
-     */
-    public TaskComparator(TaskEquality minimalNodeEquality) {
-        this.minimalNodeEquality = minimalNodeEquality;
-        init();
-    }
-
-    /* (non-Javadoc)
-     * @see SymbolComparator#equals(Object, Object)
-     */
-    @Override
-    public boolean equals(ITaskInstance taskInstance1, ITaskInstance taskInstance2) {
-        return equals(taskInstance1.getTask(), taskInstance2.getTask());
-    }        
-
-    /**
-     * 
-     */
-    public boolean equals(ITask task1, ITask task2) {
-        Boolean result;
-        
-        if (task1 != task2) {
-            //if ((task1 instanceof IEventTask) && (task2 instanceof IEventTask)) {
-                long key = ((long) System.identityHashCode(task1)) << 32;
-                key += System.identityHashCode(task2);
-            
-                result = equalityBuffer.get(key);
-            
-                if (result == null) {
-                    result = comparer.compare(task1, task2);
-                    
-                    if (equalityBuffer.size() < MAX_BUFFER_SIZE) {
-                        equalityBuffer.put(key, result);
-                    }
-                }
-            /*}
-            else {
-                result = false;
-            }*/
-        }
-        else {
-            result = true;
-        }
-        
-        return result;
-    }
-
-    /**
-     *
-     */
-    public boolean areLexicallyEqual(ITask task1, ITask task2) {
-        Boolean result;
-        
-        if (task1 != task2) {
-            long key = ((long) System.identityHashCode(task1)) << 32;
-            key += System.identityHashCode(task2);
-            
-            result = lexicalEqualityBuffer.get(key);
-            
-            if (result == null) {
-                result = lexicalComparer.compare(task1, task2);
-                if (equalityBuffer.size() < MAX_BUFFER_SIZE) {
-                    lexicalEqualityBuffer.put(key, result);
-                }
-            }
-        }
-        else {
-            result = true;
-        }
-        
-        return result;
-    }
-    
-    /**
-     * <p>
-     * TODO: comment
-     * </p>
-     *
-     */
-    void clearBuffers() {
-        equalityBuffer.clear();
-        init();
-    }
-    
-    /**
-     * 
-     */
-    private void init() {
-        if (minimalNodeEquality == TaskEquality.LEXICALLY_EQUAL) {
-            comparer = new LexicalComparer();
-        }
-        else if (minimalNodeEquality == TaskEquality.SYNTACTICALLY_EQUAL) {
-            comparer = new SyntacticalComparer();
-        }
-        else if (minimalNodeEquality == TaskEquality.SEMANTICALLY_EQUAL) {
-            comparer = new SemanticalComparer();
-        }
-        else {
-            comparer = new DefaultComparer(this.minimalNodeEquality);
-        }
-        
-        if (minimalNodeEquality == TaskEquality.LEXICALLY_EQUAL) {
-            lexicalComparer = comparer;
-            lexicalEqualityBuffer = equalityBuffer;
-        }
-        else {
-            lexicalComparer = new LexicalComparer();
-            lexicalEqualityBuffer = new HashMap<Long, Boolean>();
-        }
-    }
-    
-    /**
-     * <p>
-     * deserialize this object and reinitialize the buffers
-     * </p>
-     */
-    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
-        in.defaultReadObject();
-        init();
-    }
-
-
-    /**
-     * 
-     */
-    private static interface Comparer {
-        
-        /**
-         * 
-         */
-        boolean compare(ITask task1, ITask task2);
-    }
-
-    /**
-     * 
-     */
-    private static class LexicalComparer implements Comparer {
-        
-        /**
-         * 
-         */
-        public boolean compare(ITask task1, ITask task2) {
-            return TaskEqualityRuleManager.getInstance().areLexicallyEqual(task1, task2);
-        }
-    }
-
-    /**
-     * 
-     */
-    private static class SyntacticalComparer implements Comparer {
-        
-        /**
-         * 
-         */
-        public boolean compare(ITask task1, ITask task2) {
-            return TaskEqualityRuleManager.getInstance().areSyntacticallyEqual(task1, task2);
-        }
-    }
-
-    /**
-     * 
-     */
-    private static class SemanticalComparer implements Comparer {
-        
-        /**
-         * 
-         */
-        public boolean compare(ITask task1, ITask task2) {
-            return TaskEqualityRuleManager.getInstance().areSemanticallyEqual(task1, task2);
-        }
-    }
-
-    /**
-     * 
-     */
-    private static class DefaultComparer implements Comparer {
-        
-        /**
-         * <p>
-         * the minimal task equality two identified sublists need to have to consider them as equal
-         * </p>
-         */
-        private TaskEquality minimalNodeEquality;
-        
-        /**
-         *
-         */
-        public DefaultComparer(TaskEquality minimalNodeEquality) {
-           this.minimalNodeEquality = minimalNodeEquality;
-        }
-        
-        /**
-         * 
-         */
-        public boolean compare(ITask task1, ITask task2) {
-            return TaskEqualityRuleManager.getInstance().areAtLeastEqual
-                (task1, task2, minimalNodeEquality);
-        }
-    }
-
-}
Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskHandlingStrategy.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskHandlingStrategy.java	(revision 1287)
+++ trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskHandlingStrategy.java	(revision 1294)
@@ -42,5 +42,5 @@
      * 
      */
-    private TaskComparator comparator;
+    private TaskInstanceComparator comparator;
 
     /**
@@ -58,5 +58,5 @@
         }
         else {
-            comparator = new TaskComparator(this.consideredEquality);
+            comparator = new TaskInstanceComparator(this.consideredEquality);
         }
     }
@@ -77,5 +77,5 @@
      * @return
      */
-    public TaskComparator getTaskComparator() {
+    public TaskInstanceComparator getTaskComparator() {
         return comparator;
     }
Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskIdentityComparator.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskIdentityComparator.java	(revision 1287)
+++ trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskIdentityComparator.java	(revision 1294)
@@ -21,5 +21,5 @@
  * TODO comment
  */
-class TaskIdentityComparator extends TaskComparator {
+class TaskIdentityComparator extends TaskInstanceComparator {
 
     /**  */
Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskInstanceComparator.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskInstanceComparator.java	(revision 1294)
+++ trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskInstanceComparator.java	(revision 1294)
@@ -0,0 +1,254 @@
+//   Copyright 2012 Georg-August-Universität Göttingen, Germany
+//
+//   Licensed under the Apache License, Version 2.0 (the "License");
+//   you may not use this file except in compliance with the License.
+//   You may obtain a copy of the License at
+//
+//       http://www.apache.org/licenses/LICENSE-2.0
+//
+//   Unless required by applicable law or agreed to in writing, software
+//   distributed under the License is distributed on an "AS IS" BASIS,
+//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//   See the License for the specific language governing permissions and
+//   limitations under the License.
+
+package de.ugoe.cs.autoquest.tasktrees.temporalrelation;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.util.HashMap;
+
+import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality;
+import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEqualityRuleManager;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
+import de.ugoe.cs.autoquest.usageprofiles.SymbolComparator;
+
+/**
+ * TODO comment
+ */
+class TaskInstanceComparator implements SymbolComparator<ITaskInstance> {
+    
+    /**  */
+    private static final long serialVersionUID = 1L;
+    
+    /** */
+    private static final int MAX_BUFFER_SIZE = 2 * 1024 * 1024;
+
+    /** */
+    private TaskEquality minimalNodeEquality;
+
+    /** */
+    private transient Comparer comparer;
+
+    /** */
+    private transient Comparer lexicalComparer;
+
+    /** */
+    private transient HashMap<Long, Boolean> equalityBuffer = new HashMap<Long, Boolean>();
+
+    /** */
+    private transient HashMap<Long, Boolean> lexicalEqualityBuffer;
+
+    /**
+     *
+     */
+    public TaskInstanceComparator(TaskEquality minimalNodeEquality) {
+        this.minimalNodeEquality = minimalNodeEquality;
+        init();
+    }
+
+    /* (non-Javadoc)
+     * @see SymbolComparator#equals(Object, Object)
+     */
+    @Override
+    public boolean equals(ITaskInstance taskInstance1, ITaskInstance taskInstance2) {
+        return equals(taskInstance1.getTask(), taskInstance2.getTask());
+    }        
+
+    /**
+     * 
+     */
+    public boolean equals(ITask task1, ITask task2) {
+        Boolean result;
+        
+        if (task1 != task2) {
+            //if ((task1 instanceof IEventTask) && (task2 instanceof IEventTask)) {
+                long key = ((long) System.identityHashCode(task1)) << 32;
+                key += System.identityHashCode(task2);
+            
+                result = equalityBuffer.get(key);
+            
+                if (result == null) {
+                    result = comparer.compare(task1, task2);
+                    
+                    if (equalityBuffer.size() < MAX_BUFFER_SIZE) {
+                        equalityBuffer.put(key, result);
+                    }
+                }
+            /*}
+            else {
+                result = false;
+            }*/
+        }
+        else {
+            result = true;
+        }
+        
+        return result;
+    }
+
+    /**
+     *
+     */
+    public boolean areLexicallyEqual(ITask task1, ITask task2) {
+        Boolean result;
+        
+        if (task1 != task2) {
+            long key = ((long) System.identityHashCode(task1)) << 32;
+            key += System.identityHashCode(task2);
+            
+            result = lexicalEqualityBuffer.get(key);
+            
+            if (result == null) {
+                result = lexicalComparer.compare(task1, task2);
+                if (equalityBuffer.size() < MAX_BUFFER_SIZE) {
+                    lexicalEqualityBuffer.put(key, result);
+                }
+            }
+        }
+        else {
+            result = true;
+        }
+        
+        return result;
+    }
+    
+    /**
+     * <p>
+     * TODO: comment
+     * </p>
+     *
+     */
+    void clearBuffers() {
+        equalityBuffer.clear();
+        init();
+    }
+    
+    /**
+     * 
+     */
+    private void init() {
+        if (minimalNodeEquality == TaskEquality.LEXICALLY_EQUAL) {
+            comparer = new LexicalComparer();
+        }
+        else if (minimalNodeEquality == TaskEquality.SYNTACTICALLY_EQUAL) {
+            comparer = new SyntacticalComparer();
+        }
+        else if (minimalNodeEquality == TaskEquality.SEMANTICALLY_EQUAL) {
+            comparer = new SemanticalComparer();
+        }
+        else {
+            comparer = new DefaultComparer(this.minimalNodeEquality);
+        }
+        
+        if (minimalNodeEquality == TaskEquality.LEXICALLY_EQUAL) {
+            lexicalComparer = comparer;
+            lexicalEqualityBuffer = equalityBuffer;
+        }
+        else {
+            lexicalComparer = new LexicalComparer();
+            lexicalEqualityBuffer = new HashMap<Long, Boolean>();
+        }
+    }
+    
+    /**
+     * <p>
+     * deserialize this object and reinitialize the buffers
+     * </p>
+     */
+    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
+        in.defaultReadObject();
+        init();
+    }
+
+
+    /**
+     * 
+     */
+    private static interface Comparer {
+        
+        /**
+         * 
+         */
+        boolean compare(ITask task1, ITask task2);
+    }
+
+    /**
+     * 
+     */
+    private static class LexicalComparer implements Comparer {
+        
+        /**
+         * 
+         */
+        public boolean compare(ITask task1, ITask task2) {
+            return TaskEqualityRuleManager.getInstance().areLexicallyEqual(task1, task2);
+        }
+    }
+
+    /**
+     * 
+     */
+    private static class SyntacticalComparer implements Comparer {
+        
+        /**
+         * 
+         */
+        public boolean compare(ITask task1, ITask task2) {
+            return TaskEqualityRuleManager.getInstance().areSyntacticallyEqual(task1, task2);
+        }
+    }
+
+    /**
+     * 
+     */
+    private static class SemanticalComparer implements Comparer {
+        
+        /**
+         * 
+         */
+        public boolean compare(ITask task1, ITask task2) {
+            return TaskEqualityRuleManager.getInstance().areSemanticallyEqual(task1, task2);
+        }
+    }
+
+    /**
+     * 
+     */
+    private static class DefaultComparer implements Comparer {
+        
+        /**
+         * <p>
+         * the minimal task equality two identified sublists need to have to consider them as equal
+         * </p>
+         */
+        private TaskEquality minimalNodeEquality;
+        
+        /**
+         *
+         */
+        public DefaultComparer(TaskEquality minimalNodeEquality) {
+           this.minimalNodeEquality = minimalNodeEquality;
+        }
+        
+        /**
+         * 
+         */
+        public boolean compare(ITask task1, ITask task2) {
+            return TaskEqualityRuleManager.getInstance().areAtLeastEqual
+                (task1, task2, minimalNodeEquality);
+        }
+    }
+
+}
Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskSymbolBucketedMap.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskSymbolBucketedMap.java	(revision 1287)
+++ trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskSymbolBucketedMap.java	(revision 1294)
@@ -27,9 +27,8 @@
 
 import de.ugoe.cs.autoquest.eventcore.IEventType;
-import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
-import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration;
-import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection;
-import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence;
-import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
 import de.ugoe.cs.autoquest.usageprofiles.SymbolMap;
@@ -81,5 +80,5 @@
      * </p>
      */
-    private TaskComparator comparator;
+    private TaskInstanceComparator comparator;
 
     /**
@@ -117,5 +116,5 @@
      * @throws IllegalArgumentException if the provided comparator is null
      */
-    public TaskSymbolBucketedMap(TaskComparator comparator) {
+    public TaskSymbolBucketedMap(TaskInstanceComparator comparator) {
         if (comparator == null) {
             throw new IllegalArgumentException("comparator must not be null");
@@ -400,20 +399,18 @@
         // other = hashCode of name of event type
         
-        ITask task = taskInstance.getTask();
-        
-        if (task instanceof IEventTask) {
+        if (taskInstance instanceof IEventTaskInstance) {
             // event tasks are most likely equal to those of the event type with the same name,
             // Afterwards, they may be equal to iterations, optionals, other event tasks,
             // selections, and finally the rest.
-            IEventType eventType = ((IEventTask) task).getEventType();
+            IEventType eventType = ((IEventTaskInstance) taskInstance).getEvent().getType();
             return new int[] { eventType.getName().hashCode(), 2, 3, 4, 1 };                       
         }
-        else if (task instanceof ISequence) {
+        else if (taskInstance instanceof ISequenceInstance) {
             return new int[] { 0, 2, 3, 1 };                       
         }
-        else if (task instanceof ISelection) {
+        else if (taskInstance instanceof ISelectionInstance) {
             return new int[] { 1, 4, 2, 3 };                       
         }
-        else if (task instanceof IIteration) {
+        else if (taskInstance instanceof IIterationInstance) {
             return new int[] { 2, 1, 4 };                       
         }
Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TemporalRelationshipRuleManager.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TemporalRelationshipRuleManager.java	(revision 1287)
+++ trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TemporalRelationshipRuleManager.java	(revision 1294)
@@ -26,5 +26,4 @@
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
-import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession;
 import de.ugoe.cs.util.console.Console;
@@ -38,9 +37,9 @@
  * between tasks which are not only a major sequence. I.e. through the application of the
  * rules iterations and selections of tasks are detected. Which kind of temporal relations
- * between tasks are detected depends on the {@link ITaskInstanceListScopeRule}s known to
+ * between tasks are detected depends on the {@link ITaskInstanceScopeRule}s known to
  * this class.
  * </p>
- * <p>The class holds references to the appropriate {@link ITaskInstanceListScopeRule}s and calls
- * their {@link ITaskInstanceListScopeRule#apply(ITask, ITaskBuilder, ITaskFactory, boolean)}
+ * <p>The class holds references to the appropriate {@link ITaskInstanceScopeRule}s and calls
+ * their {@link ITaskInstanceScopeRule#apply(ITask, ITaskBuilder, ITaskFactory, boolean)}
  * method for each task in the task tree it is needed for. The general behavior of this class is
  * the following:
@@ -56,5 +55,5 @@
  *   <li>
  *     the class iterates its internal list of rules and calls their
- *     {@link ITaskInstanceListScopeRule#apply(ITask, ITaskBuilder, ITaskFactory, boolean)}
+ *     {@link ITaskInstanceScopeRule#apply(ITask, ITaskBuilder, ITaskFactory, boolean)}
  *     method.
  *   </li>
@@ -115,5 +114,5 @@
      * </p>
      */
-    private ITaskInstanceListScopeRule[] taskScopeRules;
+    private ITaskInstanceScopeRule[] taskScopeRules;
 
     /**
@@ -166,5 +165,5 @@
         //treeScopeRules.add(new DefaultGuiElementSequenceDetectionRule(frameFilter));
 
-        taskScopeRules = new ITaskInstanceListScopeRule[] {
+        taskScopeRules = new ITaskInstanceScopeRule[] {
             //new SequenceOnGuiElementDetectionRule(taskFactory, taskTreeBuilder),
             //new EventSequenceOnSameTargetDetectionRule(taskFactory, taskTreeBuilder),
@@ -262,19 +261,18 @@
      *                     on the recursion depth of calling this method.
      */
-    private int applyRules(ITaskInstanceListScopeRule[] rules,
-                           ITaskInstanceList            taskInstances,
+    private int applyRules(ITaskInstanceScopeRule[] rules,
+                           ITaskInstance                taskInstance,
                            String                       logIndent)
     {
-        Console.traceln(Level.FINER, logIndent + "applying rules for " + taskInstances.size() +
-                        " task instances");
+        Console.traceln(Level.FINER, logIndent + "applying rules on " + taskInstance);
 
         int noOfRuleApplications = 0;
 
-        for (ITaskInstanceListScopeRule rule : rules) {
+        for (ITaskInstanceScopeRule rule : rules) {
             RuleApplicationResult result;
             do {
                 Console.traceln
-                    (Level.FINER, logIndent + "trying rule " + rule + " on " + taskInstances);
-                result = rule.apply(taskInstances);
+                    (Level.FINER, logIndent + "trying rule " + rule + " on " + taskInstance);
+                result = rule.apply(taskInstance);
 
                 if ((result != null) &&
@@ -282,5 +280,5 @@
                 {
                     Console.traceln
-                        (Level.FINE, logIndent + "applied rule " + rule + " on " + taskInstances);
+                        (Level.FINE, logIndent + "applied rule " + rule + " on " + taskInstance);
                     noOfRuleApplications++;
                     
