Ignore:
Timestamp:
08/14/13 17:04:42 (11 years ago)
Author:
pharms
Message:
  • rework of task model to move event instance stuff to task instances
  • introduction of sequence, selection, iteration and optional instances
File:
1 edited

Legend:

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

    r1255 r1294  
    1414 
    1515package de.ugoe.cs.autoquest.tasktrees.treeimpl; 
    16  
    17 import java.util.Collections; 
    18 import java.util.Iterator; 
    19 import java.util.LinkedList; 
    20 import java.util.List; 
    2116 
    2217import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
     
    6459    /** 
    6560     * <p> 
    66      * the children of this task instance which are task instances, as well 
    67      * </p> 
    68      */ 
    69     private List<ITaskInstance> children; 
    70  
    71     /** 
    72      * <p> 
    7361     * instantiated the task instance with the task that is instantiated by the instance. It also 
    7462     * assigns a unique id to the instance using {@link #getNewId()}. 
     
    10290    public ITask getTask() { 
    10391        return task; 
    104     } 
    105  
    106     /* (non-Javadoc) 
    107      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance#getChildren() 
    108      */ 
    109     public synchronized List<ITaskInstance> getChildren() { 
    110         if (children == null) { 
    111             children = new LinkedList<ITaskInstance>(); 
    112         } 
    113  
    114         return Collections.unmodifiableList(children); 
    115     } 
    116  
    117     /* (non-Javadoc) 
    118      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#get(int) 
    119      */ 
    120     @Override 
    121     public ITaskInstance get(int index) { 
    122         if (children == null) { 
    123             throw new IndexOutOfBoundsException(Integer.toString(index)); 
    124         } 
    125         else { 
    126             return children.get(index); 
    127         } 
    128     } 
    129  
    130     /* (non-Javadoc) 
    131      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#size() 
    132      */ 
    133     @Override 
    134     public int size() { 
    135         if (children == null) { 
    136             return 0; 
    137         } 
    138         else { 
    139             return children.size(); 
    140         } 
    141     } 
    142  
    143     /* (non-Javadoc) 
    144      * @see java.lang.Iterable#iterator() 
    145      */ 
    146     @Override 
    147     public Iterator<ITaskInstance> iterator() { 
    148         return getChildren().iterator(); 
    14992    } 
    15093 
     
    203146        try { 
    204147            clone = (TaskInstance) super.clone(); 
    205  
    206             if (children != null) { 
    207                 clone.children = new LinkedList<ITaskInstance>(); 
    208  
    209                 for (ITaskInstance child : children) { 
    210                     clone.children.add(child.clone()); 
    211                 } 
    212             } 
    213  
    214148        } 
    215149        catch (CloneNotSupportedException e) { 
     
    219153 
    220154        return clone; 
    221     } 
    222  
    223     /** 
    224      * <p> 
    225      * used to add a child to this task instance 
    226      * </p> 
    227      *  
    228      * @param child the new child of this instance 
    229      */ 
    230     synchronized void addChild(ITaskInstance child) { 
    231         if (children == null) { 
    232             children = new LinkedList<ITaskInstance>(); 
    233         } 
    234  
    235         children.add(child); 
    236     } 
    237  
    238     /** 
    239      * <p> 
    240      * used to add a child to this task instance at a specific position 
    241      * </p> 
    242      *  
    243      * @param index the position of the new child in the list of children 
    244      * @param child the new child of this instance 
    245      */ 
    246     synchronized void addChild(int index, ITaskInstance child) { 
    247         if (children == null) { 
    248             children = new LinkedList<ITaskInstance>(); 
    249         } 
    250  
    251         children.add(index, child); 
    252     } 
    253  
    254     /** 
    255      * <p> 
    256      * removes a child from this task instance at a specific position 
    257      * </p> 
    258      *  
    259      * @param index the position of the child to be removed 
    260      *  
    261      * @return the child remove from the children of this instance 
    262      */ 
    263     synchronized ITaskInstance removeChild(int index) { 
    264         if (children != null) { 
    265             return children.remove(index); 
    266         } 
    267         else { 
    268             throw new IllegalArgumentException 
    269                 ("this task instance does not have children that can be removed"); 
    270         } 
    271155    } 
    272156 
Note: See TracChangeset for help on using the changeset viewer.