Changeset 1126


Ignore:
Timestamp:
03/18/13 11:50:04 (11 years ago)
Author:
pharms
Message:
  • extended task tree model with support for optionalities
  • improved performance of task tree handling
  • improved visualization of task trees
Location:
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees
Files:
2 added
7 edited

Legend:

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

    r1114 r1126  
    3434 
    3535    /** 
     36     *  
     37     * @param parent 
     38     * @param i 
     39     */ 
     40    void setChild(ISequence parent, int index, ITaskTreeNode child); 
     41 
     42    /** 
    3643     * @param sequence 
    3744     * @param task 
     
    4552     */ 
    4653    void setChild(IIteration iteration, ITaskTreeNode newChild); 
     54 
     55    /** 
     56     *  
     57     * @param optional 
     58     * @param newChild 
     59     */ 
     60    void setChild(IOptional optional, ITaskTreeNode newChild); 
    4761 
    4862    /** 
     
    6175 
    6276    /** 
     77     * 
     78     * @param parent 
     79     * @param i 
     80     */ 
     81    void replaceChild(ISelection parent, ITaskTreeNode oldChild, ITaskTreeNode newChild); 
     82 
     83    /** 
    6384     *  
    6485     * @param parent 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeifc/ITaskTreeNodeFactory.java

    r1114 r1126  
    5151   * @return 
    5252   */ 
     53  IOptional createNewOptional(); 
     54 
     55  /** 
     56   * 
     57   * @return 
     58   */ 
    5359  ISelection createNewSelection(); 
    5460 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/EventTask.java

    r1113 r1126  
    3939     */ 
    4040    EventTask(IEventType eventType, IEventTarget eventTarget) { 
    41         super(eventType.getName() + "(" + eventTarget + ")"); 
    42         super.setDescription(eventType + " on " + eventTarget); 
     41        super(eventType.toString()); 
     42        super.setDescription("executed on " + eventTarget); 
    4343        this.eventType = eventType; 
    4444        this.eventTarget = eventTarget; 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/Iteration.java

    r1113 r1126  
    4242        // adding more children is not allowed 
    4343        throw new UnsupportedOperationException 
    44           ("iterations may not have a list of children. Use setChild() instead."); 
     44            ("iterations may not have a list of children. Use setChild() instead."); 
    4545    } 
    4646 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskTreeBuilder.java

    r1113 r1126  
    1515package de.ugoe.cs.autoquest.tasktrees.treeimpl; 
    1616 
     17import java.util.List; 
     18 
    1719import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 
     20import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 
    1821import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 
    1922import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
     
    5962    } 
    6063 
     64    /* (non-Javadoc) 
     65     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder#setChild(de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence, int, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode) 
     66     */ 
     67    @Override 
     68    public void setChild(ISequence parent, int index, ITaskTreeNode child) { 
     69        if (!(parent instanceof Sequence)) { 
     70            throw new IllegalArgumentException 
     71                ("illegal type of task tree node provided: " + parent.getClass()); 
     72        } 
     73 
     74        ((TaskTreeNode) parent).removeChild(index); 
     75        addChildInternal(parent, index, child); 
     76    } 
     77 
    6178    /* 
    6279     * (non-Javadoc) 
     
    94111    } 
    95112 
     113    /* (non-Javadoc) 
     114     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder#setChild(de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode) 
     115     */ 
     116    @Override 
     117    public void setChild(IOptional optional, ITaskTreeNode newChild) { 
     118        if (!(optional instanceof Optional)) { 
     119            throw new IllegalArgumentException 
     120                ("illegal type of optional provided: " + optional.getClass()); 
     121        } 
     122 
     123        if (!(newChild instanceof TaskTreeNode)) { 
     124            throw new IllegalArgumentException 
     125                ("illegal type of task tree node provided: " + newChild.getClass()); 
     126        } 
     127 
     128        ((Optional) optional).setChild(newChild); 
     129    } 
     130 
    96131    /* 
    97132     * (non-Javadoc) 
     
    121156        } 
    122157 
    123         for (int i = 0; i < parent.getChildren().size(); i++) { 
    124             if ((parent.getChildren().get(i) == child) || 
    125                 ((parent.getChildren().get(i) != null) && 
    126                  (parent.getChildren().get(i).equals(child)))) 
     158        List<ITaskTreeNode> children = parent.getChildren(); 
     159         
     160        for (int i = 0; i < children.size(); i++) { 
     161            if ((children.get(i) == child) || 
     162                ((children.get(i) != null) && (children.get(i).equals(child)))) 
    127163            { 
    128164                ((TaskTreeNode) parent).removeChild(i); 
     
    132168    } 
    133169 
     170    /* (non-Javadoc) 
     171     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder#replaceChild(de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode) 
     172     */ 
     173    @Override 
     174    public void replaceChild(ISelection parent, ITaskTreeNode oldChild, ITaskTreeNode newChild) { 
     175        if (!(parent instanceof TaskTreeNode)) { 
     176            throw new IllegalArgumentException 
     177                ("illegal type of task tree node provided: " + parent.getClass()); 
     178        } 
     179 
     180        List<ITaskTreeNode> children = parent.getChildren(); 
     181         
     182        for (int i = 0; i < children.size(); i++) { 
     183            if ((children.get(i) == oldChild) || 
     184                ((children.get(i) != null) && (children.get(i).equals(oldChild)))) 
     185            { 
     186                ((TaskTreeNode) parent).removeChild(i); 
     187                ((TaskTreeNode) parent).addChild(i, newChild); 
     188                break; 
     189            } 
     190        } 
     191    } 
     192 
    134193    /* 
    135194     * (non-Javadoc) 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskTreeNode.java

    r1113 r1126  
    1515package de.ugoe.cs.autoquest.tasktrees.treeimpl; 
    1616 
    17 import java.util.ArrayList; 
     17import java.util.Collections; 
     18import java.util.LinkedList; 
    1819import java.util.List; 
    1920 
     
    8586    public synchronized List<ITaskTreeNode> getChildren() { 
    8687        if ((children == null) || (children.size() == 0)) { 
    87             return new ArrayList<ITaskTreeNode>(); 
    88         } 
    89  
    90         return children.subList(0, children.size()); 
     88            return new LinkedList<ITaskTreeNode>(); 
     89        } 
     90 
     91        return Collections.unmodifiableList(children); 
    9192    } 
    9293 
     
    154155    @Override 
    155156    public synchronized String toString() { 
    156         if (children == null) { 
    157             return name + "(" + id + ")"; 
    158         } 
    159         else { 
    160             return name + "(" + id + ", " + children.size() + " children)"; 
    161         } 
     157        StringBuffer result = new StringBuffer(); 
     158        result.append(name); 
     159        result.append('('); 
     160        result.append(id); 
     161         
     162        if (description != null) { 
     163            result.append(", "); 
     164            result.append(description); 
     165        } 
     166         
     167        if (children != null) { 
     168            result.append(", "); 
     169            result.append(children.size()); 
     170            result.append(" children"); 
     171        } 
     172         
     173        result.append(')'); 
     174        return result.toString(); 
    162175    } 
    163176 
     
    177190    synchronized void addChild(ITaskTreeNode child) { 
    178191        if (children == null) { 
    179             children = new ArrayList<ITaskTreeNode>(); 
     192            children = new LinkedList<ITaskTreeNode>(); 
    180193        } 
    181194 
     
    188201    synchronized void addChild(int index, ITaskTreeNode child) { 
    189202        if (children == null) { 
    190             children = new ArrayList<ITaskTreeNode>(); 
     203            children = new LinkedList<ITaskTreeNode>(); 
    191204        } 
    192205 
     
    216229 
    217230            if (children != null) { 
    218                 clone.children = new ArrayList<ITaskTreeNode>(); 
     231                clone.children = new LinkedList<ITaskTreeNode>(); 
    219232 
    220233                for (ITaskTreeNode child : children) { 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskTreeNodeFactory.java

    r1113 r1126  
    1919import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 
    2020import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 
     21import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 
    2122import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 
    2223import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
     
    6364    } 
    6465 
     66    /* (non-Javadoc) 
     67     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNodeFactory#createNewOptional() 
     68     */ 
     69    @Override 
     70    public IOptional createNewOptional() { 
     71        return new Optional(); 
     72    } 
     73 
    6574    /* 
    6675     * (non-Javadoc) 
Note: See TracChangeset for help on using the changeset viewer.