Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/DefaultIterationDetectionRule.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/DefaultIterationDetectionRule.java	(revision 1045)
+++ trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/DefaultIterationDetectionRule.java	(revision 1107)
@@ -61,10 +61,30 @@
  * @author Patrick Harms
  */
-public class DefaultIterationDetectionRule implements TemporalRelationshipRule {
-    
+class DefaultIterationDetectionRule implements TemporalRelationshipRule {
+
+    /**
+     * <p>
+     * the maximum length for iterated sequences
+     * </p>
+     */
     private static final int MAX_LENGTH_OF_ITERATED_SEQUENCE = 50;
     
     /**
      * <p>
+     * the task tree node factory to be used for creating substructures for the temporal
+     * relationships identified during rule
+     * </p>
+     */
+    private ITaskTreeNodeFactory taskTreeNodeFactory;
+    /**
+     * <p>
+     * the task tree builder to be used for creating substructures for the temporal relationships
+     * identified during rule application
+     * </p>
+     */
+    private ITaskTreeBuilder taskTreeBuilder;
+
+    /**
+     * <p>
      * the node equality manager needed for comparing task tree nodes with each other
      * </p>
@@ -87,9 +107,12 @@
      */
     DefaultIterationDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager,
-                                  NodeEquality            minimalNodeEquality)
+                                  NodeEquality            minimalNodeEquality,
+                                  ITaskTreeNodeFactory    taskTreeNodeFactory,
+                                  ITaskTreeBuilder        taskTreeBuilder)
     {
-        super();
         this.nodeEqualityRuleManager = nodeEqualityRuleManager;
         this.minimalNodeEquality = minimalNodeEquality;
+        this.taskTreeNodeFactory = taskTreeNodeFactory;
+        this.taskTreeBuilder = taskTreeBuilder;
     }
 
@@ -97,12 +120,9 @@
      * (non-Javadoc)
      * 
-     * @see TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory)
+     * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode,
+     * boolean)
      */
     @Override
-    public RuleApplicationResult apply(ITaskTreeNode        parent,
-                                       ITaskTreeBuilder     treeBuilder,
-                                       ITaskTreeNodeFactory nodeFactory,
-                                       boolean              finalize)
-    {
+    public RuleApplicationResult apply(ITaskTreeNode parent, boolean finalize) {
         if (!(parent instanceof ISequence)) {
             return null;
@@ -122,12 +142,12 @@
         
         
-        SubSequences subSequences = getEqualSubsequences(parent, treeBuilder, nodeFactory);
+        SubSequences subSequences = getEqualSubsequences(parent);
 
         if (subSequences != null) {
             RuleApplicationResult result = new RuleApplicationResult();
 
-            mergeEqualNodes(subSequences.equalVariants, treeBuilder, nodeFactory);
-            IIteration newIteration = createIterationBasedOnIdentifiedVariants
-                (subSequences, treeBuilder, nodeFactory, result);
+            mergeEqualNodes(subSequences.equalVariants);
+            IIteration newIteration =
+                createIterationBasedOnIdentifiedVariants(subSequences, result);
 
             determineNewlyCreatedParentTasks(parent, newIteration, result);
@@ -135,9 +155,9 @@
             // remove iterated children
             for (int j = subSequences.start; j < subSequences.end; j++) {
-                treeBuilder.removeChild((ISequence) parent, subSequences.start);
+                taskTreeBuilder.removeChild((ISequence) parent, subSequences.start);
             }
 
             // add the new iteration instead
-            treeBuilder.addChild((ISequence) parent, subSequences.start, newIteration);
+            taskTreeBuilder.addChild((ISequence) parent, subSequences.start, newIteration);
 
             result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED);
@@ -161,6 +181,4 @@
      * 
      * @param parent      the parent node in which iterations of children shall be found
-     * @param treeBuilder the tree builder that can be used for connecting task tree nodes
-     * @param nodeFactory the node factory that can be used for instantiating task tree nodes
      * 
      * @return the iterated subsequences identified in a specific part (contains the equal
@@ -168,8 +186,5 @@
      *         subpart in which the sequences were found) 
      */
-    private SubSequences getEqualSubsequences(ITaskTreeNode        parent,
-                                              ITaskTreeBuilder     treeBuilder,
-                                              ITaskTreeNodeFactory nodeFactory)
-    {
+    private SubSequences getEqualSubsequences(ITaskTreeNode parent) {
         SubSequences subSequences = null;
 
@@ -184,6 +199,5 @@
 
                 boolean foundFurtherVariants = findFurtherVariants
-                    (subSequences, parent, start, end, treeBuilder, nodeFactory,
-                     useEqualSublistLengths);
+                    (subSequences, parent, start, end, useEqualSublistLengths);
 
                 if (foundFurtherVariants) {
@@ -247,8 +261,4 @@
      * @param end                    the end index (exclusive) of the current subpart of children
      *                               in which iterations are searched for
-     * @param treeBuilder            the tree builder that can be used for connecting task tree
-     *                               nodes
-     * @param nodeFactory            the node factory that can be used for instantiating task tree
-     *                               nodes
      * @param useEqualSublistLengths true if the sublists to be searched for all need to have the
      *                               same length
@@ -260,6 +270,4 @@
                                         int                  start,
                                         int                  end,
-                                        ITaskTreeBuilder     treeBuilder,
-                                        ITaskTreeNodeFactory nodeFactory,
                                         boolean              useEqualSublistLengths)
     {
@@ -279,8 +287,8 @@
             }
             
-            ISequence furtherVariant = nodeFactory.createNewSequence();
+            ISequence furtherVariant = taskTreeNodeFactory.createNewSequence();
             
             for (int j = start; j < start + childCount; j++) {
-                treeBuilder.addChild(furtherVariant, parent.getChildren().get(j));
+                taskTreeBuilder.addChild(furtherVariant, parent.getChildren().get(j));
             }
             
@@ -305,6 +313,5 @@
                 
                 foundFurtherVariants = findFurtherVariants
-                    (subSequences, parent, start + childCount, end, treeBuilder, nodeFactory,
-                     useEqualSublistLengths);
+                    (subSequences, parent, start + childCount, end, useEqualSublistLengths);
 
                 if (foundFurtherVariants) {
@@ -331,11 +338,6 @@
      *
      * @param nodes       the list of nodes to be merged
-     * @param treeBuilder the tree builder that can be used for connecting task tree nodes
-     * @param nodeFactory the node factory that can be used for instantiating task tree nodes
-     */
-    private void mergeEqualNodes(List<ITaskTreeNode>   nodes,
-                                 ITaskTreeBuilder      treeBuilder,
-                                 ITaskTreeNodeFactory  nodeFactory)
-    {
+     */
+    private void mergeEqualNodes(List<ITaskTreeNode> nodes) {
         int index1 = 0;
         int index2 = 0;
@@ -349,6 +351,5 @@
             while (index2 < nodes.size()) {
                 variant2 = nodes.get(index2);
-                ITaskTreeNode mergedChild =
-                    mergeEqualTasks(variant1, variant2, treeBuilder, nodeFactory);
+                ITaskTreeNode mergedChild = mergeEqualTasks(variant1, variant2);
                 
                 if (mergedChild != null) {
@@ -382,53 +383,42 @@
      * @param node1       the first task to be merged
      * @param node2       the second task to be merged
-     * @param treeBuilder the tree builder that can be used for connecting task tree nodes
-     * @param nodeFactory the node factory that can be used for instantiating task tree nodes
      * 
      * @return the result of the merge
      */
-    private ITaskTreeNode mergeEqualTasks(ITaskTreeNode         node1,
-                                          ITaskTreeNode         node2,
-                                          ITaskTreeBuilder      treeBuilder,
-                                          ITaskTreeNodeFactory  nodeFactory)
-    {
+    private ITaskTreeNode mergeEqualTasks(ITaskTreeNode node1, ITaskTreeNode node2) {
         ITaskTreeNode mergeResult = null;
         
         if ((node1 instanceof ISequence) && (node2 instanceof ISequence)) {
-            mergeResult = mergeEqualSequences
-                ((ISequence) node1, (ISequence) node2, treeBuilder, nodeFactory);
+            mergeResult = mergeEqualSequences((ISequence) node1, (ISequence) node2);
         }
         else if ((node1 instanceof ISelection) && (node2 instanceof ISelection)) {
-            mergeResult = mergeEqualSelections
-                ((ISelection) node1, (ISelection) node2, treeBuilder, nodeFactory);
+            mergeResult = mergeEqualSelections((ISelection) node1, (ISelection) node2);
         }
         else if ((node1 instanceof IIteration) && (node2 instanceof IIteration)) {
-            mergeResult = mergeEqualIterations
-                ((IIteration) node1, (IIteration) node2, treeBuilder, nodeFactory);
+            mergeResult = mergeEqualIterations((IIteration) node1, (IIteration) node2);
         }
         else if (node1 instanceof ISelection) {
-            treeBuilder.addChild((ISelection) node1, node2);
+            taskTreeBuilder.addChild((ISelection) node1, node2);
             mergeResult = node1;
         }
         else if (node2 instanceof ISelection) {
-            treeBuilder.addChild((ISelection) node2, node1);
+            taskTreeBuilder.addChild((ISelection) node2, node1);
             mergeResult = node2;
         }
         else if (node1 instanceof IIteration) {
-            mergeResult = mergeEqualTasks
-                (((IIteration) node1).getChildren().get(0), node2, treeBuilder, nodeFactory);
+            mergeResult = mergeEqualTasks(((IIteration) node1).getChildren().get(0), node2);
             
             if (mergeResult != null) {
-                IIteration iteration = nodeFactory.createNewIteration();
-                treeBuilder.setChild(iteration, mergeResult);
+                IIteration iteration = taskTreeNodeFactory.createNewIteration();
+                taskTreeBuilder.setChild(iteration, mergeResult);
                 mergeResult = iteration;
             }
         }
         else if (node2 instanceof IIteration) {
-            mergeResult = mergeEqualTasks
-                (((IIteration) node2).getChildren().get(0), node1, treeBuilder, nodeFactory);
+            mergeResult = mergeEqualTasks(((IIteration) node2).getChildren().get(0), node1);
             
             if (mergeResult != null) {
-                IIteration iteration = nodeFactory.createNewIteration();
-                treeBuilder.setChild(iteration, mergeResult);
+                IIteration iteration = taskTreeNodeFactory.createNewIteration();
+                taskTreeBuilder.setChild(iteration, mergeResult);
                 mergeResult = iteration;
             }
@@ -443,7 +433,7 @@
 
         if (mergeResult == null) {
-            mergeResult = nodeFactory.createNewSelection();
-            treeBuilder.addChild((ISelection) mergeResult, node1);
-            treeBuilder.addChild((ISelection) mergeResult, node2);
+            mergeResult = taskTreeNodeFactory.createNewSelection();
+            taskTreeBuilder.addChild((ISelection) mergeResult, node1);
+            taskTreeBuilder.addChild((ISelection) mergeResult, node2);
         }
         
@@ -463,26 +453,19 @@
      * @param sequence1   the first sequence to be merged
      * @param sequence2   the second sequence to be merged
-     * @param treeBuilder the tree builder that can be used for connecting task tree nodes
-     * @param nodeFactory the node factory that can be used for instantiating task tree nodes
      * 
      * @return the result of the merge or null if merging was not possible
      */
-    private ISequence mergeEqualSequences(ISequence             sequence1,
-                                          ISequence             sequence2,
-                                          ITaskTreeBuilder      treeBuilder,
-                                          ITaskTreeNodeFactory  nodeFactory)
-    {
+    private ISequence mergeEqualSequences(ISequence sequence1, ISequence sequence2) {
         ISequence mergeResult = null;
         
         if (sequence1.getChildren().size() == sequence2.getChildren().size()) {
-            mergeResult = nodeFactory.createNewSequence();
+            mergeResult = taskTreeNodeFactory.createNewSequence();
             
             for (int i = 0; i < sequence1.getChildren().size(); i++) {
                 ITaskTreeNode mergedNode = mergeEqualTasks
-                    (sequence1.getChildren().get(i), sequence2.getChildren().get(i),
-                     treeBuilder, nodeFactory);
+                    (sequence1.getChildren().get(i), sequence2.getChildren().get(i));
                 
                 if (mergedNode != null) {
-                    treeBuilder.addChild(mergeResult, mergedNode);
+                    taskTreeBuilder.addChild(mergeResult, mergedNode);
                 }
                 else {
@@ -506,14 +489,8 @@
      * @param selection1  the first selection to be merged
      * @param selection2  the second selection to be merged
-     * @param treeBuilder the tree builder that can be used for connecting task tree nodes
-     * @param nodeFactory the node factory that can be used for instantiating task tree nodes
      * 
      * @return the result of the merge which is never null
      */
-    private ITaskTreeNode mergeEqualSelections(ISelection            selection1,
-                                               ISelection            selection2,
-                                               ITaskTreeBuilder      treeBuilder,
-                                               ITaskTreeNodeFactory  nodeFactory)
-    {
+    private ITaskTreeNode mergeEqualSelections(ISelection selection1, ISelection selection2) {
         ISelection mergeResult = selection1;
         
@@ -526,6 +503,5 @@
             childToMerge = selection2.getChildren().get(i);
             for (int j = 0; j < selection1.getChildren().size(); j++) {
-                mergedChild = mergeEqualTasks
-                    (selection1.getChildren().get(j), childToMerge, treeBuilder, nodeFactory);
+                mergedChild = mergeEqualTasks(selection1.getChildren().get(j), childToMerge);
                 
                 // a merge must not be a selection, except it is one of the children. Otherwise
@@ -538,6 +514,6 @@
                     // we found a real merge. So replace the original child in selection 1 with
                     // the merged child
-                    treeBuilder.removeChild(selection1, selection1.getChildren().get(j));
-                    treeBuilder.addChild(selection1, mergedChild);
+                    taskTreeBuilder.removeChild(selection1, selection1.getChildren().get(j));
+                    taskTreeBuilder.addChild(selection1, mergedChild);
                     mergedChild = null;
                     childToMerge = null;
@@ -547,5 +523,5 @@
             
             if (childToMerge != null) {
-                treeBuilder.addChild(selection1, childToMerge);
+                taskTreeBuilder.addChild(selection1, childToMerge);
             }
         }
@@ -563,23 +539,16 @@
      * @param selection1  the first iteration to be merged
      * @param selection2  the second iteration to be merged
-     * @param treeBuilder the tree builder that can be used for connecting task tree nodes
-     * @param nodeFactory the node factory that can be used for instantiating task tree nodes
      * 
      * @return the result of the merge or null if merging is not possible
      */
-    private ITaskTreeNode mergeEqualIterations(IIteration            iteration1,
-                                               IIteration            iteration2,
-                                               ITaskTreeBuilder      treeBuilder,
-                                               ITaskTreeNodeFactory  nodeFactory)
-    {
+    private ITaskTreeNode mergeEqualIterations(IIteration iteration1, IIteration iteration2) {
         ITaskTreeNode mergedChild = mergeEqualTasks
-            (iteration1.getChildren().get(0), iteration2.getChildren().get(0),
-             treeBuilder, nodeFactory);
+            (iteration1.getChildren().get(0), iteration2.getChildren().get(0));
         
         IIteration mergeResult = null;
         
         if (mergedChild != null) {
-            mergeResult = nodeFactory.createNewIteration();
-            treeBuilder.setChild(mergeResult, mergedChild);
+            mergeResult = taskTreeNodeFactory.createNewIteration();
+            taskTreeBuilder.setChild(mergeResult, mergedChild);
         }
         
@@ -598,15 +567,11 @@
      *
      * @param subsequences the identified and already merged equal subsequences
-     * @param treeBuilder  the tree builder that can be used for connecting task tree nodes
-     * @param nodeFactory  the node factory that can be used for instantiating the iteration
      * 
      * @return the resulting iteration
      */
     private IIteration createIterationBasedOnIdentifiedVariants(SubSequences          subsequences,
-                                                                ITaskTreeBuilder      treeBuilder,
-                                                                ITaskTreeNodeFactory  nodeFactory,
                                                                 RuleApplicationResult result)
     {
-        IIteration newIteration = nodeFactory.createNewIteration();
+        IIteration newIteration = taskTreeNodeFactory.createNewIteration();
         result.addNewlyCreatedParentNode(newIteration);
 
@@ -616,10 +581,10 @@
                 // there is only one equal variant and this has only one child. So create an
                 // iteration of this child
-                treeBuilder.setChild
+                taskTreeBuilder.setChild
                     (newIteration, subsequences.equalVariants.get(0).getChildren().get(0));
             }
             else {
                 // there was an iteration of one equal sequence
-                treeBuilder.setChild(newIteration, subsequences.equalVariants.get(0));
+                taskTreeBuilder.setChild(newIteration, subsequences.equalVariants.get(0));
                 result.addNewlyCreatedParentNode(subsequences.equalVariants.get(0));
             }
@@ -628,18 +593,18 @@
             // there are distinct variants of equal subsequences or children --> create an
             // iterated selection
-            ISelection selection = nodeFactory.createNewSelection();
+            ISelection selection = taskTreeNodeFactory.createNewSelection();
             result.addNewlyCreatedParentNode(selection);
 
             for (ITaskTreeNode variant : subsequences.equalVariants) {
                 if (variant.getChildren().size() == 1) {
-                    treeBuilder.addChild(selection, variant.getChildren().get(0));
+                    taskTreeBuilder.addChild(selection, variant.getChildren().get(0));
                 }
                 else {
-                    treeBuilder.addChild(selection, variant);
+                    taskTreeBuilder.addChild(selection, variant);
                     result.addNewlyCreatedParentNode(variant);
                 }
             }
 
-            treeBuilder.setChild(newIteration, selection);
+            taskTreeBuilder.setChild(newIteration, selection);
         }
         
