Changeset 970 for trunk


Ignore:
Timestamp:
11/08/12 19:54:41 (12 years ago)
Author:
pharms
Message:
  • correction in merging selections of task tree nodes
File:
1 edited

Legend:

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

    r922 r970  
    120120         
    121121         
    122         // to find longer iterations first, start with long sequences 
    123122        SubSequences subSequences = getEqualSubsequences(parent, treeBuilder, nodeFactory); 
    124123 
     
    173172        SubSequences subSequences = null; 
    174173 
     174        // to find longer iterations first, start with long sequences 
    175175        FIND_ITERATION: 
    176176        for (int end = parent.getChildren().size(); end > 0; end--) { 
     
    496496    /** 
    497497     * <p> 
    498      * merges equal selections. This is done through trying to merge each node of selections with 
    499      * each other. For this, the method 
    500      * {@link #mergeEqualNodes(List, ITaskTreeBuilder, ITaskTreeNodeFactory)} is called with a 
    501      * join of the child list of both selections. 
     498     * merges equal selections. This is done by adding those children of the second selection to 
     499     * the first selection that can not be merged with any of the children of the first selection. 
     500     * If a merge is possible and this merge is not a simple selection of the merged children, 
     501     * then the merged child replaces the child of the first selection which was merged. 
    502502     * </p> 
    503503     * 
     
    507507     * @param nodeFactory the node factory that can be used for instantiating task tree nodes 
    508508     *  
    509      * @return the result of the merge which is not null 
     509     * @return the result of the merge which is never null 
    510510     */ 
    511511    private ITaskTreeNode mergeEqualSelections(ISelection            selection1, 
     
    514514                                               ITaskTreeNodeFactory  nodeFactory) 
    515515    { 
    516         ISelection mergeResult = nodeFactory.createNewSelection(); 
    517              
    518         for (int i = 0; i < selection1.getChildren().size(); i++) { 
    519             treeBuilder.addChild(mergeResult, selection1.getChildren().get(i)); 
    520         } 
    521          
     516        ISelection mergeResult = selection1; 
     517         
     518        ITaskTreeNode childToMerge = null; 
     519        ITaskTreeNode mergedChild = null; 
     520         
     521        // check for each child of selection 2 if it is a duplicate of one of the children 
     522        // if selection 1. If not, add it as further child to the merge result, else skip it. 
    522523        for (int i = 0; i < selection2.getChildren().size(); i++) { 
    523             treeBuilder.addChild(mergeResult, selection2.getChildren().get(i)); 
    524         } 
    525          
    526         mergeEqualNodes(mergeResult.getChildren(), treeBuilder, nodeFactory); 
     524            childToMerge = selection2.getChildren().get(i); 
     525            for (int j = 0; j < selection1.getChildren().size(); j++) { 
     526                mergedChild = mergeEqualTasks 
     527                    (selection1.getChildren().get(j), childToMerge, treeBuilder, nodeFactory); 
     528                 
     529                // a merge must not be a selection, except it is one of the children. Otherwise 
     530                // no real merge was done. 
     531                if ((mergedChild != null) && 
     532                    ((!(mergedChild instanceof ISelection)) || 
     533                     (selection1.getChildren().get(j) == mergedChild) || 
     534                     (childToMerge == mergedChild))) 
     535                { 
     536                    // we found a real merge. So replace the original child in selection 1 with 
     537                    // the merged child 
     538                    treeBuilder.removeChild(selection1, selection1.getChildren().get(j)); 
     539                    treeBuilder.addChild(selection1, mergedChild); 
     540                    mergedChild = null; 
     541                    childToMerge = null; 
     542                    break; 
     543                } 
     544            } 
     545             
     546            if (childToMerge != null) { 
     547                treeBuilder.addChild(selection1, childToMerge); 
     548            } 
     549        } 
    527550         
    528551        return mergeResult; 
Note: See TracChangeset for help on using the changeset viewer.