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
Location:
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl
Files:
5 added
5 edited

Legend:

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

    r1255 r1294  
    1515package de.ugoe.cs.autoquest.tasktrees.treeimpl; 
    1616 
    17 import de.ugoe.cs.autoquest.eventcore.IEventTarget; 
    18 import de.ugoe.cs.autoquest.eventcore.IEventType; 
    1917import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 
    2018import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskVisitor; 
     
    3937    /** 
    4038     * <p> 
    41      * the type of the represented event 
    42      * </p>  
    43      */ 
    44     private IEventType eventType; 
    45  
    46     /** 
    47      * <p> 
    48      * the target of the represented event 
    49      * </p>  
    50      */ 
    51     private IEventTarget eventTarget; 
    52  
    53     /** 
    54      * <p> 
    55      * simple constructor initializing this task with an event type and an event target 
     39     * simple constructor initializing this task with a description for the represented events 
    5640     * </p> 
    5741     *  
    58      * @param eventType   the type of the represented event 
    59      * @param eventTarget the target of the represented event 
     42     * @param description a description for the represented events 
    6043     */ 
    61     EventTask(IEventType eventType, IEventTarget eventTarget) { 
    62         super.setDescription(eventType.toString() + " \u21D2 " + eventTarget); 
    63         this.eventType = eventType; 
    64         this.eventTarget = eventTarget; 
    65     } 
    66  
    67     /* (non-Javadoc) 
    68      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask#getEventType() 
    69      */ 
    70     @Override 
    71     public IEventType getEventType() { 
    72         return eventType; 
    73     } 
    74  
    75     /* (non-Javadoc) 
    76      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask#getEventTarget() 
    77      */ 
    78     @Override 
    79     public IEventTarget getEventTarget() { 
    80         return eventTarget; 
     44    EventTask(String description) { 
     45        super.setDescription(description); 
    8146    } 
    8247 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/Task.java

    r1215 r1294  
    1515package de.ugoe.cs.autoquest.tasktrees.treeimpl; 
    1616 
     17import java.util.Collection; 
     18import java.util.Collections; 
     19import java.util.HashSet; 
     20 
    1721import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
     22import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
    1823import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskVisitor; 
    1924 
     
    5661     */ 
    5762    private String description; 
     63     
     64    /** 
     65     * <p> 
     66     * the instances of this task 
     67     * </p> 
     68     */ 
     69    private Collection<ITaskInstance> instances = new HashSet<ITaskInstance>(); 
    5870 
    5971    /** 
     
    97109    public String getDescription() { 
    98110        return description; 
     111    } 
     112 
     113    /* (non-Javadoc) 
     114     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#getInstances() 
     115     */ 
     116    @Override 
     117    public Collection<ITaskInstance> getInstances() { 
     118        return Collections.unmodifiableCollection(instances); 
    99119    } 
    100120 
     
    163183    } 
    164184 
     185    /** 
     186     * <p> 
     187     * internally used to add an instance to this task 
     188     * </p> 
     189     *  
     190     * @param instance the instance belonging to this task 
     191     */ 
     192    void addInstance(ITaskInstance instance) { 
     193        this.instances.add(instance); 
     194    } 
     195     
    165196    /* (non-Javadoc) 
    166197     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#accept(ITaskVisitor) 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskBuilder.java

    r1216 r1294  
    1717import java.util.List; 
    1818 
    19 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 
    2019import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 
     20import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; 
    2121import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 
     22import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance; 
    2223import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 
     24import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; 
    2325import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
     26import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance; 
    2427import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
    2528import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; 
     
    4144 
    4245    /* (non-Javadoc) 
    43      * @see ITaskBuilder#addChild(ITaskInstance,ITaskInstance) 
    44      */ 
    45     @Override 
    46     public void addChild(ITaskInstance parent, ITaskInstance child) throws IllegalArgumentException 
    47     { 
    48         if (!(parent instanceof TaskInstance)) { 
    49             throw new IllegalArgumentException 
    50                 ("illegal type of task instance provided: " + parent.getClass()); 
     46     * @see ITaskBuilder#addChild(ISequenceInstance, ITaskInstance) 
     47     */ 
     48    @Override 
     49    public void addChild(ISequenceInstance instance, ITaskInstance child) 
     50        throws IllegalArgumentException 
     51    { 
     52        if (!(instance instanceof SequenceInstance)) { 
     53            throw new IllegalArgumentException 
     54                ("illegal type of sequence instance provided: " + instance.getClass()); 
    5155        } 
    5256 
    5357        if (!(child instanceof TaskInstance)) { 
    5458            throw new IllegalArgumentException 
    55                 ("illegal type of task instance provided: " + parent.getClass()); 
    56         } 
    57          
    58         // check, that the correct number of children for the distinct types are added 
    59         ITask task = parent.getTask(); 
    60          
    61         if (task instanceof IEventTask) { 
    62             throw new IllegalArgumentException 
    63                 ("can not add children to a task instance of an event task"); 
    64         } 
    65         else if (task instanceof ISelection) { 
    66             if (parent.getChildren().size() > 0) { 
    67                 throw new IllegalArgumentException 
    68                     ("the instance of a selection must have at most one child"); 
     59                ("illegal type of task instance provided: " + child.getClass()); 
     60        } 
     61         
     62        /*IStructuringTemporalRelationship parentTask = 
     63            (IStructuringTemporalRelationship) parent.getTask(); 
     64         
     65        for (ITask parentTaskChild : parentTask.getChildren()) { 
     66            if (parentTaskChild.equals(child.getTask())) { 
     67                foundChildTask = true; 
     68                break; 
    6969            } 
    7070        } 
    71         else if (task instanceof IOptional) { 
    72             if (parent.getChildren().size() > 1) { 
    73                 throw new IllegalArgumentException 
    74                     ("the instance of an optional must have at most one child"); 
    75             } 
    76         } 
    77         /*else if (task instanceof IIteration) { 
    78             for (ITaskInstance childInstance : parent.getChildren()) { 
    79                 if (!childInstance.getTask().equals(child.getTask())) { 
    80                     throw new IllegalArgumentException 
    81                         ("all children of an instance of an iteration must have exactly the " + 
    82                          "same type"); 
    83                 } 
    84             } 
    85         } 
    86          
    87         boolean foundChildTask = false; 
    88         if (parent.getTask() instanceof IStructuringTemporalRelationship) { 
    89             IStructuringTemporalRelationship parentTask = 
    90                 (IStructuringTemporalRelationship) parent.getTask(); 
    91          
    92             for (ITask parentTaskChild : parentTask.getChildren()) { 
    93                 if (parentTaskChild.equals(child.getTask())) { 
    94                     foundChildTask = true; 
    95                     break; 
    96                 } 
    97             } 
    98         } 
    99         else if (parent.getTask() instanceof IMarkingTemporalRelationship) { 
    100             IMarkingTemporalRelationship parentTask = 
    101                 (IMarkingTemporalRelationship) parent.getTask(); 
    102              
    103             foundChildTask = parentTask.getMarkedTask() != null ? 
    104                 parentTask.getMarkedTask().equals(child.getTask()) : false; 
    105         } 
    106          
     71             
    10772        if (!foundChildTask) { 
    10873            throw new IllegalArgumentException 
     
    11176        }*/ 
    11277 
    113         // finally, after all checks are positive, add the child 
    114         ((TaskInstance) parent).addChild(child); 
     78        ((SequenceInstance) instance).addChild(child); 
     79    } 
     80 
     81    /* (non-Javadoc) 
     82     * @see ITaskBuilder#addChild(ISequenceInstance, int, ITaskInstance) 
     83     */ 
     84    public void addChild(ISequenceInstance instance, int index, ITaskInstance child) 
     85        throws IllegalArgumentException 
     86    { 
     87        if (!(instance instanceof SequenceInstance)) { 
     88            throw new IllegalArgumentException 
     89                ("illegal type of sequence instance provided: " + instance.getClass()); 
     90        } 
     91 
     92        if (!(child instanceof TaskInstance)) { 
     93            throw new IllegalArgumentException 
     94                ("illegal type of task instance provided: " + child.getClass()); 
     95        } 
     96         
     97        /*IStructuringTemporalRelationship parentTask = 
     98            (IStructuringTemporalRelationship) parent.getTask(); 
     99         
     100        for (ITask parentTaskChild : parentTask.getChildren()) { 
     101            if (parentTaskChild.equals(child.getTask())) { 
     102                foundChildTask = true; 
     103                break; 
     104            } 
     105        } 
     106             
     107        if (!foundChildTask) { 
     108            throw new IllegalArgumentException 
     109                ("the task of the child instance to be added does not belong to the children " + 
     110                 "of the task of the parent instance"); 
     111        }*/ 
     112 
     113        ((SequenceInstance) instance).addChild(index, child); 
     114    } 
     115 
     116    /* (non-Javadoc) 
     117     * @see ITaskBuilder#addChild(IIterationInstance, ITaskInstance) 
     118     */ 
     119    @Override 
     120    public void addChild(IIterationInstance instance, ITaskInstance child) 
     121        throws IllegalArgumentException 
     122    { 
     123        if (!(instance instanceof IterationInstance)) { 
     124            throw new IllegalArgumentException 
     125                ("illegal type of iteration instance provided: " + instance.getClass()); 
     126        } 
     127 
     128        if (!(child instanceof TaskInstance)) { 
     129            throw new IllegalArgumentException 
     130                ("illegal type of task instance provided: " + child.getClass()); 
     131        } 
     132         
     133        /*IStructuringTemporalRelationship parentTask = 
     134            (IStructuringTemporalRelationship) parent.getTask(); 
     135         
     136        IMarkingTemporalRelationship parentTask = 
     137            (IMarkingTemporalRelationship) parent.getTask(); 
     138             
     139        foundChildTask = parentTask.getMarkedTask() != null ? 
     140            parentTask.getMarkedTask().equals(child.getTask()) : false; 
     141             
     142        if (!foundChildTask) { 
     143            throw new IllegalArgumentException 
     144                ("the task of the child instance to be added does not belong to the children " + 
     145                 "of the task of the parent instance"); 
     146        }*/ 
     147 
     148        ((IterationInstance) instance).addChild(child); 
     149    } 
     150 
     151    /* (non-Javadoc) 
     152     * @see ITaskBuilder#addChild(IIterationInstance, int, ITaskInstance) 
     153     */ 
     154    public void addChild(IIterationInstance instance, int index, ITaskInstance child) 
     155        throws IllegalArgumentException 
     156    { 
     157        if (!(instance instanceof IterationInstance)) { 
     158            throw new IllegalArgumentException 
     159                ("illegal type of iteration instance provided: " + instance.getClass()); 
     160        } 
     161 
     162        if (!(child instanceof TaskInstance)) { 
     163            throw new IllegalArgumentException 
     164                ("illegal type of task instance provided: " + child.getClass()); 
     165        } 
     166         
     167        /*IStructuringTemporalRelationship parentTask = 
     168            (IStructuringTemporalRelationship) parent.getTask(); 
     169         
     170        IMarkingTemporalRelationship parentTask = 
     171            (IMarkingTemporalRelationship) parent.getTask(); 
     172             
     173        foundChildTask = parentTask.getMarkedTask() != null ? 
     174            parentTask.getMarkedTask().equals(child.getTask()) : false; 
     175             
     176        if (!foundChildTask) { 
     177            throw new IllegalArgumentException 
     178                ("the task of the child instance to be added does not belong to the children " + 
     179                 "of the task of the parent instance"); 
     180        }*/ 
     181 
     182        ((IterationInstance) instance).addChild(index, child); 
     183    } 
     184 
     185    /* (non-Javadoc) 
     186     * @see ITaskBuilder#setChild(ISelectionInstance, ITaskInstance) 
     187     */ 
     188    @Override 
     189    public void setChild(ISelectionInstance instance, ITaskInstance child) 
     190        throws IllegalArgumentException 
     191    { 
     192        if (!(instance instanceof SelectionInstance)) { 
     193            throw new IllegalArgumentException 
     194                ("illegal type of sequence instance provided: " + instance.getClass()); 
     195        } 
     196 
     197        if (!(child instanceof TaskInstance)) { 
     198            throw new IllegalArgumentException 
     199                ("illegal type of task instance provided: " + child.getClass()); 
     200        } 
     201         
     202        /*IStructuringTemporalRelationship parentTask = 
     203            (IStructuringTemporalRelationship) parent.getTask(); 
     204         
     205        for (ITask parentTaskChild : parentTask.getChildren()) { 
     206            if (parentTaskChild.equals(child.getTask())) { 
     207                foundChildTask = true; 
     208                break; 
     209            } 
     210        } 
     211             
     212        if (!foundChildTask) { 
     213            throw new IllegalArgumentException 
     214                ("the task of the child instance to be added does not belong to the children " + 
     215                 "of the task of the parent instance"); 
     216        }*/ 
     217 
     218        ((SelectionInstance) instance).setChild(child); 
     219    } 
     220 
     221    /* (non-Javadoc) 
     222     * @see ITaskBuilder#setChild(IOptionalInstance, ITaskInstance) 
     223     */ 
     224    @Override 
     225    public void setChild(IOptionalInstance instance, ITaskInstance child) 
     226        throws IllegalArgumentException 
     227    { 
     228        if (!(instance instanceof OptionalInstance)) { 
     229            throw new IllegalArgumentException 
     230                ("illegal type of optional instance provided: " + instance.getClass()); 
     231        } 
     232 
     233        if (!(child instanceof TaskInstance)) { 
     234            throw new IllegalArgumentException 
     235                ("illegal type of task instance provided: " + child.getClass()); 
     236        } 
     237         
     238        /*IStructuringTemporalRelationship parentTask = 
     239            (IStructuringTemporalRelationship) parent.getTask(); 
     240         
     241        IMarkingTemporalRelationship parentTask = 
     242            (IMarkingTemporalRelationship) parent.getTask(); 
     243             
     244        foundChildTask = parentTask.getMarkedTask() != null ? 
     245            parentTask.getMarkedTask().equals(child.getTask()) : false; 
     246             
     247        if (!foundChildTask) { 
     248            throw new IllegalArgumentException 
     249                ("the task of the child instance to be added does not belong to the children " + 
     250                 "of the task of the parent instance"); 
     251        }*/ 
     252 
     253        ((OptionalInstance) instance).setChild(child); 
    115254    } 
    116255 
     
    134273 
    135274    /* (non-Javadoc) 
     275     * @see ITaskBuilder#addExecutedTask(IUserSession, int, ITaskInstance) 
     276     */ 
     277    public void addExecutedTask(IUserSession session, int index, ITaskInstance taskInstance) { 
     278        if (!(session instanceof UserSession)) { 
     279            throw new IllegalArgumentException 
     280                ("illegal type of session provided: " + session.getClass()); 
     281        } 
     282 
     283        if (!(taskInstance instanceof TaskInstance)) { 
     284            throw new IllegalArgumentException 
     285                ("illegal type of task instance provided: " + taskInstance.getClass()); 
     286        } 
     287         
     288        ((UserSession) session).addExecutedTask(index, taskInstance); 
     289    } 
     290 
     291    /* (non-Javadoc) 
    136292     * @see ITaskBuilder#addTaskInstance(ITaskInstanceList, ITaskInstance) 
    137293     */ 
    138294    @Override 
    139295    public void addTaskInstance(ITaskInstanceList taskInstanceList, ITaskInstance taskInstance) { 
    140         if (taskInstanceList instanceof TaskInstance) { 
    141             ((TaskInstance) taskInstanceList).addChild(taskInstance); 
     296        if (taskInstanceList instanceof SequenceInstance) { 
     297            addChild((SequenceInstance) taskInstanceList, taskInstance); 
     298        } 
     299        else if (taskInstanceList instanceof IterationInstance) { 
     300            addChild((IterationInstance) taskInstanceList, taskInstance); 
    142301        } 
    143302        else if (taskInstanceList instanceof UserSession) { 
    144             ((UserSession) taskInstanceList).addExecutedTask(taskInstance); 
     303            addExecutedTask((UserSession) taskInstanceList, taskInstance); 
    145304        } 
    146305        else { 
     
    158317                                ITaskInstance     taskInstance) 
    159318    { 
    160         if (taskInstanceList instanceof TaskInstance) { 
    161             ((TaskInstance) taskInstanceList).addChild(index, taskInstance); 
     319        if (taskInstanceList instanceof SequenceInstance) { 
     320            addChild((SequenceInstance) taskInstanceList, index, taskInstance); 
     321        } 
     322        else if (taskInstanceList instanceof IterationInstance) { 
     323            addChild((IterationInstance) taskInstanceList, index, taskInstance); 
    162324        } 
    163325        else if (taskInstanceList instanceof UserSession) { 
    164             ((UserSession) taskInstanceList).addExecutedTask(index, taskInstance); 
     326            addExecutedTask((UserSession) taskInstanceList, index, taskInstance); 
    165327        } 
    166328        else { 
     
    178340                                ITaskInstance     taskInstance) 
    179341    { 
    180         if (taskInstanceList instanceof TaskInstance) { 
    181             ((TaskInstance) taskInstanceList).removeChild(index); 
    182             ((TaskInstance) taskInstanceList).addChild(index, taskInstance); 
    183         } 
    184         else if (taskInstanceList instanceof UserSession) { 
    185             ((UserSession) taskInstanceList).removeExecutedTask(index); 
    186             ((UserSession) taskInstanceList).addExecutedTask(index, taskInstance); 
    187         } 
    188         else { 
    189             throw new IllegalArgumentException 
    190                 ("illegal type of task instance list provided: " + taskInstanceList.getClass()); 
    191         } 
     342        removeTaskInstance(taskInstanceList, index); 
     343        addTaskInstance(taskInstanceList, index, taskInstance); 
    192344    } 
    193345 
     
    334486    @Override 
    335487    public void removeTaskInstance(ITaskInstanceList taskInstanceList, int index) { 
    336         if (taskInstanceList instanceof TaskInstance) { 
    337             ((TaskInstance) taskInstanceList).removeChild(index); 
     488        if (taskInstanceList instanceof SequenceInstance) { 
     489            ((SequenceInstance) taskInstanceList).removeChild(index); 
     490        } 
     491        else if (taskInstanceList instanceof IterationInstance) { 
     492            ((IterationInstance) taskInstanceList).removeChild(index); 
    338493        } 
    339494        else if (taskInstanceList instanceof UserSession) { 
     
    369524    } 
    370525 
    371     /* (non-Javadoc) 
    372      * @see ITaskBuilder#setDescription(ITask, java.lang.String) 
    373      */ 
    374     @Override 
    375     public void setDescription(ITask parent, String description) { 
    376         if (!(parent instanceof Task)) { 
    377             throw new IllegalArgumentException 
    378                 ("illegal type of task provided: " + parent.getClass()); 
    379         } 
    380  
    381         ((Task) parent).setDescription(description); 
    382     } 
    383  
    384526    /** 
    385527     * <p> 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskFactory.java

    r1216 r1294  
    1717import java.util.List; 
    1818 
    19 import de.ugoe.cs.autoquest.eventcore.IEventTarget; 
    20 import de.ugoe.cs.autoquest.eventcore.IEventType; 
     19import de.ugoe.cs.autoquest.eventcore.Event; 
    2120import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 
     21import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; 
    2222import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 
     23import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; 
    2324import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 
     25import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance; 
    2426import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 
     27import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; 
    2528import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
    26 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
    27 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
    28 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; 
     29import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance; 
    2930import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; 
    3031import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; 
     
    4344 
    4445    /* (non-Javadoc) 
    45      * @see ITaskFactory#createNewEventTask(IEventType, IEventTarget) 
     46     * @see ITaskFactory#createNewEventTask(String) 
    4647     */ 
    4748    @Override 
    48     public IEventTask createNewEventTask(IEventType eventType, IEventTarget eventTarget) { 
    49         return new EventTask(eventType, eventTarget); 
     49    public IEventTask createNewEventTask(String description) { 
     50        return new EventTask(description); 
    5051    } 
    5152 
     
    8384 
    8485    /* (non-Javadoc) 
    85      * @see ITaskFactory#createNewTaskInstance(ITask) 
     86     * @see ITaskFactory#createNewTaskInstance(IEventTask, Event) 
    8687     */ 
    8788    @Override 
    88     public ITaskInstance createNewTaskInstance(ITask task) { 
    89         return new TaskInstance(task); 
     89    public IEventTaskInstance createNewTaskInstance(IEventTask task, Event event) { 
     90        if (!(task instanceof EventTask)) { 
     91            throw new IllegalArgumentException 
     92                ("illegal type of event task provided: " + task.getClass()); 
     93        } 
     94         
     95        EventTaskInstance instance = new EventTaskInstance(task, event); 
     96        ((EventTask) task).addInstance(instance); 
     97         
     98        return instance; 
    9099    } 
    91100 
    92101    /* (non-Javadoc) 
    93      * @see ITaskFactory#createNewTaskInstanceList() 
     102     * @see ITaskFactory#createNewTaskInstance(ISequence) 
    94103     */ 
    95104    @Override 
    96     public ITaskInstanceList createNewTaskInstanceList() { 
    97         return new TaskInstance(new Sequence()); 
     105    public ISequenceInstance createNewTaskInstance(ISequence sequence) { 
     106        if (!(sequence instanceof Sequence)) { 
     107            throw new IllegalArgumentException 
     108                ("illegal type of sequence provided: " + sequence.getClass()); 
     109        } 
     110         
     111        SequenceInstance instance = new SequenceInstance(sequence); 
     112        ((Sequence) sequence).addInstance(instance); 
     113         
     114        return instance; 
     115    } 
     116 
     117    /* (non-Javadoc) 
     118     * @see ITaskFactory#createNewTaskInstance(IIteration) 
     119     */ 
     120    @Override 
     121    public IIterationInstance createNewTaskInstance(IIteration iteration) { 
     122        if (!(iteration instanceof Iteration)) { 
     123            throw new IllegalArgumentException 
     124                ("illegal type of iteration provided: " + iteration.getClass()); 
     125        } 
     126         
     127        IterationInstance instance = new IterationInstance(iteration); 
     128        ((Iteration) iteration).addInstance(instance); 
     129         
     130        return instance; 
     131    } 
     132 
     133    /* (non-Javadoc) 
     134     * @see ITaskFactory#createNewTaskInstance(IOptional) 
     135     */ 
     136    @Override 
     137    public IOptionalInstance createNewTaskInstance(IOptional optional) { 
     138        if (!(optional instanceof Optional)) { 
     139            throw new IllegalArgumentException 
     140                ("illegal type of optional provided: " + optional.getClass()); 
     141        } 
     142         
     143        OptionalInstance instance = new OptionalInstance(optional); 
     144        ((Optional) optional).addInstance(instance); 
     145         
     146        return instance; 
     147    } 
     148 
     149    /* (non-Javadoc) 
     150     * @see ITaskFactory#createNewTaskInstance(ISelection) 
     151     */ 
     152    @Override 
     153    public ISelectionInstance createNewTaskInstance(ISelection selection) { 
     154        if (!(selection instanceof Selection)) { 
     155            throw new IllegalArgumentException 
     156                ("illegal type of optional provided: " + selection.getClass()); 
     157        } 
     158         
     159        SelectionInstance instance = new SelectionInstance(selection); 
     160        ((Selection) selection).addInstance(instance); 
     161         
     162        return instance; 
    98163    } 
    99164 
  • 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.