Ignore:
Timestamp:
02/21/13 18:39:13 (11 years ago)
Author:
pharms
Message:
  • changed rules to be testable on their own
  • added first version for a task detection rule
  • refactored rules to have a simpler interface
File:
1 edited

Legend:

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

    r993 r1107  
    2020 * @author 2012, last modified by $Author: patrick$ 
    2121 */ 
    22 public class DefaultGuiElementSequenceDetectionRule implements TemporalRelationshipRule { 
    23  
     22class DefaultGuiElementSequenceDetectionRule implements TemporalRelationshipRule { 
     23 
     24    /** 
     25     * <p> 
     26     * the task tree node factory to be used for creating substructures for the temporal 
     27     * relationships identified during rule 
     28     * </p> 
     29     */ 
     30    private ITaskTreeNodeFactory taskTreeNodeFactory; 
     31    /** 
     32     * <p> 
     33     * the task tree builder to be used for creating substructures for the temporal relationships 
     34     * identified during rule application 
     35     * </p> 
     36     */ 
     37    private ITaskTreeBuilder taskTreeBuilder; 
     38     
    2439    /** 
    2540     * <p> 
     
    3146    /** 
    3247     * <p> 
    33      * instantiates the rule without a GUI element filter 
    34      * </p> 
    35      */ 
    36     DefaultGuiElementSequenceDetectionRule() { 
    37         this.guiElementFilter = null; 
    38     } 
    39  
     48     * instantiates the rule with a task tree node factory and builder to be used during rule 
     49     * application but without a GUI element filter 
     50     * </p> 
     51     *  
     52     * @param taskTreeNodeFactory the task tree node factory to be used for creating substructures 
     53     *                            for the temporal relationships identified during rule 
     54     *                            application 
     55     * @param taskTreeBuilder     the task tree builder to be used for creating substructures for 
     56     *                            the temporal relationships identified during rule application 
     57     */ 
     58    DefaultGuiElementSequenceDetectionRule(ITaskTreeNodeFactory taskTreeNodeFactory, 
     59                                           ITaskTreeBuilder     taskTreeBuilder) 
     60    { 
     61        this(null, taskTreeNodeFactory, taskTreeBuilder); 
     62    } 
     63     
    4064    /** 
    4165     * <p> 
     
    4569     * </p> 
    4670     * 
    47      * @param guiElementFilter the GUI element filter to be applied 
    48      */ 
    49     DefaultGuiElementSequenceDetectionRule(List<Class<? extends IGUIElement>> guiElementFilter) { 
     71     * @param guiElementFilter    the GUI element filter to be applied 
     72     * @param taskTreeNodeFactory the task tree node factory to be used for creating substructures 
     73     *                            for the temporal relationships identified during rule 
     74     *                            application 
     75     * @param taskTreeBuilder     the task tree builder to be used for creating substructures for 
     76     *                            the temporal relationships identified during rule application 
     77     */ 
     78    DefaultGuiElementSequenceDetectionRule(List<Class<? extends IGUIElement>> guiElementFilter, 
     79                                           ITaskTreeNodeFactory taskTreeNodeFactory, 
     80                                           ITaskTreeBuilder     taskTreeBuilder) 
     81    { 
    5082        this.guiElementFilter = guiElementFilter; 
     83        this.taskTreeNodeFactory = taskTreeNodeFactory; 
     84        this.taskTreeBuilder = taskTreeBuilder; 
    5185    } 
    5286 
     
    5589     *  
    5690     * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, 
    57      * TaskTreeBuilder, TaskTreeNodeFactory) 
     91     * boolean) 
    5892     */ 
    5993    @Override 
    60     public RuleApplicationResult apply(ITaskTreeNode        parent, 
    61                                        ITaskTreeBuilder     builder, 
    62                                        ITaskTreeNodeFactory nodeFactory, 
    63                                        boolean              finalize) 
    64     { 
     94    public RuleApplicationResult apply(ITaskTreeNode parent, boolean finalize) { 
    6595        if (!(parent instanceof ISequence)) { 
    6696            return null; 
     
    95125        // anything. 
    96126         
    97         RuleApplicationStatus status; 
     127        RuleApplicationStatus status = null; 
    98128        if (initialHierarchyLevel < maxHierarchyDepth) { 
    99             status = generateSubSequences(parent, hierarchies, initialHierarchyLevel, finalize, 
    100                                           builder, nodeFactory, result); 
    101         } 
    102         else { 
     129            status = generateSubSequences 
     130                (parent, hierarchies, initialHierarchyLevel, finalize, result); 
     131        } 
     132         
     133        if (status == null) { 
    103134            status = RuleApplicationStatus.RULE_NOT_APPLIED; 
    104135        } 
     
    121152     * @param maxHierarchyDepth the maximum hierarchy depth that may apply in this application 
    122153     * @param finalize          true, if the application shall be finalized, false else 
    123      * @param builder           the builder to use for generating the tree structure 
    124      * @param nodeFactory       the node factory to use for generating the tree structure 
    125154     * @param result            the result of the rule application to add newly created parent 
    126155     *                          nodes to 
     
    136165                                                       int                     hierarchyLevel, 
    137166                                                       boolean                 finalize, 
    138                                                        ITaskTreeBuilder        builder, 
    139                                                        ITaskTreeNodeFactory    nodeFactory, 
    140167                                                       RuleApplicationResult   result) 
    141168    { 
     
    169196            } 
    170197            else if (nextGuiElementDiffers) { 
    171                 status = condenseSequence(parent, hierarchies, hierarchyLevel, startingIndex, 
    172                                           index - 1, builder, nodeFactory, result); 
     198                status = condenseSequence 
     199                    (parent, hierarchies, hierarchyLevel, startingIndex, index - 1, result); 
    173200 
    174201                if (status != null) { 
     
    195222                status = condenseSequence 
    196223                    (parent, hierarchies, hierarchyLevel, startingIndex, 
    197                      parent.getChildren().size() - 1, builder, nodeFactory, result); 
     224                     parent.getChildren().size() - 1, result); 
    198225            } 
    199226            else if (status != RuleApplicationStatus.RULE_APPLICATION_FINISHED) { 
     
    225252     * @param startIndex     the index of the first child belonging to the subgroup 
    226253     * @param endIndex       the index of the last child belonging to the subgroup 
    227      * @param builder        the builder to use for generating the tree structure 
    228      * @param nodeFactory    the node factory to use for generating the tree structure 
    229254     * @param result         the result of the rule application to add newly created parent nodes to 
    230255     *  
     
    238263                                                   int                     startIndex, 
    239264                                                   int                     endIndex, 
    240                                                    ITaskTreeBuilder        builder, 
    241                                                    ITaskTreeNodeFactory    nodeFactory, 
    242265                                                   RuleApplicationResult   result) 
    243266    { 
     
    247270 
    248271        if (!onlyASingleChildToReduce || !singleChildIsSequence) { 
    249             ISequence sequence = nodeFactory.createNewSequence(); 
     272            ISequence sequence = taskTreeNodeFactory.createNewSequence(); 
    250273             
    251274            List<List<IGUIElement>> subHierarchies = new ArrayList<List<IGUIElement>>(); 
    252275            List<IGUIElement> newHierarchy = 
    253276                hierarchies.get(startIndex).subList(0, hierarchyLevel + 1); 
    254             builder.setDescription(sequence, "interactions on " + 
    255                                    newHierarchy.get(newHierarchy.size() - 1).getStringIdentifier()); 
     277            taskTreeBuilder.setDescription 
     278                (sequence, "interactions on " + 
     279                 newHierarchy.get(newHierarchy.size() - 1).getStringIdentifier()); 
    256280 
    257281            for (int i = startIndex; i <= endIndex; i++) { 
    258                 builder.addChild(sequence, parent.getChildren().get(startIndex)); 
    259                 builder.removeChild((ISequence) parent, startIndex); 
     282                taskTreeBuilder.addChild(sequence, parent.getChildren().get(startIndex)); 
     283                taskTreeBuilder.removeChild((ISequence) parent, startIndex); 
    260284                 
    261285                subHierarchies.add(hierarchies.remove(startIndex)); 
    262286            } 
    263287 
    264             builder.addChild((ISequence) parent, startIndex, sequence); 
     288            taskTreeBuilder.addChild((ISequence) parent, startIndex, sequence); 
    265289             
    266290            hierarchies.add(startIndex, newHierarchy); 
    267291             
    268             generateSubSequences 
    269                 (sequence, subHierarchies, hierarchyLevel + 1, true, builder, nodeFactory, result); 
     292            generateSubSequences(sequence, subHierarchies, hierarchyLevel + 1, true, result); 
    270293 
    271294            result.addNewlyCreatedParentNode(sequence); 
Note: See TracChangeset for help on using the changeset viewer.