Ignore:
Timestamp:
09/05/14 19:33:12 (10 years ago)
Author:
rkrimmel
Message:

Used Eclipse code cleanup

Location:
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl
Files:
19 edited

Legend:

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

    r1410 r1733  
    2020/** 
    2121 * <p> 
    22  * this is the default implementation of the interface {@link IEventTask}. It does not do anything 
    23  * fancy except implementing the interface. 
    24  * </p>  
     22 * this is the default implementation of the interface {@link IEventTask}. It 
     23 * does not do anything fancy except implementing the interface. 
     24 * </p> 
    2525 * 
    2626 * @author Patrick Harms 
    2727 */ 
    2828class EventTask extends Task implements IEventTask { 
    29      
    30     /** 
    31      * <p> 
    32      * default serial version UID 
    33      * </p> 
    34      */ 
    35     private static final long serialVersionUID = 1L; 
    3629 
    37     /** 
    38      * <p> 
    39      * simple constructor initializing this task with a description for the represented events 
    40      * </p> 
    41      *  
    42      * @param type a type for the represented events 
    43      */ 
    44     EventTask(String type) { 
    45         super(type); 
    46     } 
     30        /** 
     31         * <p> 
     32         * default serial version UID 
     33         * </p> 
     34         */ 
     35        private static final long serialVersionUID = 1L; 
    4736 
    48     /* (non-Javadoc) 
    49      * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.Task#clone() 
    50      */ 
    51     @Override 
    52     public EventTask clone() { 
    53         // Event type and target are unchangeable and do not need to be cloned 
    54         return (EventTask) super.clone(); 
    55     } 
     37        /** 
     38         * <p> 
     39         * simple constructor initializing this task with a description for the 
     40         * represented events 
     41         * </p> 
     42         *  
     43         * @param type 
     44         *            a type for the represented events 
     45         */ 
     46        EventTask(String type) { 
     47                super(type); 
     48        } 
    5649 
    57     /* (non-Javadoc) 
    58      * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.Task#accept(ITaskVisitor) 
    59      */ 
    60     @Override 
    61     public void accept(ITaskVisitor visitor) { 
    62         visitor.visit(this); 
    63     } 
     50        /* 
     51         * (non-Javadoc) 
     52         *  
     53         * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.Task#accept(ITaskVisitor) 
     54         */ 
     55        @Override 
     56        public void accept(ITaskVisitor visitor) { 
     57                visitor.visit(this); 
     58        } 
     59 
     60        /* 
     61         * (non-Javadoc) 
     62         *  
     63         * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.Task#clone() 
     64         */ 
     65        @Override 
     66        public EventTask clone() { 
     67                // Event type and target are unchangeable and do not need to be cloned 
     68                return (EventTask) super.clone(); 
     69        } 
    6470 
    6571} 
  • branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/EventTaskInstance.java

    r1414 r1733  
    2828class EventTaskInstance extends TaskInstance implements IEventTaskInstance { 
    2929 
    30     /** 
    31      * <p> 
    32      * default serial version UID 
    33      * </p> 
    34      */ 
    35     private static final long serialVersionUID = 1L; 
    36      
    37     /** 
    38      * <p> 
    39      * the event represented by this instance 
    40      * </p> 
    41      */ 
    42     private Event event; 
     30        /** 
     31         * <p> 
     32         * default serial version UID 
     33         * </p> 
     34         */ 
     35        private static final long serialVersionUID = 1L; 
    4336 
    44     /** 
    45      * <p> 
    46      * initializes this instance with the respective task model and the represented event 
    47      * </p> 
    48      * 
    49      * @param task  the task of which this is an instance 
    50      * @param event the event represented by this instance 
    51      */ 
    52     EventTaskInstance(IEventTask task, Event event) { 
    53         super(task); 
    54         this.event = event; 
    55     } 
     37        /** 
     38         * <p> 
     39         * the event represented by this instance 
     40         * </p> 
     41         */ 
     42        private final Event event; 
    5643 
    57     /* (non-Javadoc) 
    58      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance#getEvent() 
    59      */ 
    60     @Override 
    61     public Event getEvent() { 
    62         return event; 
    63     } 
     44        /** 
     45         * <p> 
     46         * initializes this instance with the respective task model and the 
     47         * represented event 
     48         * </p> 
     49         * 
     50         * @param task 
     51         *            the task of which this is an instance 
     52         * @param event 
     53         *            the event represented by this instance 
     54         */ 
     55        EventTaskInstance(IEventTask task, Event event) { 
     56                super(task); 
     57                this.event = event; 
     58        } 
    6459 
    65     /* (non-Javadoc) 
    66      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance#getEventTask() 
    67      */ 
    68     @Override 
    69     public IEventTask getEventTask() { 
    70         return (IEventTask) super.getTask(); 
    71     } 
     60        /* 
     61         * (non-Javadoc) 
     62         *  
     63         * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.IEventTaskInstance#clone() 
     64         */ 
     65        @Override 
     66        public synchronized IEventTaskInstance clone() { 
     67                return (IEventTaskInstance) super.clone(); 
     68        } 
    7269 
    73     /* (non-Javadoc) 
    74      * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.IEventTaskInstance#clone() 
    75      */ 
    76     @Override 
    77     public synchronized IEventTaskInstance clone() { 
    78         return (IEventTaskInstance) super.clone(); 
    79     } 
     70        /* 
     71         * (non-Javadoc) 
     72         *  
     73         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance#getEvent() 
     74         */ 
     75        @Override 
     76        public Event getEvent() { 
     77                return event; 
     78        } 
     79 
     80        /* 
     81         * (non-Javadoc) 
     82         *  
     83         * @see 
     84         * de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance#getEventTask() 
     85         */ 
     86        @Override 
     87        public IEventTask getEventTask() { 
     88                return (IEventTask) super.getTask(); 
     89        } 
    8090 
    8191} 
  • branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/Iteration.java

    r1215 r1733  
    2121/** 
    2222 * <p> 
    23  * this is the default implementation of the interface {@link IIteration}. It does not do anything 
    24  * fancy except implementing the interface. 
    25  * </p>  
     23 * this is the default implementation of the interface {@link IIteration}. It 
     24 * does not do anything fancy except implementing the interface. 
     25 * </p> 
    2626 * 
    2727 * @author Patrick Harms 
     
    2929class Iteration extends MarkingTemporalRelationship implements IIteration { 
    3030 
    31     /** 
    32     * <p> 
    33     * default serial version UID 
    34     * </p> 
    35     */ 
    36     private static final long serialVersionUID = 1L; 
     31        /** 
     32        * <p> 
     33        * default serial version UID 
     34        * </p> 
     35        */ 
     36        private static final long serialVersionUID = 1L; 
    3737 
    38     /** 
    39     * <p> 
    40      * simple constructor providing the base class with a human readable name of the type of this 
    41      * task 
    42     * </p> 
    43     */ 
    44     Iteration() { 
    45         super("iteration"); 
    46     } 
     38        /** 
     39        * <p> 
     40         * simple constructor providing the base class with a human readable name of 
     41         * the type of this task 
     42        * </p> 
     43        */ 
     44        Iteration() { 
     45                super("iteration"); 
     46        } 
    4747 
    48     /* (non-Javadoc) 
    49      * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.MarkingTemporalRelationship#setMarkedTask(ITask) 
    50      */ 
    51     @Override 
    52     protected void setMarkedTask(ITask markedTask) { 
    53         if (markedTask instanceof IIteration) { 
    54             throw new IllegalArgumentException 
    55                 ("the marked task of an iteration must not be an iteration"); 
    56         } 
    57         else if (markedTask instanceof IOptional) { 
    58             throw new IllegalArgumentException 
    59                 ("the marked task of an iteration must not be an optional"); 
    60         } 
    61          
    62         super.setMarkedTask(markedTask); 
    63     } 
     48        /* 
     49         * (non-Javadoc) 
     50         *  
     51         * @see 
     52         * de.ugoe.cs.autoquest.tasktrees.treeimpl.MarkingTemporalRelationship#clone 
     53         * () 
     54         */ 
     55        @Override 
     56        public Iteration clone() { 
     57                return (Iteration) super.clone(); 
     58        } 
    6459 
    65     /* (non-Javadoc) 
    66      * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.MarkingTemporalRelationship#clone() 
    67      */ 
    68     @Override 
    69     public Iteration clone() { 
    70         return (Iteration) super.clone(); 
    71     } 
    72      
     60        /* 
     61         * (non-Javadoc) 
     62         *  
     63         * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.MarkingTemporalRelationship# 
     64         * setMarkedTask(ITask) 
     65         */ 
     66        @Override 
     67        protected void setMarkedTask(ITask markedTask) { 
     68                if (markedTask instanceof IIteration) { 
     69                        throw new IllegalArgumentException( 
     70                                        "the marked task of an iteration must not be an iteration"); 
     71                } else if (markedTask instanceof IOptional) { 
     72                        throw new IllegalArgumentException( 
     73                                        "the marked task of an iteration must not be an optional"); 
     74                } 
     75 
     76                super.setMarkedTask(markedTask); 
     77        } 
     78 
    7379} 
  • branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/IterationInstance.java

    r1414 r1733  
    3333class IterationInstance extends TaskInstance implements IIterationInstance { 
    3434 
    35     /** 
    36     * <p> 
    37     * default serial version UID 
    38     * </p> 
    39     */ 
    40     private static final long serialVersionUID = 1L; 
     35        /** 
     36        * <p> 
     37        * default serial version UID 
     38        * </p> 
     39        */ 
     40        private static final long serialVersionUID = 1L; 
    4141 
    42     /** 
    43     * <p> 
    44     * the children of this task instance which are task instances, as well 
    45     * </p> 
    46     */ 
    47     private List<ITaskInstance> children; 
     42        /** 
     43        * <p> 
     44        * the children of this task instance which are task instances, as well 
     45        * </p> 
     46        */ 
     47        private List<ITaskInstance> children; 
    4848 
    49     /** 
    50      * <p> 
    51      * initializes this instance with the respective task model 
    52      * </p> 
    53      * 
    54      * @param task  the task of which this is an instance 
    55      */ 
    56     IterationInstance(IIteration task) { 
    57         super(task); 
    58     } 
     49        /** 
     50         * <p> 
     51         * initializes this instance with the respective task model 
     52         * </p> 
     53         * 
     54         * @param task 
     55         *            the task of which this is an instance 
     56         */ 
     57        IterationInstance(IIteration task) { 
     58                super(task); 
     59        } 
    5960 
    60     /* (non-Javadoc) 
    61      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance#getChildren() 
    62      */ 
    63     public synchronized List<ITaskInstance> getChildren() { 
    64         if (children == null) { 
    65             children = new LinkedList<ITaskInstance>(); 
    66         } 
     61        /** 
     62         * <p> 
     63         * used to add a child to this task instance at a specific position 
     64         * </p> 
     65         *  
     66         * @param index 
     67         *            the position of the new child in the list of children 
     68         * @param child 
     69         *            the new child of this instance 
     70         */ 
     71        synchronized void addChild(int index, ITaskInstance child) { 
     72                if (children == null) { 
     73                        children = new LinkedList<ITaskInstance>(); 
     74                } 
    6775 
    68         return Collections.unmodifiableList(children); 
    69     } 
     76                children.add(index, child); 
     77        } 
    7078 
    71     /* (non-Javadoc) 
    72      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#get(int) 
    73      */ 
    74     @Override 
    75     public ITaskInstance get(int index) { 
    76         if (children == null) { 
    77             throw new IndexOutOfBoundsException(Integer.toString(index)); 
    78         } 
    79         else { 
    80             return children.get(index); 
    81         } 
    82     } 
     79        /** 
     80         * <p> 
     81         * used to add a child to this task instance 
     82         * </p> 
     83         *  
     84         * @param child 
     85         *            the new child of this instance 
     86         */ 
     87        synchronized void addChild(ITaskInstance child) { 
     88                if (children == null) { 
     89                        children = new LinkedList<ITaskInstance>(); 
     90                } 
    8391 
    84     /* (non-Javadoc) 
    85      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#size() 
    86      */ 
    87     @Override 
    88     public int size() { 
    89         if (children == null) { 
    90             return 0; 
    91         } 
    92         else { 
    93             return children.size(); 
    94         } 
    95     } 
     92                children.add(child); 
     93        } 
    9694 
    97     /* (non-Javadoc) 
    98      * @see java.lang.Iterable#iterator() 
    99      */ 
    100     @Override 
    101     public Iterator<ITaskInstance> iterator() { 
    102         return getChildren().iterator(); 
    103     } 
     95        /* 
     96         * (non-Javadoc) 
     97         *  
     98         * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.IIterationInstance#clone() 
     99         */ 
     100        @Override 
     101        public synchronized IIterationInstance clone() { 
     102                final IterationInstance clone = (IterationInstance) super.clone(); 
    104103 
    105     /* (non-Javadoc) 
    106      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance#getIteration() 
    107      */ 
    108     @Override 
    109     public IIteration getIteration() { 
    110         return (IIteration) super.getTask(); 
    111     } 
     104                if (children != null) { 
     105                        clone.children = new LinkedList<ITaskInstance>(); 
    112106 
    113     /* (non-Javadoc) 
    114      * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.IIterationInstance#clone() 
    115      */ 
    116     @Override 
    117     public synchronized IIterationInstance clone() { 
    118         IterationInstance clone = (IterationInstance) super.clone(); 
     107                        for (final ITaskInstance child : children) { 
     108                                clone.children.add(child.clone()); 
     109                        } 
     110                } 
    119111 
    120         if (children != null) { 
    121             clone.children = new LinkedList<ITaskInstance>(); 
     112                return clone; 
     113        } 
    122114 
    123             for (ITaskInstance child : children) { 
    124                 clone.children.add(child.clone()); 
    125             } 
    126         } 
     115        /* 
     116         * (non-Javadoc) 
     117         *  
     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                } else { 
     125                        return children.get(index); 
     126                } 
     127        } 
    127128 
    128         return clone; 
    129     } 
     129        /* 
     130         * (non-Javadoc) 
     131         *  
     132         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance#getChildren() 
     133         */ 
     134        public synchronized List<ITaskInstance> getChildren() { 
     135                if (children == null) { 
     136                        children = new LinkedList<ITaskInstance>(); 
     137                } 
    130138 
    131     /** 
    132      * <p> 
    133      * used to add a child to this task instance 
    134      * </p> 
    135      *  
    136      * @param child the new child of this instance 
    137      */ 
    138     synchronized void addChild(ITaskInstance child) { 
    139         if (children == null) { 
    140             children = new LinkedList<ITaskInstance>(); 
    141         } 
     139                return Collections.unmodifiableList(children); 
     140        } 
    142141 
    143         children.add(child); 
    144     } 
     142        /* 
     143         * (non-Javadoc) 
     144         *  
     145         * @see 
     146         * de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance#getIteration() 
     147         */ 
     148        @Override 
     149        public IIteration getIteration() { 
     150                return (IIteration) super.getTask(); 
     151        } 
    145152 
    146     /** 
    147      * <p> 
    148      * used to add a child to this task instance at a specific position 
    149      * </p> 
    150      *  
    151      * @param index the position of the new child in the list of children 
    152      * @param child the new child of this instance 
    153      */ 
    154     synchronized void addChild(int index, ITaskInstance child) { 
    155         if (children == null) { 
    156             children = new LinkedList<ITaskInstance>(); 
    157         } 
     153        /* 
     154         * (non-Javadoc) 
     155         *  
     156         * @see java.lang.Iterable#iterator() 
     157         */ 
     158        @Override 
     159        public Iterator<ITaskInstance> iterator() { 
     160                return getChildren().iterator(); 
     161        } 
    158162 
    159         children.add(index, child); 
    160     } 
     163        /** 
     164         * <p> 
     165         * removes a child from this task instance at a specific position 
     166         * </p> 
     167         *  
     168         * @param index 
     169         *            the position of the child to be removed 
     170         *  
     171         * @return the child removed from the children of this instance 
     172         */ 
     173        synchronized ITaskInstance removeChild(int index) { 
     174                if (children != null) { 
     175                        return children.remove(index); 
     176                } else { 
     177                        throw new IllegalArgumentException( 
     178                                        "this task instance does not have children that can be removed"); 
     179                } 
     180        } 
    161181 
    162     /** 
    163      * <p> 
    164      * removes a child from this task instance at a specific position 
    165      * </p> 
    166      *  
    167      * @param index the position of the child to be removed 
    168      *  
    169      * @return the child removed from the children of this instance 
    170      */ 
    171     synchronized ITaskInstance removeChild(int index) { 
    172         if (children != null) { 
    173             return children.remove(index); 
    174         } 
    175         else { 
    176             throw new IllegalArgumentException 
    177                 ("this task instance does not have children that can be removed"); 
    178         } 
    179     } 
     182        /* 
     183         * (non-Javadoc) 
     184         *  
     185         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#size() 
     186         */ 
     187        @Override 
     188        public int size() { 
     189                if (children == null) { 
     190                        return 0; 
     191                } else { 
     192                        return children.size(); 
     193                } 
     194        } 
    180195 
    181196} 
  • branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/MarkingTemporalRelationship.java

    r1357 r1733  
    2020/** 
    2121 * <p> 
    22  * this is the default implementation of the interface {@link IMarkingTemporalRelationship}. It 
    23  * does not do anything fancy except implementing the interface. 
     22 * this is the default implementation of the interface 
     23 * {@link IMarkingTemporalRelationship}. It does not do anything fancy except 
     24 * implementing the interface. 
    2425 * </p> 
    2526 *  
    2627 * @author Patrick Harms 
    2728 */ 
    28 abstract class MarkingTemporalRelationship extends Task 
    29     implements IMarkingTemporalRelationship 
    30 { 
     29abstract class MarkingTemporalRelationship extends Task implements 
     30                IMarkingTemporalRelationship { 
    3131 
    32     /** 
    33     * <p> 
    34     * default serial version UID 
    35     * </p> 
    36     */ 
    37     private static final long serialVersionUID = 1L; 
     32        /** 
     33        * <p> 
     34        * default serial version UID 
     35        * </p> 
     36        */ 
     37        private static final long serialVersionUID = 1L; 
    3838 
    39     /** 
    40      * <p> 
    41      * the task marked through this marking temporal relationship 
    42      * </p> 
    43      */ 
    44     private ITask markedTask; 
    45      
    46     /** 
    47      * <p> 
    48      * initializes this temporal relationship with a human readable name 
    49      * </p> 
    50      * 
    51      * @param relationshipType the human readable name of this temporal relationship 
    52      */ 
    53     MarkingTemporalRelationship(String relationshipType) { 
    54         super(relationshipType); 
    55          
    56         if ((relationshipType == null) || ("".equals(relationshipType))) { 
    57             throw new IllegalArgumentException 
    58                 ("the relationship type must be something meaningful"); 
    59         } 
    60     } 
     39        /** 
     40         * <p> 
     41         * the task marked through this marking temporal relationship 
     42         * </p> 
     43         */ 
     44        private ITask markedTask; 
    6145 
    62     /* (non-Javadoc) 
    63      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.IMarkingTemporalRelationship#getMarkedTask() 
    64      */ 
    65     @Override 
    66     public ITask getMarkedTask() { 
    67         return markedTask; 
    68     } 
     46        /** 
     47         * <p> 
     48         * initializes this temporal relationship with a human readable name 
     49         * </p> 
     50         * 
     51         * @param relationshipType 
     52         *            the human readable name of this temporal relationship 
     53         */ 
     54        MarkingTemporalRelationship(String relationshipType) { 
     55                super(relationshipType); 
    6956 
    70     /* (non-Javadoc) 
    71      * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.Task#clone() 
    72      */ 
    73     @Override 
    74     public synchronized MarkingTemporalRelationship clone() { 
    75         MarkingTemporalRelationship clone = null; 
    76         clone = (MarkingTemporalRelationship) super.clone(); 
    77              
    78         if (markedTask != null) { 
    79             clone.markedTask = markedTask.clone(); 
    80         } 
     57                if ((relationshipType == null) || ("".equals(relationshipType))) { 
     58                        throw new IllegalArgumentException( 
     59                                        "the relationship type must be something meaningful"); 
     60                } 
     61        } 
    8162 
    82         return clone; 
    83     } 
     63        /* 
     64         * (non-Javadoc) 
     65         *  
     66         * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.Task#clone() 
     67         */ 
     68        @Override 
     69        public synchronized MarkingTemporalRelationship clone() { 
     70                MarkingTemporalRelationship clone = null; 
     71                clone = (MarkingTemporalRelationship) super.clone(); 
    8472 
    85     /** 
    86      * <p> 
    87      * used to set the marked task 
    88      * </p> 
    89      *  
    90      * @param markedTask the marked task to set 
    91      */ 
    92     protected void setMarkedTask(ITask markedTask) { 
    93         this.markedTask = markedTask; 
    94          
    95         super.setDescription(markedTask.toString()); 
    96     } 
     73                if (markedTask != null) { 
     74                        clone.markedTask = markedTask.clone(); 
     75                } 
     76 
     77                return clone; 
     78        } 
     79 
     80        /* 
     81         * (non-Javadoc) 
     82         *  
     83         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.IMarkingTemporalRelationship# 
     84         * getMarkedTask() 
     85         */ 
     86        @Override 
     87        public ITask getMarkedTask() { 
     88                return markedTask; 
     89        } 
     90 
     91        /** 
     92         * <p> 
     93         * used to set the marked task 
     94         * </p> 
     95         *  
     96         * @param markedTask 
     97         *            the marked task to set 
     98         */ 
     99        protected void setMarkedTask(ITask markedTask) { 
     100                this.markedTask = markedTask; 
     101 
     102                super.setDescription(markedTask.toString()); 
     103        } 
    97104 
    98105} 
  • branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/Optional.java

    r1215 r1733  
    2020/** 
    2121 * <p> 
    22  * this is the default implementation of the interface {@link IOptional}. It does not do anything 
    23  * fancy except implementing the interface. 
    24  * </p>  
     22 * this is the default implementation of the interface {@link IOptional}. It 
     23 * does not do anything fancy except implementing the interface. 
     24 * </p> 
    2525 * 
    2626 * @author Patrick Harms 
     
    2828class Optional extends MarkingTemporalRelationship implements IOptional { 
    2929 
    30     /** 
    31     * <p> 
    32     * default serial version UID 
    33     * </p> 
    34     */ 
    35     private static final long serialVersionUID = 1L; 
     30        /** 
     31        * <p> 
     32        * default serial version UID 
     33        * </p> 
     34        */ 
     35        private static final long serialVersionUID = 1L; 
    3636 
    37     /** 
    38      * <p> 
    39      * simple constructor providing the base class with a human readable name of the type of this 
    40      * task 
    41      * </p> 
    42      */ 
    43     Optional() { 
    44         super("optionality"); 
    45     } 
    46      
    47     /* (non-Javadoc) 
    48      * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.MarkingTemporalRelationship#setMarkedTask(ITask) 
    49      */ 
    50     @Override 
    51     protected void setMarkedTask(ITask markedTask) { 
    52         if (markedTask instanceof IOptional) { 
    53             throw new IllegalArgumentException 
    54                 ("the marked task of an optional must not be an optional"); 
    55         } 
    56          
    57         super.setMarkedTask(markedTask); 
    58     } 
     37        /** 
     38         * <p> 
     39         * simple constructor providing the base class with a human readable name of 
     40         * the type of this task 
     41         * </p> 
     42         */ 
     43        Optional() { 
     44                super("optionality"); 
     45        } 
    5946 
    60     /* (non-Javadoc) 
    61      * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.MarkingTemporalRelationship#clone() 
    62      */ 
    63     @Override 
    64     public Optional clone() { 
    65         return (Optional) super.clone(); 
    66     } 
     47        /* 
     48         * (non-Javadoc) 
     49         *  
     50         * @see 
     51         * de.ugoe.cs.autoquest.tasktrees.treeimpl.MarkingTemporalRelationship#clone 
     52         * () 
     53         */ 
     54        @Override 
     55        public Optional clone() { 
     56                return (Optional) super.clone(); 
     57        } 
     58 
     59        /* 
     60         * (non-Javadoc) 
     61         *  
     62         * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.MarkingTemporalRelationship# 
     63         * setMarkedTask(ITask) 
     64         */ 
     65        @Override 
     66        protected void setMarkedTask(ITask markedTask) { 
     67                if (markedTask instanceof IOptional) { 
     68                        throw new IllegalArgumentException( 
     69                                        "the marked task of an optional must not be an optional"); 
     70                } 
     71 
     72                super.setMarkedTask(markedTask); 
     73        } 
    6774 
    6875} 
  • branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/OptionalInstance.java

    r1414 r1733  
    2929class OptionalInstance extends TaskInstance implements IOptionalInstance { 
    3030 
    31     /** 
    32     * <p> 
    33     * default serial version UID 
    34     * </p> 
    35     */ 
    36     private static final long serialVersionUID = 1L; 
     31        /** 
     32        * <p> 
     33        * default serial version UID 
     34        * </p> 
     35        */ 
     36        private static final long serialVersionUID = 1L; 
    3737 
    38     /** 
    39      * <p> 
    40      * the child of this task instance if any 
    41      * </p> 
    42      */ 
    43     private ITaskInstance child; 
    44      
    45     /** 
    46      * <p> 
    47      * initializes this instance with the respective task model 
    48      * </p> 
    49      * 
    50      * @param task  the task of which this is an instance 
    51      */ 
    52     OptionalInstance(ITask task) { 
    53         super(task); 
    54     } 
     38        /** 
     39         * <p> 
     40         * the child of this task instance if any 
     41         * </p> 
     42         */ 
     43        private ITaskInstance child; 
    5544 
    56     /* (non-Javadoc) 
    57      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance#getChild() 
    58      */ 
    59     @Override 
    60     public ITaskInstance getChild() { 
    61         return child; 
    62     } 
     45        /** 
     46         * <p> 
     47         * initializes this instance with the respective task model 
     48         * </p> 
     49         * 
     50         * @param task 
     51         *            the task of which this is an instance 
     52         */ 
     53        OptionalInstance(ITask task) { 
     54                super(task); 
     55        } 
    6356 
    64     /* (non-Javadoc) 
    65      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance#getOptional() 
    66      */ 
    67     @Override 
    68     public IOptional getOptional() { 
    69         return (IOptional) super.getTask(); 
    70     } 
     57        /* 
     58         * (non-Javadoc) 
     59         *  
     60         * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.ISequenceInstance#clone() 
     61         */ 
     62        @Override 
     63        public synchronized IOptionalInstance clone() { 
     64                final OptionalInstance clone = (OptionalInstance) super.clone(); 
    7165 
    72     /* (non-Javadoc) 
    73      * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.ISequenceInstance#clone() 
    74      */ 
    75     @Override 
    76     public synchronized IOptionalInstance clone() { 
    77         OptionalInstance clone = (OptionalInstance) super.clone(); 
     66                if (child != null) { 
     67                        clone.child = child.clone(); 
     68                } 
    7869 
    79         if (child != null) { 
    80             clone.child = child.clone(); 
    81         } 
     70                return clone; 
     71        } 
    8272 
    83         return clone; 
    84     } 
     73        /* 
     74         * (non-Javadoc) 
     75         *  
     76         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance#getChild() 
     77         */ 
     78        @Override 
     79        public ITaskInstance getChild() { 
     80                return child; 
     81        } 
    8582 
    86     /** 
    87      * <p> 
    88      * used to set the child of this task instance 
    89      * </p> 
    90      *  
    91      * @param child the new child of this instance 
    92      */ 
    93     void setChild(ITaskInstance child) { 
    94         if (child instanceof IOptionalInstance) { 
    95             throw new IllegalArgumentException("the child of an optional can not be an optional"); 
    96         } 
    97          
    98         this.child = child; 
    99     } 
     83        /* 
     84         * (non-Javadoc) 
     85         *  
     86         * @see 
     87         * de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance#getOptional() 
     88         */ 
     89        @Override 
     90        public IOptional getOptional() { 
     91                return (IOptional) super.getTask(); 
     92        } 
     93 
     94        /** 
     95         * <p> 
     96         * used to set the child of this task instance 
     97         * </p> 
     98         *  
     99         * @param child 
     100         *            the new child of this instance 
     101         */ 
     102        void setChild(ITaskInstance child) { 
     103                if (child instanceof IOptionalInstance) { 
     104                        throw new IllegalArgumentException( 
     105                                        "the child of an optional can not be an optional"); 
     106                } 
     107 
     108                this.child = child; 
     109        } 
    100110 
    101111} 
  • branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/Selection.java

    r1404 r1733  
    2020/** 
    2121 * <p> 
    22  * this is the default implementation of the interface {@link ISelection}. It does not do anything 
    23  * fancy except implementing the interface. 
    24  * </p>  
     22 * this is the default implementation of the interface {@link ISelection}. It 
     23 * does not do anything fancy except implementing the interface. 
     24 * </p> 
    2525 * 
    2626 * @author Patrick Harms 
     
    2828class Selection extends StructuringTemporalRelationship implements ISelection { 
    2929 
    30     /** 
    31     * <p> 
    32     * default serial version UID 
    33     * </p> 
    34     */ 
    35     private static final long serialVersionUID = 1L; 
     30        /** 
     31        * <p> 
     32        * default serial version UID 
     33        * </p> 
     34        */ 
     35        private static final long serialVersionUID = 1L; 
    3636 
    37     /** 
    38     * <p> 
    39      * simple constructor providing the base class with a human readable name of the type of this 
    40      * task 
    41     * </p> 
    42     */ 
    43     Selection() { 
    44         super("selection"); 
    45     } 
     37        /** 
     38        * <p> 
     39         * simple constructor providing the base class with a human readable name of 
     40         * the type of this task 
     41        * </p> 
     42        */ 
     43        Selection() { 
     44                super("selection"); 
     45        } 
    4646 
    47     /* (non-Javadoc) 
    48      * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.StructuringTemporalRelationship#clone() 
    49      */ 
    50     @Override 
    51     public Selection clone() { 
    52         return (Selection) super.clone(); 
    53     } 
     47        /* 
     48         * (non-Javadoc) 
     49         *  
     50         * @see 
     51         * de.ugoe.cs.autoquest.tasktrees.treeimpl.StructuringTemporalRelationship 
     52         * #addChild(int,ITask) 
     53         */ 
     54        @Override 
     55        void addChild(int index, ITask newChild) { 
     56                super.addChild(index, newChild); 
     57        } 
    5458 
    55     /* (non-Javadoc) 
    56      * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.StructuringTemporalRelationship#addChild(ITask) 
    57      */ 
    58     @Override 
    59     void addChild(ITask newChild) { 
    60         super.addChild(newChild); 
    61     } 
     59        /* 
     60         * (non-Javadoc) 
     61         *  
     62         * @see 
     63         * de.ugoe.cs.autoquest.tasktrees.treeimpl.StructuringTemporalRelationship 
     64         * #addChild(ITask) 
     65         */ 
     66        @Override 
     67        void addChild(ITask newChild) { 
     68                super.addChild(newChild); 
     69        } 
    6270 
    63     /* (non-Javadoc) 
    64      * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.StructuringTemporalRelationship#addChild(int,ITask) 
    65      */ 
    66     @Override 
    67     void addChild(int index, ITask newChild) { 
    68         super.addChild(index, newChild); 
    69     } 
     71        /* 
     72         * (non-Javadoc) 
     73         *  
     74         * @see 
     75         * de.ugoe.cs.autoquest.tasktrees.treeimpl.StructuringTemporalRelationship 
     76         * #clone() 
     77         */ 
     78        @Override 
     79        public Selection clone() { 
     80                return (Selection) super.clone(); 
     81        } 
    7082 
    7183} 
  • branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/SelectionInstance.java

    r1414 r1733  
    2929class SelectionInstance extends TaskInstance implements ISelectionInstance { 
    3030 
    31     /** 
    32     * <p> 
    33     * default serial version UID 
    34     * </p> 
    35     */ 
    36     private static final long serialVersionUID = 1L; 
     31        /** 
     32        * <p> 
     33        * default serial version UID 
     34        * </p> 
     35        */ 
     36        private static final long serialVersionUID = 1L; 
    3737 
    38     /** 
    39      * <p> 
    40      * the child of this task instance 
    41      * </p> 
    42      */ 
    43     private ITaskInstance child; 
    44      
    45     /** 
    46      * <p> 
    47      * initializes this instance with the respective task model 
    48      * </p> 
    49      * 
    50      * @param task  the task of which this is an instance 
    51      */ 
    52     SelectionInstance(ITask task) { 
    53         super(task); 
    54     } 
     38        /** 
     39         * <p> 
     40         * the child of this task instance 
     41         * </p> 
     42         */ 
     43        private ITaskInstance child; 
    5544 
    56     /* (non-Javadoc) 
    57      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance#getChild() 
    58      */ 
    59     @Override 
    60     public ITaskInstance getChild() { 
    61         return child; 
    62     } 
     45        /** 
     46         * <p> 
     47         * initializes this instance with the respective task model 
     48         * </p> 
     49         * 
     50         * @param task 
     51         *            the task of which this is an instance 
     52         */ 
     53        SelectionInstance(ITask task) { 
     54                super(task); 
     55        } 
    6356 
    64     /* (non-Javadoc) 
    65      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance#getSelection() 
    66      */ 
    67     @Override 
    68     public ISelection getSelection() { 
    69         return (ISelection) super.getTask(); 
    70     } 
     57        /* 
     58         * (non-Javadoc) 
     59         *  
     60         * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.ISequenceInstance#clone() 
     61         */ 
     62        @Override 
     63        public synchronized ISelectionInstance clone() { 
     64                final SelectionInstance clone = (SelectionInstance) super.clone(); 
    7165 
    72     /* (non-Javadoc) 
    73      * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.ISequenceInstance#clone() 
    74      */ 
    75     @Override 
    76     public synchronized ISelectionInstance clone() { 
    77         SelectionInstance clone = (SelectionInstance) super.clone(); 
     66                if (child != null) { 
     67                        clone.child = child.clone(); 
     68                } 
    7869 
    79         if (child != null) { 
    80             clone.child = child.clone(); 
    81         } 
     70                return clone; 
     71        } 
    8272 
    83         return clone; 
    84     } 
     73        /* 
     74         * (non-Javadoc) 
     75         *  
     76         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance#getChild() 
     77         */ 
     78        @Override 
     79        public ITaskInstance getChild() { 
     80                return child; 
     81        } 
    8582 
    86     /** 
    87      * <p> 
    88      * used to set the child of this task instance 
    89      * </p> 
    90      *  
    91      * @param child the new child of this instance 
    92      */ 
    93     void setChild(ITaskInstance child) { 
    94         if (child instanceof ISelectionInstance) { 
    95             throw new IllegalArgumentException("the child of a selection can not be a selection"); 
    96         } 
    97          
    98         this.child = child; 
    99     } 
     83        /* 
     84         * (non-Javadoc) 
     85         *  
     86         * @see 
     87         * de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance#getSelection() 
     88         */ 
     89        @Override 
     90        public ISelection getSelection() { 
     91                return (ISelection) super.getTask(); 
     92        } 
     93 
     94        /** 
     95         * <p> 
     96         * used to set the child of this task instance 
     97         * </p> 
     98         *  
     99         * @param child 
     100         *            the new child of this instance 
     101         */ 
     102        void setChild(ITaskInstance child) { 
     103                if (child instanceof ISelectionInstance) { 
     104                        throw new IllegalArgumentException( 
     105                                        "the child of a selection can not be a selection"); 
     106                } 
     107 
     108                this.child = child; 
     109        } 
    100110 
    101111} 
  • branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/Sequence.java

    r1215 r1733  
    1919/** 
    2020 * <p> 
    21  * this is the default implementation of the interface {@link ISequence}. It does not do anything 
    22  * fancy except implementing the interface. 
    23  * </p>  
     21 * this is the default implementation of the interface {@link ISequence}. It 
     22 * does not do anything fancy except implementing the interface. 
     23 * </p> 
    2424 * 
    2525 * @author Patrick Harms 
    2626 */ 
    2727class Sequence extends StructuringTemporalRelationship implements ISequence { 
    28      
    29     /** 
    30      * <p> 
    31      * default serial version UID 
    32      * </p> 
    33      */ 
    34     private static final long serialVersionUID = 1L; 
    3528 
    36     /** 
    37      * <p> 
    38      * simple constructor providing the base class with a human readable name of the type of this 
    39      * task 
    40      * </p> 
    41      */ 
    42     Sequence() { 
    43         super("sequence"); 
    44     } 
     29        /** 
     30         * <p> 
     31         * default serial version UID 
     32         * </p> 
     33         */ 
     34        private static final long serialVersionUID = 1L; 
    4535 
    46     /* (non-Javadoc) 
    47      * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.StructuringTemporalRelationship#clone() 
    48      */ 
    49     @Override 
    50     public Sequence clone() { 
    51         return (Sequence) super.clone(); 
    52     } 
    53      
     36        /** 
     37         * <p> 
     38         * simple constructor providing the base class with a human readable name of 
     39         * the type of this task 
     40         * </p> 
     41         */ 
     42        Sequence() { 
     43                super("sequence"); 
     44        } 
     45 
     46        /* 
     47         * (non-Javadoc) 
     48         *  
     49         * @see 
     50         * de.ugoe.cs.autoquest.tasktrees.treeimpl.StructuringTemporalRelationship 
     51         * #clone() 
     52         */ 
     53        @Override 
     54        public Sequence clone() { 
     55                return (Sequence) super.clone(); 
     56        } 
     57 
    5458} 
  • branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/SequenceInstance.java

    r1414 r1733  
    3434class SequenceInstance extends TaskInstance implements ISequenceInstance { 
    3535 
    36     /** 
    37     * <p> 
    38     * default serial version UID 
    39     * </p> 
    40     */ 
    41     private static final long serialVersionUID = 1L; 
     36        /** 
     37        * <p> 
     38        * default serial version UID 
     39        * </p> 
     40        */ 
     41        private static final long serialVersionUID = 1L; 
    4242 
    43     /** 
    44     * <p> 
    45     * the children of this task instance which are task instances, as well 
    46     * </p> 
    47     */ 
    48     private List<ITaskInstance> children; 
     43        /** 
     44        * <p> 
     45        * the children of this task instance which are task instances, as well 
     46        * </p> 
     47        */ 
     48        private List<ITaskInstance> children; 
    4949 
    50     /** 
    51      * <p> 
    52      * initializes this instance with the respective task model 
    53      * </p> 
    54      * 
    55      * @param task  the task of which this is an instance 
    56      */ 
    57     SequenceInstance(ISequence task) { 
    58         super(task); 
    59     } 
     50        /** 
     51         * <p> 
     52         * initializes this instance with the respective task model 
     53         * </p> 
     54         * 
     55         * @param task 
     56         *            the task of which this is an instance 
     57         */ 
     58        SequenceInstance(ISequence task) { 
     59                super(task); 
     60        } 
    6061 
    61     /* (non-Javadoc) 
    62      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance#getChildren() 
    63      */ 
    64     public synchronized List<ITaskInstance> getChildren() { 
    65         if (children == null) { 
    66             children = new LinkedList<ITaskInstance>(); 
    67         } 
     62        /** 
     63         * <p> 
     64         * used to add a child to this task instance at a specific position 
     65         * </p> 
     66         *  
     67         * @param index 
     68         *            the position of the new child in the list of children 
     69         * @param child 
     70         *            the new child of this instance 
     71         */ 
     72        synchronized void addChild(int index, ITaskInstance child) { 
     73                if (children == null) { 
     74                        children = new LinkedList<ITaskInstance>(); 
     75                } 
    6876 
    69         return Collections.unmodifiableList(children); 
    70     } 
     77                children.add(index, child); 
     78        } 
    7179 
    72     /* (non-Javadoc) 
    73      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#get(int) 
    74      */ 
    75     @Override 
    76     public ITaskInstance get(int index) { 
    77         if (children == null) { 
    78             throw new IndexOutOfBoundsException(Integer.toString(index)); 
    79         } 
    80         else { 
    81             return children.get(index); 
    82         } 
    83     } 
     80        /** 
     81         * <p> 
     82         * used to add a child to this task instance 
     83         * </p> 
     84         *  
     85         * @param child 
     86         *            the new child of this instance 
     87         */ 
     88        synchronized void addChild(ITaskInstance child) { 
     89                if (children == null) { 
     90                        children = new LinkedList<ITaskInstance>(); 
     91                } 
    8492 
    85     /* (non-Javadoc) 
    86      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#size() 
    87      */ 
    88     @Override 
    89     public int size() { 
    90         if (children == null) { 
    91             return 0; 
    92         } 
    93         else { 
    94             return children.size(); 
    95         } 
    96     } 
     93                children.add(child); 
     94        } 
    9795 
    98     /* (non-Javadoc) 
    99      * @see java.lang.Iterable#iterator() 
    100      */ 
    101     @Override 
    102     public Iterator<ITaskInstance> iterator() { 
    103         return getChildren().iterator(); 
    104     } 
     96        /* 
     97         * (non-Javadoc) 
     98         *  
     99         * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.ISequenceInstance#clone() 
     100         */ 
     101        @Override 
     102        public synchronized ISequenceInstance clone() { 
     103                final SequenceInstance clone = (SequenceInstance) super.clone(); 
    105104 
    106     /* (non-Javadoc) 
    107      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance#getSequence() 
    108      */ 
    109     @Override 
    110     public ISequence getSequence() { 
    111         return (ISequence) super.getTask(); 
    112     } 
     105                if (children != null) { 
     106                        clone.children = new LinkedList<ITaskInstance>(); 
    113107 
    114     /* (non-Javadoc) 
    115      * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.ISequenceInstance#clone() 
    116      */ 
    117     @Override 
    118     public synchronized ISequenceInstance clone() { 
    119         SequenceInstance clone = (SequenceInstance) super.clone(); 
     108                        for (final ITaskInstance child : children) { 
     109                                clone.children.add(child.clone()); 
     110                        } 
     111                } 
    120112 
    121         if (children != null) { 
    122             clone.children = new LinkedList<ITaskInstance>(); 
     113                return clone; 
     114        } 
    123115 
    124             for (ITaskInstance child : children) { 
    125                 clone.children.add(child.clone()); 
    126             } 
    127         } 
     116        /* 
     117         * (non-Javadoc) 
     118         *  
     119         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#get(int) 
     120         */ 
     121        @Override 
     122        public ITaskInstance get(int index) { 
     123                if (children == null) { 
     124                        throw new IndexOutOfBoundsException(Integer.toString(index)); 
     125                } else { 
     126                        return children.get(index); 
     127                } 
     128        } 
    128129 
    129         return clone; 
    130     } 
     130        /* 
     131         * (non-Javadoc) 
     132         *  
     133         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance#getChildren() 
     134         */ 
     135        public synchronized List<ITaskInstance> getChildren() { 
     136                if (children == null) { 
     137                        children = new LinkedList<ITaskInstance>(); 
     138                } 
    131139 
    132     /** 
    133      * <p> 
    134      * used to add a child to this task instance 
    135      * </p> 
    136      *  
    137      * @param child the new child of this instance 
    138      */ 
    139     synchronized void addChild(ITaskInstance child) { 
    140         if (children == null) { 
    141             children = new LinkedList<ITaskInstance>(); 
    142         } 
     140                return Collections.unmodifiableList(children); 
     141        } 
    143142 
    144         children.add(child); 
    145     } 
     143        /* 
     144         * (non-Javadoc) 
     145         *  
     146         * @see 
     147         * de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance#getSequence() 
     148         */ 
     149        @Override 
     150        public ISequence getSequence() { 
     151                return (ISequence) super.getTask(); 
     152        } 
    146153 
    147     /** 
    148      * <p> 
    149      * used to add a child to this task instance at a specific position 
    150      * </p> 
    151      *  
    152      * @param index the position of the new child in the list of children 
    153      * @param child the new child of this instance 
    154      */ 
    155     synchronized void addChild(int index, ITaskInstance child) { 
    156         if (children == null) { 
    157             children = new LinkedList<ITaskInstance>(); 
    158         } 
     154        /* 
     155         * (non-Javadoc) 
     156         *  
     157         * @see java.lang.Iterable#iterator() 
     158         */ 
     159        @Override 
     160        public Iterator<ITaskInstance> iterator() { 
     161                return getChildren().iterator(); 
     162        } 
    159163 
    160         children.add(index, child); 
    161     } 
     164        /** 
     165         * <p> 
     166         * removes a child from this task instance at a specific position 
     167         * </p> 
     168         *  
     169         * @param index 
     170         *            the position of the child to be removed 
     171         *  
     172         * @return the child removed from the children of this instance 
     173         */ 
     174        synchronized ITaskInstance removeChild(int index) { 
     175                if (children != null) { 
     176                        return children.remove(index); 
     177                } else { 
     178                        throw new IllegalArgumentException( 
     179                                        "this task instance does not have children that can be removed"); 
     180                } 
     181        } 
    162182 
    163     /** 
    164      * <p> 
    165      * removes a child from this task instance at a specific position 
    166      * </p> 
    167      *  
    168      * @param index the position of the child to be removed 
    169      *  
    170      * @return the child removed from the children of this instance 
    171      */ 
    172     synchronized ITaskInstance removeChild(int index) { 
    173         if (children != null) { 
    174             return children.remove(index); 
    175         } 
    176         else { 
    177             throw new IllegalArgumentException 
    178                 ("this task instance does not have children that can be removed"); 
    179         } 
    180     } 
     183        /* 
     184         * (non-Javadoc) 
     185         *  
     186         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#size() 
     187         */ 
     188        @Override 
     189        public int size() { 
     190                if (children == null) { 
     191                        return 0; 
     192                } else { 
     193                        return children.size(); 
     194                } 
     195        } 
    181196 
    182197} 
  • branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/StructuringTemporalRelationship.java

    r1357 r1733  
    2323/** 
    2424 * <p> 
    25  * this is the default implementation of the interface {@link IStructuringTemporalRelationship}. It 
    26  * does not do anything fancy except implementing the interface. 
     25 * this is the default implementation of the interface 
     26 * {@link IStructuringTemporalRelationship}. It does not do anything fancy 
     27 * except implementing the interface. 
    2728 * </p> 
    2829 *  
    2930 * @author Patrick Harms 
    3031 */ 
    31 abstract class StructuringTemporalRelationship extends Task 
    32     implements IStructuringTemporalRelationship 
    33 { 
     32abstract class StructuringTemporalRelationship extends Task implements 
     33                IStructuringTemporalRelationship { 
    3434 
    35     /** 
    36      * <p> 
    37      * default serial version UID 
    38      * </p> 
    39      */ 
    40     private static final long serialVersionUID = 1L; 
    41      
    42     /** 
    43      * <p> 
    44      * the list of children of this temporal relationship 
    45      * </p> 
    46      */ 
    47     private List<ITask> children = new LinkedList<ITask>(); 
     35        /** 
     36         * <p> 
     37         * default serial version UID 
     38         * </p> 
     39         */ 
     40        private static final long serialVersionUID = 1L; 
    4841 
    49     /** 
    50      * <p> 
    51      * initializes this temporal relationship with a human readable name 
    52      * </p> 
    53      * 
    54      * @param relationshipType the human readable name of this temporal relationship 
    55      */ 
    56     StructuringTemporalRelationship(String relationshipType) { 
    57         super(relationshipType); 
    58          
    59         if ((relationshipType == null) || ("".equals(relationshipType))) { 
    60             throw new IllegalArgumentException 
    61                 ("the relationship type must be something meaningful"); 
    62         } 
    63     } 
     42        /** 
     43         * <p> 
     44         * the list of children of this temporal relationship 
     45         * </p> 
     46         */ 
     47        private List<ITask> children = new LinkedList<ITask>(); 
    6448 
    65     /* (non-Javadoc) 
    66      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.IStructuringTemporalRelationship#getChildren() 
    67      */ 
    68     @Override 
    69     public List<ITask> getChildren() { 
    70         return children; 
    71     } 
     49        /** 
     50         * <p> 
     51         * initializes this temporal relationship with a human readable name 
     52         * </p> 
     53         * 
     54         * @param relationshipType 
     55         *            the human readable name of this temporal relationship 
     56         */ 
     57        StructuringTemporalRelationship(String relationshipType) { 
     58                super(relationshipType); 
    7259 
    73     /* (non-Javadoc) 
    74      * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.Task#clone() 
    75      */ 
    76     @Override 
    77     public synchronized StructuringTemporalRelationship clone() { 
    78         StructuringTemporalRelationship clone = null; 
    79         clone = (StructuringTemporalRelationship) super.clone(); 
    80              
    81         clone.children = new LinkedList<ITask>(); 
    82          
    83         for (ITask child : this.children) { 
    84             clone.children.add(child.clone()); 
    85         } 
     60                if ((relationshipType == null) || ("".equals(relationshipType))) { 
     61                        throw new IllegalArgumentException( 
     62                                        "the relationship type must be something meaningful"); 
     63                } 
     64        } 
    8665 
    87         return clone; 
    88     } 
     66        /** 
     67         * <p> 
     68         * used to add a new child to this temporal relationship at a specific 
     69         * position. 
     70         * </p> 
     71         * 
     72         * @param index 
     73         *            the index of the new child to be added. 
     74         * @param newChild 
     75         *            the new child to be added 
     76         */ 
     77        void addChild(int index, ITask newChild) { 
     78                children.add(index, newChild); 
     79        } 
    8980 
    90     /** 
    91      * <p> 
    92      * used to add a new child to this temporal relationship. 
    93      * </p> 
    94      * 
    95      * @param newChild the new child to be added 
    96      */ 
    97     void addChild(ITask newChild) { 
    98         children.add(newChild); 
    99     } 
     81        /** 
     82         * <p> 
     83         * used to add a new child to this temporal relationship. 
     84         * </p> 
     85         * 
     86         * @param newChild 
     87         *            the new child to be added 
     88         */ 
     89        void addChild(ITask newChild) { 
     90                children.add(newChild); 
     91        } 
    10092 
    101     /** 
    102      * <p> 
    103      * used to add a new child to this temporal relationship at a specific position. 
    104      * </p> 
    105      * 
    106      * @param index    the index of the new child to be added. 
    107      * @param newChild the new child to be added 
    108      */ 
    109     void addChild(int index, ITask newChild) { 
    110         children.add(index, newChild); 
    111     } 
    112      
    113     /** 
    114      * <p> 
    115      * removes a child from this temporal relationship at a specific position. 
    116      * </p> 
    117      * 
    118      * @param index the index of the child to be removed. 
    119      */ 
    120     void removeChild(int index) { 
    121         children.remove(index); 
    122     } 
     93        /* 
     94         * (non-Javadoc) 
     95         *  
     96         * @see de.ugoe.cs.autoquest.tasktrees.treeimpl.Task#clone() 
     97         */ 
     98        @Override 
     99        public synchronized StructuringTemporalRelationship clone() { 
     100                StructuringTemporalRelationship clone = null; 
     101                clone = (StructuringTemporalRelationship) super.clone(); 
     102 
     103                clone.children = new LinkedList<ITask>(); 
     104 
     105                for (final ITask child : this.children) { 
     106                        clone.children.add(child.clone()); 
     107                } 
     108 
     109                return clone; 
     110        } 
     111 
     112        /* 
     113         * (non-Javadoc) 
     114         *  
     115         * @see 
     116         * de.ugoe.cs.autoquest.tasktrees.treeifc.IStructuringTemporalRelationship 
     117         * #getChildren() 
     118         */ 
     119        @Override 
     120        public List<ITask> getChildren() { 
     121                return children; 
     122        } 
     123 
     124        /** 
     125         * <p> 
     126         * removes a child from this temporal relationship at a specific position. 
     127         * </p> 
     128         * 
     129         * @param index 
     130         *            the index of the child to be removed. 
     131         */ 
     132        void removeChild(int index) { 
     133                children.remove(index); 
     134        } 
    123135} 
  • branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/Task.java

    r1400 r1733  
    3232/** 
    3333 * <p> 
    34  * this is the default implementation of the interface {@link ITask}. It 
    35  * does not do anything fancy except implementing the interface. 
     34 * this is the default implementation of the interface {@link ITask}. It does 
     35 * not do anything fancy except implementing the interface. 
    3636 * </p> 
    3737 *  
     
    4040abstract class Task implements ITask { 
    4141 
    42     /** 
    43      * <p> 
    44      * default serial version UID 
    45      * </p> 
    46      */ 
    47     private static final long serialVersionUID = 1L; 
    48  
    49     /** 
    50      * <p> 
    51      * used as a counter to generate new ids for each newly created task. May overflow. 
    52      * </p> 
    53      */ 
    54     private static int temporalId = 0; 
    55  
    56     /** 
    57      * <p> 
    58      * the id of the task (unique throughout the system as long as {@link #temporalId} does not 
    59      * overflow. 
    60      * </p> 
    61      */ 
    62     private int id; 
    63      
    64     /** 
    65      * <p> 
    66      * a human readable type of the task (used for visualization purposes) 
    67      * </p> 
    68      */ 
    69     private String type; 
    70  
    71     /** 
    72      * <p> 
    73      * a human readable description of the task 
    74      * </p> 
    75      */ 
    76     private String description; 
    77      
    78     /** 
    79      * <p> 
    80      * the instances of this task 
    81      * </p> 
    82      */ 
    83     private Collection<ITaskInstance> instances = new HashSet<ITaskInstance>(); 
    84      
    85     /** 
    86      * <p> 
    87      * the execution variants of this task 
    88      * </p> 
    89      */ 
    90     private Collection<Collection<ITaskInstance>> executionVariants; 
    91  
    92     /** 
    93      * <p> 
    94      * constructs a new task with a new id. The id is generated using the {@link #getNewId()} 
    95      * method 
    96      * </p> 
    97      *  
    98      * @param type the human readable type of the task 
    99      *  
    100      * @throws IllegalArgumentException in the case the provided type is null 
    101      */ 
    102     Task(String type) { 
    103         this.id = getNewId(); 
    104         this.type = type; 
    105          
    106         if (type == null) { 
    107             throw new IllegalArgumentException("type must not be null"); 
    108         } 
    109     } 
    110  
    111     /** 
    112      * <p> 
    113      * creates a new id for a task using {@link #temporalId} by incrementing it an returning its 
    114      * current value. Resets the counter if {@link Integer.MAX_VALUE} is reached. 
    115      * </p> 
    116      *  
    117      * @return a new unique id for a task as long as {@link #temporalId} does not overflow 
    118      */ 
    119     private static synchronized int getNewId() { 
    120         if (temporalId == Integer.MAX_VALUE) { 
    121             temporalId = 0; 
    122         } 
    123  
    124         return temporalId++; 
    125     } 
    126  
    127     /* (non-Javadoc) 
    128      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#geId() 
    129      */ 
    130     @Override 
    131     public int getId() { 
    132         return id; 
    133     } 
    134  
    135     /* (non-Javadoc) 
    136      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#getType() 
    137      */ 
    138     @Override 
    139     public String getType() { 
    140         return type; 
    141     } 
    142  
    143     /* (non-Javadoc) 
    144      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#getDescription() 
    145      */ 
    146     @Override 
    147     public String getDescription() { 
    148         return description; 
    149     } 
    150  
    151     /* (non-Javadoc) 
    152      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#getInstances() 
    153      */ 
    154     @Override 
    155     public Collection<ITaskInstance> getInstances() { 
    156         return Collections.unmodifiableCollection(instances); 
    157     } 
    158  
    159     /* (non-Javadoc) 
    160      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#getExecutionVariants() 
    161      */ 
    162     @Override 
    163     public synchronized Collection<Collection<ITaskInstance>> getExecutionVariants() { 
    164         if (executionVariants == null) { 
    165             executionVariants = new LinkedList<Collection<ITaskInstance>>(); 
    166             determineExecutionVariants(executionVariants); 
    167         } 
    168          
    169         return executionVariants; 
    170     } 
    171  
    172     /* (non-Javadoc) 
    173      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#equals(ITask) 
    174      */ 
    175     @Override 
    176     public final boolean equals(ITask task) { 
    177         // tasks are only equal if they are identical or if they have the same id 
    178         // (may happen, if they are cloned) 
    179         return (this == task) || (this.hashCode() == task.hashCode()); 
    180     } 
    181  
    182     /* (non-Javadoc) 
    183      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#hashCode() 
    184      */ 
    185     @Override 
    186     public synchronized int hashCode() { 
    187         return id; 
    188     } 
    189  
    190     /* (non-Javadoc) 
    191      * @see java.lang.Object#toString() 
    192      */ 
    193     @Override 
    194     public synchronized String toString() { 
    195         StringBuffer result = new StringBuffer(); 
    196         result.append(type); 
    197         result.append(" #"); 
    198         result.append(id); 
    199          
    200         if (description != null) { 
    201             result.append(" ("); 
    202             result.append(description); 
    203             result.append(')'); 
    204         } 
    205          
    206         return result.toString(); 
    207     } 
    208  
    209     /* (non-Javadoc) 
    210      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#clone() 
    211      */ 
    212     @Override 
    213     public synchronized ITask clone() { 
    214         Task clone = null; 
    215         try { 
    216             clone = (Task) super.clone(); 
    217         } 
    218         catch (CloneNotSupportedException e) { 
    219             // this should never happen. Therefore simply dump the exception 
    220             e.printStackTrace(); 
    221         } 
    222  
    223         return clone; 
    224     } 
    225  
    226     /** 
    227      * <p> 
    228      * internally used to set the human readable description of the task 
    229      * </p> 
    230      *  
    231      * @param description the new human readable description of the task 
    232      */ 
    233     void setDescription(String description) { 
    234         this.description = description; 
    235     } 
    236  
    237     /** 
    238      * <p> 
    239      * internally used to remove an instance from this task 
    240      * </p> 
    241      *  
    242      * @param instance the instance to be removed from this task 
    243      */ 
    244     synchronized void removeInstance(ITaskInstance instance) { 
    245         this.instances.remove(instance); 
    246         this.executionVariants = null; 
    247     } 
    248  
    249     /** 
    250      * <p> 
    251      * internally used to add an instance to this task 
    252      * </p> 
    253      *  
    254      * @param instance the instance belonging to this task 
    255      */ 
    256     synchronized void addInstance(ITaskInstance instance) { 
    257         this.instances.add(instance); 
    258         this.executionVariants = null; 
    259     } 
    260      
    261     /* (non-Javadoc) 
    262      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#accept(ITaskVisitor) 
    263      */ 
    264     @Override 
    265     public void accept(ITaskVisitor visitor) { 
    266         visitor.visit(this); 
    267     } 
    268  
    269     /** 
    270      * 
    271      */ 
    272     private void determineExecutionVariants(Collection<Collection<ITaskInstance>> executionVariants) 
    273     { 
    274         for (ITaskInstance instance : instances) { 
    275             boolean added = false; 
    276             for (Collection<ITaskInstance> variant : executionVariants) { 
    277                 if (!variant.isEmpty() && (isSameExecution(variant.iterator().next(), instance))) { 
    278                     variant.add(instance); 
    279                     added = true; 
    280                 } 
    281             } 
    282              
    283             if (!added) { 
    284                 Collection<ITaskInstance> variant = new HashSet<ITaskInstance>(); 
    285                 variant.add(instance); 
    286                 executionVariants.add(variant); 
    287             } 
    288         } 
    289     } 
    290  
    291     /** 
    292      * 
    293      */ 
    294     private boolean isSameExecution(ITaskInstance instance1, ITaskInstance instance2) { 
    295         if (instance1 instanceof IIterationInstance) { 
    296             if (!(instance2 instanceof IIterationInstance)) { 
    297                 return false; 
    298             } 
    299              
    300             ITaskInstanceList iteration1 = (ITaskInstanceList) instance1; 
    301             ITaskInstanceList iteration2 = (ITaskInstanceList) instance2; 
    302              
    303             return isSameExecutionList(iteration1, iteration2); 
    304         } 
    305         else if (instance1 instanceof ISequenceInstance) { 
    306             if (!(instance2 instanceof ISequenceInstance)) { 
    307                 return false; 
    308             } 
    309              
    310             ITaskInstanceList selection1 = (ITaskInstanceList) instance1; 
    311             ITaskInstanceList selection2 = (ITaskInstanceList) instance2; 
    312              
    313             return isSameExecutionList(selection1, selection2); 
    314         } 
    315         else if (instance1 instanceof ISelectionInstance) { 
    316             if (!(instance2 instanceof ISelectionInstance)) { 
    317                 return false; 
    318             } 
    319             else { 
    320                 return isSameExecution(((ISelectionInstance) instance1).getChild(), 
    321                                        ((ISelectionInstance) instance2).getChild()); 
    322             } 
    323         } 
    324         else if (instance1 instanceof IOptionalInstance) { 
    325             if (!(instance2 instanceof IOptionalInstance)) { 
    326                 return false; 
    327             } 
    328             else { 
    329                 return isSameExecution(((IOptionalInstance) instance1).getChild(), 
    330                                        ((IOptionalInstance) instance2).getChild()); 
    331             } 
    332         } 
    333         else if (instance1 instanceof IEventTaskInstance) { 
    334             if (!(instance2 instanceof IEventTaskInstance)) { 
    335                 return false; 
    336             } 
    337             else { 
    338                 return ((IEventTaskInstance) instance1).getTask().equals 
    339                     (((IEventTaskInstance) instance2).getTask()); 
    340             } 
    341         } 
    342         else if (instance1 == null) { 
    343             return instance2 == null; 
    344         } 
    345         else { 
    346             throw new IllegalArgumentException("unknown type of task instance: " + instance1); 
    347         } 
    348     } 
    349  
    350     /** 
    351      * 
    352      */ 
    353     private boolean isSameExecutionList(ITaskInstanceList list1, ITaskInstanceList list2) { 
    354         if (list1.size() == list2.size()) { 
    355             for (int i = 0; i < list1.size(); i++) { 
    356                 if (!isSameExecution(list1.get(i), list2.get(i))) { 
    357                     return false; 
    358                 } 
    359             } 
    360              
    361             return true; 
    362         } 
    363         else { 
    364             return false; 
    365         } 
    366     } 
     42        /** 
     43         * <p> 
     44         * creates a new id for a task using {@link #temporalId} by incrementing it 
     45         * an returning its current value. Resets the counter if 
     46         * {@link Integer.MAX_VALUE} is reached. 
     47         * </p> 
     48         *  
     49         * @return a new unique id for a task as long as {@link #temporalId} does 
     50         *         not overflow 
     51         */ 
     52        private static synchronized int getNewId() { 
     53                if (temporalId == Integer.MAX_VALUE) { 
     54                        temporalId = 0; 
     55                } 
     56 
     57                return temporalId++; 
     58        } 
     59 
     60        /** 
     61         * <p> 
     62         * default serial version UID 
     63         * </p> 
     64         */ 
     65        private static final long serialVersionUID = 1L; 
     66 
     67        /** 
     68         * <p> 
     69         * used as a counter to generate new ids for each newly created task. May 
     70         * overflow. 
     71         * </p> 
     72         */ 
     73        private static int temporalId = 0; 
     74 
     75        /** 
     76         * <p> 
     77         * the id of the task (unique throughout the system as long as 
     78         * {@link #temporalId} does not overflow. 
     79         * </p> 
     80         */ 
     81        private final int id; 
     82 
     83        /** 
     84         * <p> 
     85         * a human readable type of the task (used for visualization purposes) 
     86         * </p> 
     87         */ 
     88        private final String type; 
     89 
     90        /** 
     91         * <p> 
     92         * a human readable description of the task 
     93         * </p> 
     94         */ 
     95        private String description; 
     96 
     97        /** 
     98         * <p> 
     99         * the instances of this task 
     100         * </p> 
     101         */ 
     102        private final Collection<ITaskInstance> instances = new HashSet<ITaskInstance>(); 
     103 
     104        /** 
     105         * <p> 
     106         * the execution variants of this task 
     107         * </p> 
     108         */ 
     109        private Collection<Collection<ITaskInstance>> executionVariants; 
     110 
     111        /** 
     112         * <p> 
     113         * constructs a new task with a new id. The id is generated using the 
     114         * {@link #getNewId()} method 
     115         * </p> 
     116         *  
     117         * @param type 
     118         *            the human readable type of the task 
     119         *  
     120         * @throws IllegalArgumentException 
     121         *             in the case the provided type is null 
     122         */ 
     123        Task(String type) { 
     124                this.id = getNewId(); 
     125                this.type = type; 
     126 
     127                if (type == null) { 
     128                        throw new IllegalArgumentException("type must not be null"); 
     129                } 
     130        } 
     131 
     132        /* 
     133         * (non-Javadoc) 
     134         *  
     135         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#accept(ITaskVisitor) 
     136         */ 
     137        @Override 
     138        public void accept(ITaskVisitor visitor) { 
     139                visitor.visit(this); 
     140        } 
     141 
     142        /** 
     143         * <p> 
     144         * internally used to add an instance to this task 
     145         * </p> 
     146         *  
     147         * @param instance 
     148         *            the instance belonging to this task 
     149         */ 
     150        synchronized void addInstance(ITaskInstance instance) { 
     151                this.instances.add(instance); 
     152                this.executionVariants = null; 
     153        } 
     154 
     155        /* 
     156         * (non-Javadoc) 
     157         *  
     158         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#clone() 
     159         */ 
     160        @Override 
     161        public synchronized ITask clone() { 
     162                Task clone = null; 
     163                try { 
     164                        clone = (Task) super.clone(); 
     165                } catch (final CloneNotSupportedException e) { 
     166                        // this should never happen. Therefore simply dump the exception 
     167                        e.printStackTrace(); 
     168                } 
     169 
     170                return clone; 
     171        } 
     172 
     173        /** 
     174         * 
     175         */ 
     176        private void determineExecutionVariants( 
     177                        Collection<Collection<ITaskInstance>> executionVariants) { 
     178                for (final ITaskInstance instance : instances) { 
     179                        boolean added = false; 
     180                        for (final Collection<ITaskInstance> variant : executionVariants) { 
     181                                if (!variant.isEmpty() 
     182                                                && (isSameExecution(variant.iterator().next(), instance))) { 
     183                                        variant.add(instance); 
     184                                        added = true; 
     185                                } 
     186                        } 
     187 
     188                        if (!added) { 
     189                                final Collection<ITaskInstance> variant = new HashSet<ITaskInstance>(); 
     190                                variant.add(instance); 
     191                                executionVariants.add(variant); 
     192                        } 
     193                } 
     194        } 
     195 
     196        /* 
     197         * (non-Javadoc) 
     198         *  
     199         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#equals(ITask) 
     200         */ 
     201        @Override 
     202        public final boolean equals(ITask task) { 
     203                // tasks are only equal if they are identical or if they have the same 
     204                // id 
     205                // (may happen, if they are cloned) 
     206                return (this == task) || (this.hashCode() == task.hashCode()); 
     207        } 
     208 
     209        /* 
     210         * (non-Javadoc) 
     211         *  
     212         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#getDescription() 
     213         */ 
     214        @Override 
     215        public String getDescription() { 
     216                return description; 
     217        } 
     218 
     219        /* 
     220         * (non-Javadoc) 
     221         *  
     222         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#getExecutionVariants() 
     223         */ 
     224        @Override 
     225        public synchronized Collection<Collection<ITaskInstance>> getExecutionVariants() { 
     226                if (executionVariants == null) { 
     227                        executionVariants = new LinkedList<Collection<ITaskInstance>>(); 
     228                        determineExecutionVariants(executionVariants); 
     229                } 
     230 
     231                return executionVariants; 
     232        } 
     233 
     234        /* 
     235         * (non-Javadoc) 
     236         *  
     237         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#geId() 
     238         */ 
     239        @Override 
     240        public int getId() { 
     241                return id; 
     242        } 
     243 
     244        /* 
     245         * (non-Javadoc) 
     246         *  
     247         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#getInstances() 
     248         */ 
     249        @Override 
     250        public Collection<ITaskInstance> getInstances() { 
     251                return Collections.unmodifiableCollection(instances); 
     252        } 
     253 
     254        /* 
     255         * (non-Javadoc) 
     256         *  
     257         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#getType() 
     258         */ 
     259        @Override 
     260        public String getType() { 
     261                return type; 
     262        } 
     263 
     264        /* 
     265         * (non-Javadoc) 
     266         *  
     267         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#hashCode() 
     268         */ 
     269        @Override 
     270        public synchronized int hashCode() { 
     271                return id; 
     272        } 
     273 
     274        /** 
     275         * 
     276         */ 
     277        private boolean isSameExecution(ITaskInstance instance1, 
     278                        ITaskInstance instance2) { 
     279                if (instance1 instanceof IIterationInstance) { 
     280                        if (!(instance2 instanceof IIterationInstance)) { 
     281                                return false; 
     282                        } 
     283 
     284                        final ITaskInstanceList iteration1 = (ITaskInstanceList) instance1; 
     285                        final ITaskInstanceList iteration2 = (ITaskInstanceList) instance2; 
     286 
     287                        return isSameExecutionList(iteration1, iteration2); 
     288                } else if (instance1 instanceof ISequenceInstance) { 
     289                        if (!(instance2 instanceof ISequenceInstance)) { 
     290                                return false; 
     291                        } 
     292 
     293                        final ITaskInstanceList selection1 = (ITaskInstanceList) instance1; 
     294                        final ITaskInstanceList selection2 = (ITaskInstanceList) instance2; 
     295 
     296                        return isSameExecutionList(selection1, selection2); 
     297                } else if (instance1 instanceof ISelectionInstance) { 
     298                        if (!(instance2 instanceof ISelectionInstance)) { 
     299                                return false; 
     300                        } else { 
     301                                return isSameExecution( 
     302                                                ((ISelectionInstance) instance1).getChild(), 
     303                                                ((ISelectionInstance) instance2).getChild()); 
     304                        } 
     305                } else if (instance1 instanceof IOptionalInstance) { 
     306                        if (!(instance2 instanceof IOptionalInstance)) { 
     307                                return false; 
     308                        } else { 
     309                                return isSameExecution( 
     310                                                ((IOptionalInstance) instance1).getChild(), 
     311                                                ((IOptionalInstance) instance2).getChild()); 
     312                        } 
     313                } else if (instance1 instanceof IEventTaskInstance) { 
     314                        if (!(instance2 instanceof IEventTaskInstance)) { 
     315                                return false; 
     316                        } else { 
     317                                return ((IEventTaskInstance) instance1).getTask().equals( 
     318                                                ((IEventTaskInstance) instance2).getTask()); 
     319                        } 
     320                } else if (instance1 == null) { 
     321                        return instance2 == null; 
     322                } else { 
     323                        throw new IllegalArgumentException( 
     324                                        "unknown type of task instance: " + instance1); 
     325                } 
     326        } 
     327 
     328        /** 
     329         * 
     330         */ 
     331        private boolean isSameExecutionList(ITaskInstanceList list1, 
     332                        ITaskInstanceList list2) { 
     333                if (list1.size() == list2.size()) { 
     334                        for (int i = 0; i < list1.size(); i++) { 
     335                                if (!isSameExecution(list1.get(i), list2.get(i))) { 
     336                                        return false; 
     337                                } 
     338                        } 
     339 
     340                        return true; 
     341                } else { 
     342                        return false; 
     343                } 
     344        } 
     345 
     346        /** 
     347         * <p> 
     348         * internally used to remove an instance from this task 
     349         * </p> 
     350         *  
     351         * @param instance 
     352         *            the instance to be removed from this task 
     353         */ 
     354        synchronized void removeInstance(ITaskInstance instance) { 
     355                this.instances.remove(instance); 
     356                this.executionVariants = null; 
     357        } 
     358 
     359        /** 
     360         * <p> 
     361         * internally used to set the human readable description of the task 
     362         * </p> 
     363         *  
     364         * @param description 
     365         *            the new human readable description of the task 
     366         */ 
     367        void setDescription(String description) { 
     368                this.description = description; 
     369        } 
     370 
     371        /* 
     372         * (non-Javadoc) 
     373         *  
     374         * @see java.lang.Object#toString() 
     375         */ 
     376        @Override 
     377        public synchronized String toString() { 
     378                final StringBuffer result = new StringBuffer(); 
     379                result.append(type); 
     380                result.append(" #"); 
     381                result.append(id); 
     382 
     383                if (description != null) { 
     384                        result.append(" ("); 
     385                        result.append(description); 
     386                        result.append(')'); 
     387                } 
     388 
     389                return result.toString(); 
     390        } 
    367391} 
  • branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskBuilder.java

    r1422 r1733  
    3636 * <p> 
    3737 * this is the default implementation of the interface {@link ITaskBuilder}. It 
    38  * does not do anything fancy except implementing the interface. In some situations, it performs 
    39  * a check if the model or instances to be created a valid. However, this can not be done 
    40  * in any situation of the creation process. 
     38 * does not do anything fancy except implementing the interface. In some 
     39 * situations, it performs a check if the model or instances to be created a 
     40 * valid. However, this can not be done in any situation of the creation 
     41 * process. 
    4142 * </p> 
    4243 *  
     
    4546public class TaskBuilder implements ITaskBuilder { 
    4647 
    47     /* (non-Javadoc) 
    48      * @see ITaskBuilder#addChild(ISequenceInstance, ITaskInstance) 
    49      */ 
    50     @Override 
    51     public void addChild(ISequenceInstance instance, ITaskInstance child) 
    52         throws IllegalArgumentException 
    53     { 
    54         if (!(instance instanceof SequenceInstance)) { 
    55             throw new IllegalArgumentException 
    56                 ("illegal type of sequence instance provided: " + instance.getClass()); 
    57         } 
    58  
    59         if (!(child instanceof TaskInstance)) { 
    60             throw new IllegalArgumentException 
    61                 ("illegal type of task instance provided: " + child.getClass()); 
    62         } 
    63          
    64         SequenceInstance seqInstance = (SequenceInstance) instance; 
    65          
    66         // check if new child instance matches the model, if this can be checked 
    67         IStructuringTemporalRelationship parentTask = 
    68             (IStructuringTemporalRelationship) instance.getTask(); 
    69          
    70         if (((parentTask.getChildren() != null) && (parentTask.getChildren().size() > 0)) && 
    71             ((parentTask.getChildren().size() <= seqInstance.size()) || 
    72              (!parentTask.getChildren().get(seqInstance.size()).equals(child.getTask())))) 
    73         { 
    74             throw new IllegalArgumentException 
    75                 ("the task of the child instance to be added does not belong to the children " + 
    76                  "of the task of the parent instance"); 
    77         } 
    78  
    79         seqInstance.addChild(child); 
    80     } 
    81  
    82     /* (non-Javadoc) 
    83      * @see ITaskBuilder#addChild(ISequenceInstance, int, ITaskInstance) 
    84      */ 
    85     public void addChild(ISequenceInstance instance, int index, ITaskInstance child) 
    86         throws IllegalArgumentException 
    87     { 
    88         if (!(instance instanceof SequenceInstance)) { 
    89             throw new IllegalArgumentException 
    90                 ("illegal type of sequence instance provided: " + instance.getClass()); 
    91         } 
    92  
    93         if (!(child instanceof TaskInstance)) { 
    94             throw new IllegalArgumentException 
    95                 ("illegal type of task instance provided: " + child.getClass()); 
    96         } 
    97          
    98         SequenceInstance seqInstance = (SequenceInstance) instance; 
    99          
    100         // check if new child instance matches the model, if this can be checked 
    101         IStructuringTemporalRelationship parentTask = 
    102             (IStructuringTemporalRelationship) instance.getTask(); 
    103          
    104         if (((parentTask.getChildren() != null) && (parentTask.getChildren().size() > 0)) && 
    105             ((parentTask.getChildren().size() <= index) || 
    106              (!parentTask.getChildren().get(index).equals(child.getTask())))) 
    107         { 
    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         seqInstance.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         // check if new child instance matches the model, if this can be checked 
    134         IMarkingTemporalRelationship parentTask = 
    135             (IMarkingTemporalRelationship) instance.getTask(); 
    136                  
    137         boolean foundChildTask = parentTask.getMarkedTask() != null ? 
    138             parentTask.getMarkedTask().equals(child.getTask()) : true; 
    139                  
    140         if (!foundChildTask) { 
    141             throw new IllegalArgumentException 
    142                 ("the task of the child instance does not match the model of the task of the " + 
    143                  "iteration instance: " + parentTask.getMarkedTask() + " <> " + child.getTask()); 
    144         } 
    145  
    146         ((IterationInstance) instance).addChild(child); 
    147     } 
    148  
    149     /* (non-Javadoc) 
    150      * @see ITaskBuilder#addChild(IIterationInstance, int, ITaskInstance) 
    151      */ 
    152     public void addChild(IIterationInstance instance, int index, ITaskInstance child) 
    153         throws IllegalArgumentException 
    154     { 
    155         if (!(instance instanceof IterationInstance)) { 
    156             throw new IllegalArgumentException 
    157                 ("illegal type of iteration instance provided: " + instance.getClass()); 
    158         } 
    159  
    160         if (!(child instanceof TaskInstance)) { 
    161             throw new IllegalArgumentException 
    162                 ("illegal type of task instance provided: " + child.getClass()); 
    163         } 
    164          
    165         // check if new child instance matches the model, if this can be checked 
    166         IMarkingTemporalRelationship parentTask = 
    167             (IMarkingTemporalRelationship) instance.getTask(); 
    168                  
    169         boolean foundChildTask = parentTask.getMarkedTask() != null ? 
    170             parentTask.getMarkedTask().equals(child.getTask()) : true; 
    171                  
    172         if (!foundChildTask) { 
    173             throw new IllegalArgumentException 
    174                 ("the task of the child instance does not match the model of the task of the " + 
    175                  "iteration instance: " + parentTask.getMarkedTask() + " <> " + child.getTask()); 
    176         } 
    177  
    178         ((IterationInstance) instance).addChild(index, child); 
    179     } 
    180  
    181     /* (non-Javadoc) 
    182      * @see ITaskBuilder#setChild(ISelectionInstance, ITaskInstance) 
    183      */ 
    184     @Override 
    185     public void setChild(ISelectionInstance instance, ITaskInstance child) 
    186         throws IllegalArgumentException 
    187     { 
    188         if (!(instance instanceof SelectionInstance)) { 
    189             throw new IllegalArgumentException 
    190                 ("illegal type of selection instance provided: " + instance.getClass()); 
    191         } 
    192  
    193         if (!(child instanceof TaskInstance)) { 
    194             throw new IllegalArgumentException("illegal type of task instance provided: " + 
    195                                                (child == null ? null : child.getClass())); 
    196         } 
    197          
    198         // check if new child instance matches the model, if this can be checked 
    199         IStructuringTemporalRelationship parentTask = 
    200             (IStructuringTemporalRelationship) instance.getTask(); 
    201          
    202         boolean foundChildTask = false; 
    203         for (ITask parentTaskChild : parentTask.getChildren()) { 
    204             if (parentTaskChild.equals(child.getTask())) { 
    205                 foundChildTask = true; 
    206                 break; 
    207             } 
    208         } 
    209              
    210         if (!foundChildTask) { 
    211             throw new IllegalArgumentException 
    212                 ("the task of the child instance to be added does not belong to the children " + 
    213                  "of the selection task model of the parent instance"); 
    214         } 
    215  
    216         ((SelectionInstance) instance).setChild(child); 
    217     } 
    218  
    219     /* (non-Javadoc) 
    220      * @see ITaskBuilder#setChild(IOptionalInstance, ITaskInstance) 
    221      */ 
    222     @Override 
    223     public void setChild(IOptionalInstance instance, ITaskInstance child) 
    224         throws IllegalArgumentException 
    225     { 
    226         if (!(instance instanceof OptionalInstance)) { 
    227             throw new IllegalArgumentException 
    228                 ("illegal type of optional instance provided: " + instance.getClass()); 
    229         } 
    230  
    231         if (!(child instanceof TaskInstance)) { 
    232             throw new IllegalArgumentException 
    233                 ("illegal type of task instance provided: " + child.getClass()); 
    234         } 
    235          
    236         // check if new child instance matches the model, if this can be checked 
    237         IMarkingTemporalRelationship parentTask = 
    238             (IMarkingTemporalRelationship) instance.getTask(); 
    239              
    240         boolean foundChildTask = parentTask.getMarkedTask() != null ? 
    241             parentTask.getMarkedTask().equals(child.getTask()) : true; 
    242              
    243         if (!foundChildTask) { 
    244             throw new IllegalArgumentException 
    245                 ("the task of the child instance does not match the model of the task of the " + 
    246                  "optional instance: " + parentTask.getMarkedTask() + " <> " + child.getTask()); 
    247         } 
    248  
    249         ((OptionalInstance) instance).setChild(child); 
    250     } 
    251  
    252     /* (non-Javadoc) 
    253      * @see ITaskBuilder#addExecutedTask(IUserSession, ITaskInstance) 
    254      */ 
    255     @Override 
    256     public void addExecutedTask(IUserSession session, ITaskInstance taskInstance) { 
    257         if (!(session instanceof UserSession)) { 
    258             throw new IllegalArgumentException 
    259                 ("illegal type of session provided: " + session.getClass()); 
    260         } 
    261  
    262         if (!(taskInstance instanceof TaskInstance)) { 
    263             throw new IllegalArgumentException 
    264                 ("illegal type of task instance provided: " + taskInstance.getClass()); 
    265         } 
    266          
    267         ((UserSession) session).addExecutedTask(taskInstance); 
    268     } 
    269  
    270     /* (non-Javadoc) 
    271      * @see ITaskBuilder#addExecutedTask(IUserSession, int, ITaskInstance) 
    272      */ 
    273     public void addExecutedTask(IUserSession session, int index, ITaskInstance taskInstance) { 
    274         if (!(session instanceof UserSession)) { 
    275             throw new IllegalArgumentException 
    276                 ("illegal type of session provided: " + session.getClass()); 
    277         } 
    278  
    279         if (!(taskInstance instanceof TaskInstance)) { 
    280             throw new IllegalArgumentException 
    281                 ("illegal type of task instance provided: " + taskInstance.getClass()); 
    282         } 
    283          
    284         ((UserSession) session).addExecutedTask(index, taskInstance); 
    285     } 
    286  
    287     /* (non-Javadoc) 
    288      * @see ITaskBuilder#addTaskInstance(ITaskInstanceList, ITaskInstance) 
    289      */ 
    290     @Override 
    291     public void addTaskInstance(ITaskInstanceList taskInstanceList, ITaskInstance taskInstance) { 
    292         if (taskInstanceList instanceof SequenceInstance) { 
    293             addChild((SequenceInstance) taskInstanceList, taskInstance); 
    294         } 
    295         else if (taskInstanceList instanceof IterationInstance) { 
    296             addChild((IterationInstance) taskInstanceList, taskInstance); 
    297         } 
    298         else if (taskInstanceList instanceof UserSession) { 
    299             addExecutedTask((UserSession) taskInstanceList, taskInstance); 
    300         } 
    301         else { 
    302             throw new IllegalArgumentException 
    303                 ("illegal type of task instance list provided: " + taskInstanceList.getClass()); 
    304         } 
    305     } 
    306  
    307     /* (non-Javadoc) 
    308      * @see ITaskBuilder#addTaskInstance(ITaskInstanceList, int, ITaskInstance) 
    309      */ 
    310     @Override 
    311     public void addTaskInstance(ITaskInstanceList taskInstanceList, 
    312                                 int               index, 
    313                                 ITaskInstance     taskInstance) 
    314     { 
    315         if (taskInstanceList instanceof SequenceInstance) { 
    316             addChild((SequenceInstance) taskInstanceList, index, taskInstance); 
    317         } 
    318         else if (taskInstanceList instanceof IterationInstance) { 
    319             addChild((IterationInstance) taskInstanceList, index, taskInstance); 
    320         } 
    321         else if (taskInstanceList instanceof UserSession) { 
    322             addExecutedTask((UserSession) taskInstanceList, index, taskInstance); 
    323         } 
    324         else { 
    325             throw new IllegalArgumentException 
    326                 ("illegal type of task instance list provided: " + taskInstanceList.getClass()); 
    327         } 
    328     } 
    329  
    330     /* (non-Javadoc) 
    331      * @see ITaskBuilder#setTaskInstance(ITaskInstanceList, int, ITaskInstance) 
    332      */ 
    333     @Override 
    334     public void setTaskInstance(ITaskInstanceList taskInstanceList, 
    335                                 int               index, 
    336                                 ITaskInstance     taskInstance) 
    337     { 
    338         removeTaskInstance(taskInstanceList, index); 
    339         addTaskInstance(taskInstanceList, index, taskInstance); 
    340     } 
    341  
    342     /* (non-Javadoc) 
    343      * @see ITaskBuilder#setTask(ITaskInstance, ITask) 
    344      */ 
    345     @Override 
    346     public void setTask(ITaskInstance taskInstance, ITask task) { 
    347         if (!(taskInstance instanceof TaskInstance)) { 
    348             throw new IllegalArgumentException 
    349                 ("illegal type of task instance provided: " + taskInstance.getClass()); 
    350         } 
    351         if (!(task instanceof Task)) { 
    352             throw new IllegalArgumentException("illegal type of task provided: " + task.getClass()); 
    353         } 
    354          
    355         if (((TaskInstance) taskInstance).getTask() instanceof Task) { 
    356             ((Task) ((TaskInstance) taskInstance).getTask()).removeInstance(taskInstance); 
    357         } 
    358         ((TaskInstance) taskInstance).setTask(task); 
    359          
    360         ((Task) task).addInstance(taskInstance); 
    361     } 
    362  
    363     /* (non-Javadoc) 
    364      * @see ITaskBuilder#addChild(ISequence, ITask) 
    365      */ 
    366     @Override 
    367     public void addChild(ISequence parent, ITask child) { 
    368         if (!(parent instanceof Sequence)) { 
    369             throw new IllegalArgumentException 
    370                 ("illegal type of sequence provided: " + parent.getClass()); 
    371         } 
    372  
    373         addChildInternal((Sequence) parent, -1, child); 
    374     } 
    375  
    376     /* (non-Javadoc) 
    377      * @see ITaskBuilder#addChild(ISequence, int, ITask) 
    378      */ 
    379     @Override 
    380     public void addChild(ISequence parent, int index, ITask child) { 
    381         if (!(parent instanceof Sequence)) { 
    382             throw new IllegalArgumentException 
    383                 ("illegal type of sequence provided: " + parent.getClass()); 
    384         } 
    385  
    386         addChildInternal((Sequence) parent, index, child); 
    387     } 
    388  
    389     /* (non-Javadoc) 
    390      * @see ITaskBuilder#setChild(ISequence, int, ITask) 
    391      */ 
    392     @Override 
    393     public void setChild(ISequence parent, int index, ITask child) { 
    394         if (!(parent instanceof Sequence)) { 
    395             throw new IllegalArgumentException 
    396                 ("illegal type of sequence provided: " + parent.getClass()); 
    397         } 
    398  
    399         ((Sequence) parent).removeChild(index); 
    400         addChildInternal((Sequence) parent, index, child); 
    401     } 
    402  
    403     /* (non-Javadoc) 
    404      * @see ITaskBuilder#addChild(ISelection, ITask) 
    405      */ 
    406     @Override 
    407     public void addChild(ISelection parent, ITask child) { 
    408         if (!(parent instanceof Selection)) { 
    409             throw new IllegalArgumentException 
    410                 ("illegal type of selection provided: " + parent.getClass()); 
    411         } 
    412  
    413         addChildInternal((Selection) parent, -1, child); 
    414     } 
    415  
    416     /* (non-Javadoc) 
    417      * @see ITaskBuilder#setMarkedTask(IIteration, ITask) 
    418      */ 
    419     @Override 
    420     public void setMarkedTask(IIteration iteration, ITask newChild) { 
    421         if (!(iteration instanceof Iteration)) { 
    422             throw new IllegalArgumentException 
    423                 ("illegal type of iteration provided: " + iteration.getClass()); 
    424         } 
    425  
    426         if (!(newChild instanceof Task)) { 
    427             throw new IllegalArgumentException 
    428                 ("illegal type of task provided: " + newChild.getClass()); 
    429         } 
    430  
    431         ((Iteration) iteration).setMarkedTask(newChild); 
    432     } 
    433  
    434     /* (non-Javadoc) 
    435      * @see ITaskTreeBuilder#setChild(IOptional, ITaskTreeNode) 
    436      */ 
    437     @Override 
    438     public void setMarkedTask(IOptional optional, ITask newChild) { 
    439         if (!(optional instanceof Optional)) { 
    440             throw new IllegalArgumentException 
    441                 ("illegal type of optional provided: " + optional.getClass()); 
    442         } 
    443  
    444         if (!(newChild instanceof Task)) { 
    445             throw new IllegalArgumentException 
    446                 ("illegal type of task provided: " + newChild.getClass()); 
    447         } 
    448  
    449         ((Optional) optional).setMarkedTask(newChild); 
    450     } 
    451  
    452     /* (non-Javadoc) 
    453      * @see ITaskBuilder#removeChild(ISequence, int) 
    454      */ 
    455     @Override 
    456     public void removeChild(ISequence parent, int index) { 
    457         if (!(parent instanceof Sequence)) { 
    458             throw new IllegalArgumentException 
    459                 ("illegal type of sequence provided: " + parent.getClass()); 
    460         } 
    461  
    462         ((Sequence) parent).removeChild(index); 
    463     } 
    464  
    465     /* (non-Javadoc) 
    466      * @see ITaskBuilder#removeChild(ISelection, ITask) 
    467      */ 
    468     @Override 
    469     public void removeChild(ISelection parent, ITask child) { 
    470         if (!(parent instanceof Selection)) { 
    471             throw new IllegalArgumentException 
    472                 ("illegal type of selection provided: " + parent.getClass()); 
    473         } 
    474  
    475         List<ITask> children = parent.getChildren(); 
    476          
    477         for (int i = 0; i < children.size(); i++) { 
    478             if ((children.get(i) == child) || 
    479                 ((children.get(i) != null) && (children.get(i).equals(child)))) 
    480             { 
    481                 ((Selection) parent).removeChild(i); 
    482                 break; 
    483             } 
    484         } 
    485     } 
    486  
    487     /* (non-Javadoc) 
    488      * @see ITaskBuilder#removeTaskInstance(ITaskInstanceList, int) 
    489      */ 
    490     @Override 
    491     public void removeTaskInstance(ITaskInstanceList taskInstanceList, int index) { 
    492         if (taskInstanceList instanceof SequenceInstance) { 
    493             ((SequenceInstance) taskInstanceList).removeChild(index); 
    494         } 
    495         else if (taskInstanceList instanceof IterationInstance) { 
    496             ((IterationInstance) taskInstanceList).removeChild(index); 
    497         } 
    498         else if (taskInstanceList instanceof UserSession) { 
    499             ((UserSession) taskInstanceList).removeExecutedTask(index); 
    500         } 
    501         else { 
    502             throw new IllegalArgumentException 
    503                 ("illegal type of task instance list provided: " + taskInstanceList.getClass()); 
    504         } 
    505     } 
    506  
    507     /* (non-Javadoc) 
    508      * @see ITaskTreeBuilder#replaceChild(ISelection, ITaskTreeNode, ITaskTreeNode) 
    509      */ 
    510     @Override 
    511     public void replaceChild(ISelection parent, ITask oldChild, ITask newChild) { 
    512         if (!(parent instanceof Selection)) { 
    513             throw new IllegalArgumentException 
    514                 ("illegal type of selection provided: " + parent.getClass()); 
    515         } 
    516  
    517         List<ITask> children = parent.getChildren(); 
    518          
    519         for (int i = 0; i < children.size(); i++) { 
    520             if ((children.get(i) == oldChild) || 
    521                 ((children.get(i) != null) && (children.get(i).equals(oldChild)))) 
    522             { 
    523                 ((Selection) parent).removeChild(i); 
    524                 ((Selection) parent).addChild(i, newChild); 
    525                 break; 
    526             } 
    527         } 
    528     } 
    529  
    530     /** 
    531      * <p> 
    532      * internal convenience method for adding children to a structuring temporal relationship 
    533      * including a check for the child type. 
    534      * </p> 
    535      */ 
    536     private void addChildInternal(StructuringTemporalRelationship parent, int index, ITask child) { 
    537         if (!(child instanceof Task)) { 
    538             throw new IllegalArgumentException 
    539                 ("illegal type of task provided: " + child.getClass()); 
    540         } 
    541  
    542         if (index > -1) { 
    543             parent.addChild(index, child); 
    544         } 
    545         else { 
    546             parent.addChild(child); 
    547         } 
    548     } 
     48        /* 
     49         * (non-Javadoc) 
     50         *  
     51         * @see ITaskBuilder#addChild(IIterationInstance, int, ITaskInstance) 
     52         */ 
     53        public void addChild(IIterationInstance instance, int index, 
     54                        ITaskInstance child) throws IllegalArgumentException { 
     55                if (!(instance instanceof IterationInstance)) { 
     56                        throw new IllegalArgumentException( 
     57                                        "illegal type of iteration instance provided: " 
     58                                                        + instance.getClass()); 
     59                } 
     60 
     61                if (!(child instanceof TaskInstance)) { 
     62                        throw new IllegalArgumentException( 
     63                                        "illegal type of task instance provided: " 
     64                                                        + child.getClass()); 
     65                } 
     66 
     67                // check if new child instance matches the model, if this can be checked 
     68                final IMarkingTemporalRelationship parentTask = (IMarkingTemporalRelationship) instance 
     69                                .getTask(); 
     70 
     71                final boolean foundChildTask = parentTask.getMarkedTask() != null ? parentTask 
     72                                .getMarkedTask().equals(child.getTask()) : true; 
     73 
     74                if (!foundChildTask) { 
     75                        throw new IllegalArgumentException( 
     76                                        "the task of the child instance does not match the model of the task of the " 
     77                                                        + "iteration instance: " 
     78                                                        + parentTask.getMarkedTask() + " <> " 
     79                                                        + child.getTask()); 
     80                } 
     81 
     82                ((IterationInstance) instance).addChild(index, child); 
     83        } 
     84 
     85        /* 
     86         * (non-Javadoc) 
     87         *  
     88         * @see ITaskBuilder#addChild(IIterationInstance, ITaskInstance) 
     89         */ 
     90        @Override 
     91        public void addChild(IIterationInstance instance, ITaskInstance child) 
     92                        throws IllegalArgumentException { 
     93                if (!(instance instanceof IterationInstance)) { 
     94                        throw new IllegalArgumentException( 
     95                                        "illegal type of iteration instance provided: " 
     96                                                        + instance.getClass()); 
     97                } 
     98 
     99                if (!(child instanceof TaskInstance)) { 
     100                        throw new IllegalArgumentException( 
     101                                        "illegal type of task instance provided: " 
     102                                                        + child.getClass()); 
     103                } 
     104 
     105                // check if new child instance matches the model, if this can be checked 
     106                final IMarkingTemporalRelationship parentTask = (IMarkingTemporalRelationship) instance 
     107                                .getTask(); 
     108 
     109                final boolean foundChildTask = parentTask.getMarkedTask() != null ? parentTask 
     110                                .getMarkedTask().equals(child.getTask()) : true; 
     111 
     112                if (!foundChildTask) { 
     113                        throw new IllegalArgumentException( 
     114                                        "the task of the child instance does not match the model of the task of the " 
     115                                                        + "iteration instance: " 
     116                                                        + parentTask.getMarkedTask() + " <> " 
     117                                                        + child.getTask()); 
     118                } 
     119 
     120                ((IterationInstance) instance).addChild(child); 
     121        } 
     122 
     123        /* 
     124         * (non-Javadoc) 
     125         *  
     126         * @see ITaskBuilder#addChild(ISelection, ITask) 
     127         */ 
     128        @Override 
     129        public void addChild(ISelection parent, ITask child) { 
     130                if (!(parent instanceof Selection)) { 
     131                        throw new IllegalArgumentException( 
     132                                        "illegal type of selection provided: " + parent.getClass()); 
     133                } 
     134 
     135                addChildInternal((Selection) parent, -1, child); 
     136        } 
     137 
     138        /* 
     139         * (non-Javadoc) 
     140         *  
     141         * @see ITaskBuilder#addChild(ISequence, int, ITask) 
     142         */ 
     143        @Override 
     144        public void addChild(ISequence parent, int index, ITask child) { 
     145                if (!(parent instanceof Sequence)) { 
     146                        throw new IllegalArgumentException( 
     147                                        "illegal type of sequence provided: " + parent.getClass()); 
     148                } 
     149 
     150                addChildInternal((Sequence) parent, index, child); 
     151        } 
     152 
     153        /* 
     154         * (non-Javadoc) 
     155         *  
     156         * @see ITaskBuilder#addChild(ISequence, ITask) 
     157         */ 
     158        @Override 
     159        public void addChild(ISequence parent, ITask child) { 
     160                if (!(parent instanceof Sequence)) { 
     161                        throw new IllegalArgumentException( 
     162                                        "illegal type of sequence provided: " + parent.getClass()); 
     163                } 
     164 
     165                addChildInternal((Sequence) parent, -1, child); 
     166        } 
     167 
     168        /* 
     169         * (non-Javadoc) 
     170         *  
     171         * @see ITaskBuilder#addChild(ISequenceInstance, int, ITaskInstance) 
     172         */ 
     173        public void addChild(ISequenceInstance instance, int index, 
     174                        ITaskInstance child) throws IllegalArgumentException { 
     175                if (!(instance instanceof SequenceInstance)) { 
     176                        throw new IllegalArgumentException( 
     177                                        "illegal type of sequence instance provided: " 
     178                                                        + instance.getClass()); 
     179                } 
     180 
     181                if (!(child instanceof TaskInstance)) { 
     182                        throw new IllegalArgumentException( 
     183                                        "illegal type of task instance provided: " 
     184                                                        + child.getClass()); 
     185                } 
     186 
     187                final SequenceInstance seqInstance = (SequenceInstance) instance; 
     188 
     189                // check if new child instance matches the model, if this can be checked 
     190                final IStructuringTemporalRelationship parentTask = (IStructuringTemporalRelationship) instance 
     191                                .getTask(); 
     192 
     193                if (((parentTask.getChildren() != null) && (parentTask.getChildren() 
     194                                .size() > 0)) 
     195                                && ((parentTask.getChildren().size() <= index) || (!parentTask 
     196                                                .getChildren().get(index).equals(child.getTask())))) { 
     197                        throw new IllegalArgumentException( 
     198                                        "the task of the child instance to be added does not belong to the children " 
     199                                                        + "of the task of the parent instance"); 
     200                } 
     201 
     202                seqInstance.addChild(index, child); 
     203        } 
     204 
     205        /* 
     206         * (non-Javadoc) 
     207         *  
     208         * @see ITaskBuilder#addChild(ISequenceInstance, ITaskInstance) 
     209         */ 
     210        @Override 
     211        public void addChild(ISequenceInstance instance, ITaskInstance child) 
     212                        throws IllegalArgumentException { 
     213                if (!(instance instanceof SequenceInstance)) { 
     214                        throw new IllegalArgumentException( 
     215                                        "illegal type of sequence instance provided: " 
     216                                                        + instance.getClass()); 
     217                } 
     218 
     219                if (!(child instanceof TaskInstance)) { 
     220                        throw new IllegalArgumentException( 
     221                                        "illegal type of task instance provided: " 
     222                                                        + child.getClass()); 
     223                } 
     224 
     225                final SequenceInstance seqInstance = (SequenceInstance) instance; 
     226 
     227                // check if new child instance matches the model, if this can be checked 
     228                final IStructuringTemporalRelationship parentTask = (IStructuringTemporalRelationship) instance 
     229                                .getTask(); 
     230 
     231                if (((parentTask.getChildren() != null) && (parentTask.getChildren() 
     232                                .size() > 0)) 
     233                                && ((parentTask.getChildren().size() <= seqInstance.size()) || (!parentTask 
     234                                                .getChildren().get(seqInstance.size()) 
     235                                                .equals(child.getTask())))) { 
     236                        throw new IllegalArgumentException( 
     237                                        "the task of the child instance to be added does not belong to the children " 
     238                                                        + "of the task of the parent instance"); 
     239                } 
     240 
     241                seqInstance.addChild(child); 
     242        } 
     243 
     244        /** 
     245         * <p> 
     246         * internal convenience method for adding children to a structuring temporal 
     247         * relationship including a check for the child type. 
     248         * </p> 
     249         */ 
     250        private void addChildInternal(StructuringTemporalRelationship parent, 
     251                        int index, ITask child) { 
     252                if (!(child instanceof Task)) { 
     253                        throw new IllegalArgumentException( 
     254                                        "illegal type of task provided: " + child.getClass()); 
     255                } 
     256 
     257                if (index > -1) { 
     258                        parent.addChild(index, child); 
     259                } else { 
     260                        parent.addChild(child); 
     261                } 
     262        } 
     263 
     264        /* 
     265         * (non-Javadoc) 
     266         *  
     267         * @see ITaskBuilder#addExecutedTask(IUserSession, int, ITaskInstance) 
     268         */ 
     269        public void addExecutedTask(IUserSession session, int index, 
     270                        ITaskInstance taskInstance) { 
     271                if (!(session instanceof UserSession)) { 
     272                        throw new IllegalArgumentException( 
     273                                        "illegal type of session provided: " + session.getClass()); 
     274                } 
     275 
     276                if (!(taskInstance instanceof TaskInstance)) { 
     277                        throw new IllegalArgumentException( 
     278                                        "illegal type of task instance provided: " 
     279                                                        + taskInstance.getClass()); 
     280                } 
     281 
     282                ((UserSession) session).addExecutedTask(index, taskInstance); 
     283        } 
     284 
     285        /* 
     286         * (non-Javadoc) 
     287         *  
     288         * @see ITaskBuilder#addExecutedTask(IUserSession, ITaskInstance) 
     289         */ 
     290        @Override 
     291        public void addExecutedTask(IUserSession session, ITaskInstance taskInstance) { 
     292                if (!(session instanceof UserSession)) { 
     293                        throw new IllegalArgumentException( 
     294                                        "illegal type of session provided: " + session.getClass()); 
     295                } 
     296 
     297                if (!(taskInstance instanceof TaskInstance)) { 
     298                        throw new IllegalArgumentException( 
     299                                        "illegal type of task instance provided: " 
     300                                                        + taskInstance.getClass()); 
     301                } 
     302 
     303                ((UserSession) session).addExecutedTask(taskInstance); 
     304        } 
     305 
     306        /* 
     307         * (non-Javadoc) 
     308         *  
     309         * @see ITaskBuilder#addTaskInstance(ITaskInstanceList, int, ITaskInstance) 
     310         */ 
     311        @Override 
     312        public void addTaskInstance(ITaskInstanceList taskInstanceList, int index, 
     313                        ITaskInstance taskInstance) { 
     314                if (taskInstanceList instanceof SequenceInstance) { 
     315                        addChild((SequenceInstance) taskInstanceList, index, taskInstance); 
     316                } else if (taskInstanceList instanceof IterationInstance) { 
     317                        addChild((IterationInstance) taskInstanceList, index, taskInstance); 
     318                } else if (taskInstanceList instanceof UserSession) { 
     319                        addExecutedTask((UserSession) taskInstanceList, index, taskInstance); 
     320                } else { 
     321                        throw new IllegalArgumentException( 
     322                                        "illegal type of task instance list provided: " 
     323                                                        + taskInstanceList.getClass()); 
     324                } 
     325        } 
     326 
     327        /* 
     328         * (non-Javadoc) 
     329         *  
     330         * @see ITaskBuilder#addTaskInstance(ITaskInstanceList, ITaskInstance) 
     331         */ 
     332        @Override 
     333        public void addTaskInstance(ITaskInstanceList taskInstanceList, 
     334                        ITaskInstance taskInstance) { 
     335                if (taskInstanceList instanceof SequenceInstance) { 
     336                        addChild((SequenceInstance) taskInstanceList, taskInstance); 
     337                } else if (taskInstanceList instanceof IterationInstance) { 
     338                        addChild((IterationInstance) taskInstanceList, taskInstance); 
     339                } else if (taskInstanceList instanceof UserSession) { 
     340                        addExecutedTask((UserSession) taskInstanceList, taskInstance); 
     341                } else { 
     342                        throw new IllegalArgumentException( 
     343                                        "illegal type of task instance list provided: " 
     344                                                        + taskInstanceList.getClass()); 
     345                } 
     346        } 
     347 
     348        /* 
     349         * (non-Javadoc) 
     350         *  
     351         * @see ITaskBuilder#removeChild(ISelection, ITask) 
     352         */ 
     353        @Override 
     354        public void removeChild(ISelection parent, ITask child) { 
     355                if (!(parent instanceof Selection)) { 
     356                        throw new IllegalArgumentException( 
     357                                        "illegal type of selection provided: " + parent.getClass()); 
     358                } 
     359 
     360                final List<ITask> children = parent.getChildren(); 
     361 
     362                for (int i = 0; i < children.size(); i++) { 
     363                        if ((children.get(i) == child) 
     364                                        || ((children.get(i) != null) && (children.get(i) 
     365                                                        .equals(child)))) { 
     366                                ((Selection) parent).removeChild(i); 
     367                                break; 
     368                        } 
     369                } 
     370        } 
     371 
     372        /* 
     373         * (non-Javadoc) 
     374         *  
     375         * @see ITaskBuilder#removeChild(ISequence, int) 
     376         */ 
     377        @Override 
     378        public void removeChild(ISequence parent, int index) { 
     379                if (!(parent instanceof Sequence)) { 
     380                        throw new IllegalArgumentException( 
     381                                        "illegal type of sequence provided: " + parent.getClass()); 
     382                } 
     383 
     384                ((Sequence) parent).removeChild(index); 
     385        } 
     386 
     387        /* 
     388         * (non-Javadoc) 
     389         *  
     390         * @see ITaskBuilder#removeTaskInstance(ITaskInstanceList, int) 
     391         */ 
     392        @Override 
     393        public void removeTaskInstance(ITaskInstanceList taskInstanceList, int index) { 
     394                if (taskInstanceList instanceof SequenceInstance) { 
     395                        ((SequenceInstance) taskInstanceList).removeChild(index); 
     396                } else if (taskInstanceList instanceof IterationInstance) { 
     397                        ((IterationInstance) taskInstanceList).removeChild(index); 
     398                } else if (taskInstanceList instanceof UserSession) { 
     399                        ((UserSession) taskInstanceList).removeExecutedTask(index); 
     400                } else { 
     401                        throw new IllegalArgumentException( 
     402                                        "illegal type of task instance list provided: " 
     403                                                        + taskInstanceList.getClass()); 
     404                } 
     405        } 
     406 
     407        /* 
     408         * (non-Javadoc) 
     409         *  
     410         * @see ITaskTreeBuilder#replaceChild(ISelection, ITaskTreeNode, 
     411         * ITaskTreeNode) 
     412         */ 
     413        @Override 
     414        public void replaceChild(ISelection parent, ITask oldChild, ITask newChild) { 
     415                if (!(parent instanceof Selection)) { 
     416                        throw new IllegalArgumentException( 
     417                                        "illegal type of selection provided: " + parent.getClass()); 
     418                } 
     419 
     420                final List<ITask> children = parent.getChildren(); 
     421 
     422                for (int i = 0; i < children.size(); i++) { 
     423                        if ((children.get(i) == oldChild) 
     424                                        || ((children.get(i) != null) && (children.get(i) 
     425                                                        .equals(oldChild)))) { 
     426                                ((Selection) parent).removeChild(i); 
     427                                ((Selection) parent).addChild(i, newChild); 
     428                                break; 
     429                        } 
     430                } 
     431        } 
     432 
     433        /* 
     434         * (non-Javadoc) 
     435         *  
     436         * @see ITaskBuilder#setChild(IOptionalInstance, ITaskInstance) 
     437         */ 
     438        @Override 
     439        public void setChild(IOptionalInstance instance, ITaskInstance child) 
     440                        throws IllegalArgumentException { 
     441                if (!(instance instanceof OptionalInstance)) { 
     442                        throw new IllegalArgumentException( 
     443                                        "illegal type of optional instance provided: " 
     444                                                        + instance.getClass()); 
     445                } 
     446 
     447                if (!(child instanceof TaskInstance)) { 
     448                        throw new IllegalArgumentException( 
     449                                        "illegal type of task instance provided: " 
     450                                                        + child.getClass()); 
     451                } 
     452 
     453                // check if new child instance matches the model, if this can be checked 
     454                final IMarkingTemporalRelationship parentTask = (IMarkingTemporalRelationship) instance 
     455                                .getTask(); 
     456 
     457                final boolean foundChildTask = parentTask.getMarkedTask() != null ? parentTask 
     458                                .getMarkedTask().equals(child.getTask()) : true; 
     459 
     460                if (!foundChildTask) { 
     461                        throw new IllegalArgumentException( 
     462                                        "the task of the child instance does not match the model of the task of the " 
     463                                                        + "optional instance: " 
     464                                                        + parentTask.getMarkedTask() + " <> " 
     465                                                        + child.getTask()); 
     466                } 
     467 
     468                ((OptionalInstance) instance).setChild(child); 
     469        } 
     470 
     471        /* 
     472         * (non-Javadoc) 
     473         *  
     474         * @see ITaskBuilder#setChild(ISelectionInstance, ITaskInstance) 
     475         */ 
     476        @Override 
     477        public void setChild(ISelectionInstance instance, ITaskInstance child) 
     478                        throws IllegalArgumentException { 
     479                if (!(instance instanceof SelectionInstance)) { 
     480                        throw new IllegalArgumentException( 
     481                                        "illegal type of selection instance provided: " 
     482                                                        + instance.getClass()); 
     483                } 
     484 
     485                if (!(child instanceof TaskInstance)) { 
     486                        throw new IllegalArgumentException( 
     487                                        "illegal type of task instance provided: " 
     488                                                        + (child == null ? null : child.getClass())); 
     489                } 
     490 
     491                // check if new child instance matches the model, if this can be checked 
     492                final IStructuringTemporalRelationship parentTask = (IStructuringTemporalRelationship) instance 
     493                                .getTask(); 
     494 
     495                boolean foundChildTask = false; 
     496                for (final ITask parentTaskChild : parentTask.getChildren()) { 
     497                        if (parentTaskChild.equals(child.getTask())) { 
     498                                foundChildTask = true; 
     499                                break; 
     500                        } 
     501                } 
     502 
     503                if (!foundChildTask) { 
     504                        throw new IllegalArgumentException( 
     505                                        "the task of the child instance to be added does not belong to the children " 
     506                                                        + "of the selection task model of the parent instance"); 
     507                } 
     508 
     509                ((SelectionInstance) instance).setChild(child); 
     510        } 
     511 
     512        /* 
     513         * (non-Javadoc) 
     514         *  
     515         * @see ITaskBuilder#setChild(ISequence, int, ITask) 
     516         */ 
     517        @Override 
     518        public void setChild(ISequence parent, int index, ITask child) { 
     519                if (!(parent instanceof Sequence)) { 
     520                        throw new IllegalArgumentException( 
     521                                        "illegal type of sequence provided: " + parent.getClass()); 
     522                } 
     523 
     524                ((Sequence) parent).removeChild(index); 
     525                addChildInternal((Sequence) parent, index, child); 
     526        } 
     527 
     528        /* 
     529         * (non-Javadoc) 
     530         *  
     531         * @see ITaskBuilder#setMarkedTask(IIteration, ITask) 
     532         */ 
     533        @Override 
     534        public void setMarkedTask(IIteration iteration, ITask newChild) { 
     535                if (!(iteration instanceof Iteration)) { 
     536                        throw new IllegalArgumentException( 
     537                                        "illegal type of iteration provided: " 
     538                                                        + iteration.getClass()); 
     539                } 
     540 
     541                if (!(newChild instanceof Task)) { 
     542                        throw new IllegalArgumentException( 
     543                                        "illegal type of task provided: " + newChild.getClass()); 
     544                } 
     545 
     546                ((Iteration) iteration).setMarkedTask(newChild); 
     547        } 
     548 
     549        /* 
     550         * (non-Javadoc) 
     551         *  
     552         * @see ITaskTreeBuilder#setChild(IOptional, ITaskTreeNode) 
     553         */ 
     554        @Override 
     555        public void setMarkedTask(IOptional optional, ITask newChild) { 
     556                if (!(optional instanceof Optional)) { 
     557                        throw new IllegalArgumentException( 
     558                                        "illegal type of optional provided: " + optional.getClass()); 
     559                } 
     560 
     561                if (!(newChild instanceof Task)) { 
     562                        throw new IllegalArgumentException( 
     563                                        "illegal type of task provided: " + newChild.getClass()); 
     564                } 
     565 
     566                ((Optional) optional).setMarkedTask(newChild); 
     567        } 
     568 
     569        /* 
     570         * (non-Javadoc) 
     571         *  
     572         * @see ITaskBuilder#setTask(ITaskInstance, ITask) 
     573         */ 
     574        @Override 
     575        public void setTask(ITaskInstance taskInstance, ITask task) { 
     576                if (!(taskInstance instanceof TaskInstance)) { 
     577                        throw new IllegalArgumentException( 
     578                                        "illegal type of task instance provided: " 
     579                                                        + taskInstance.getClass()); 
     580                } 
     581                if (!(task instanceof Task)) { 
     582                        throw new IllegalArgumentException( 
     583                                        "illegal type of task provided: " + task.getClass()); 
     584                } 
     585 
     586                if (((TaskInstance) taskInstance).getTask() instanceof Task) { 
     587                        ((Task) ((TaskInstance) taskInstance).getTask()) 
     588                                        .removeInstance(taskInstance); 
     589                } 
     590                ((TaskInstance) taskInstance).setTask(task); 
     591 
     592                ((Task) task).addInstance(taskInstance); 
     593        } 
     594 
     595        /* 
     596         * (non-Javadoc) 
     597         *  
     598         * @see ITaskBuilder#setTaskInstance(ITaskInstanceList, int, ITaskInstance) 
     599         */ 
     600        @Override 
     601        public void setTaskInstance(ITaskInstanceList taskInstanceList, int index, 
     602                        ITaskInstance taskInstance) { 
     603                removeTaskInstance(taskInstanceList, index); 
     604                addTaskInstance(taskInstanceList, index, taskInstance); 
     605        } 
    549606 
    550607} 
  • branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskFactory.java

    r1294 r1733  
    3535 * <p> 
    3636 * this is the default implementation of the interface {@link ITaskFactory}. It 
    37  * does not do anything fancy except implementing the interface. It instantiates the other 
    38  * implementations of the tree ifc in this package. 
     37 * does not do anything fancy except implementing the interface. It instantiates 
     38 * the other implementations of the tree ifc in this package. 
    3939 * </p> 
    4040 *  
     
    4343public class TaskFactory implements ITaskFactory { 
    4444 
    45     /* (non-Javadoc) 
    46      * @see ITaskFactory#createNewEventTask(String) 
    47      */ 
    48     @Override 
    49     public IEventTask createNewEventTask(String description) { 
    50         return new EventTask(description); 
    51     } 
    52  
    53     /* (non-Javadoc) 
    54      * @see ITaskFactory#createNewSequence() 
    55      */ 
    56     @Override 
    57     public ISequence createNewSequence() { 
    58         return new Sequence(); 
    59     } 
    60  
    61     /* (non-Javadoc) 
    62      * @see ITaskFactory#createNewIteration() 
    63      */ 
    64     @Override 
    65     public IIteration createNewIteration() { 
    66         return new Iteration(); 
    67     } 
    68  
    69     /* (non-Javadoc) 
    70      * @see ITaskFactory#createNewOptional() 
    71      */ 
    72     @Override 
    73     public IOptional createNewOptional() { 
    74         return new Optional(); 
    75     } 
    76  
    77     /* (non-Javadoc) 
    78      * @see ITaskFactory#createNewSelection() 
    79      */ 
    80     @Override 
    81     public ISelection createNewSelection() { 
    82         return new Selection(); 
    83     } 
    84  
    85     /* (non-Javadoc) 
    86      * @see ITaskFactory#createNewTaskInstance(IEventTask, Event) 
    87      */ 
    88     @Override 
    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; 
    99     } 
    100  
    101     /* (non-Javadoc) 
    102      * @see ITaskFactory#createNewTaskInstance(ISequence) 
    103      */ 
    104     @Override 
    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; 
    163     } 
    164  
    165     /* (non-Javadoc) 
    166      * @see ITaskFactory#createUserSession() 
    167      */ 
    168     @Override 
    169     public IUserSession createUserSession() { 
    170         return new UserSession(); 
    171     } 
    172  
    173     /* (non-Javadoc) 
    174      * @see ITaskFactory#createTaskModel(List<IUserSession>) 
    175      */ 
    176     @Override 
    177     public ITaskModel createTaskModel(List<IUserSession> userSessions) { 
    178         return new TaskModel(userSessions); 
    179     } 
     45        /* 
     46         * (non-Javadoc) 
     47         *  
     48         * @see ITaskFactory#createNewEventTask(String) 
     49         */ 
     50        @Override 
     51        public IEventTask createNewEventTask(String description) { 
     52                return new EventTask(description); 
     53        } 
     54 
     55        /* 
     56         * (non-Javadoc) 
     57         *  
     58         * @see ITaskFactory#createNewIteration() 
     59         */ 
     60        @Override 
     61        public IIteration createNewIteration() { 
     62                return new Iteration(); 
     63        } 
     64 
     65        /* 
     66         * (non-Javadoc) 
     67         *  
     68         * @see ITaskFactory#createNewOptional() 
     69         */ 
     70        @Override 
     71        public IOptional createNewOptional() { 
     72                return new Optional(); 
     73        } 
     74 
     75        /* 
     76         * (non-Javadoc) 
     77         *  
     78         * @see ITaskFactory#createNewSelection() 
     79         */ 
     80        @Override 
     81        public ISelection createNewSelection() { 
     82                return new Selection(); 
     83        } 
     84 
     85        /* 
     86         * (non-Javadoc) 
     87         *  
     88         * @see ITaskFactory#createNewSequence() 
     89         */ 
     90        @Override 
     91        public ISequence createNewSequence() { 
     92                return new Sequence(); 
     93        } 
     94 
     95        /* 
     96         * (non-Javadoc) 
     97         *  
     98         * @see ITaskFactory#createNewTaskInstance(IEventTask, Event) 
     99         */ 
     100        @Override 
     101        public IEventTaskInstance createNewTaskInstance(IEventTask task, Event event) { 
     102                if (!(task instanceof EventTask)) { 
     103                        throw new IllegalArgumentException( 
     104                                        "illegal type of event task provided: " + task.getClass()); 
     105                } 
     106 
     107                final EventTaskInstance instance = new EventTaskInstance(task, event); 
     108                ((EventTask) task).addInstance(instance); 
     109 
     110                return instance; 
     111        } 
     112 
     113        /* 
     114         * (non-Javadoc) 
     115         *  
     116         * @see ITaskFactory#createNewTaskInstance(IIteration) 
     117         */ 
     118        @Override 
     119        public IIterationInstance createNewTaskInstance(IIteration iteration) { 
     120                if (!(iteration instanceof Iteration)) { 
     121                        throw new IllegalArgumentException( 
     122                                        "illegal type of iteration provided: " 
     123                                                        + iteration.getClass()); 
     124                } 
     125 
     126                final IterationInstance instance = new IterationInstance(iteration); 
     127                ((Iteration) iteration).addInstance(instance); 
     128 
     129                return instance; 
     130        } 
     131 
     132        /* 
     133         * (non-Javadoc) 
     134         *  
     135         * @see ITaskFactory#createNewTaskInstance(IOptional) 
     136         */ 
     137        @Override 
     138        public IOptionalInstance createNewTaskInstance(IOptional optional) { 
     139                if (!(optional instanceof Optional)) { 
     140                        throw new IllegalArgumentException( 
     141                                        "illegal type of optional provided: " + optional.getClass()); 
     142                } 
     143 
     144                final OptionalInstance instance = new OptionalInstance(optional); 
     145                ((Optional) optional).addInstance(instance); 
     146 
     147                return instance; 
     148        } 
     149 
     150        /* 
     151         * (non-Javadoc) 
     152         *  
     153         * @see ITaskFactory#createNewTaskInstance(ISelection) 
     154         */ 
     155        @Override 
     156        public ISelectionInstance createNewTaskInstance(ISelection selection) { 
     157                if (!(selection instanceof Selection)) { 
     158                        throw new IllegalArgumentException( 
     159                                        "illegal type of optional provided: " 
     160                                                        + selection.getClass()); 
     161                } 
     162 
     163                final SelectionInstance instance = new SelectionInstance(selection); 
     164                ((Selection) selection).addInstance(instance); 
     165 
     166                return instance; 
     167        } 
     168 
     169        /* 
     170         * (non-Javadoc) 
     171         *  
     172         * @see ITaskFactory#createNewTaskInstance(ISequence) 
     173         */ 
     174        @Override 
     175        public ISequenceInstance createNewTaskInstance(ISequence sequence) { 
     176                if (!(sequence instanceof Sequence)) { 
     177                        throw new IllegalArgumentException( 
     178                                        "illegal type of sequence provided: " + sequence.getClass()); 
     179                } 
     180 
     181                final SequenceInstance instance = new SequenceInstance(sequence); 
     182                ((Sequence) sequence).addInstance(instance); 
     183 
     184                return instance; 
     185        } 
     186 
     187        /* 
     188         * (non-Javadoc) 
     189         *  
     190         * @see ITaskFactory#createTaskModel(List<IUserSession>) 
     191         */ 
     192        @Override 
     193        public ITaskModel createTaskModel(List<IUserSession> userSessions) { 
     194                return new TaskModel(userSessions); 
     195        } 
     196 
     197        /* 
     198         * (non-Javadoc) 
     199         *  
     200         * @see ITaskFactory#createUserSession() 
     201         */ 
     202        @Override 
     203        public IUserSession createUserSession() { 
     204                return new UserSession(); 
     205        } 
    180206 
    181207} 
  • branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskInfo.java

    r1428 r1733  
    3131 */ 
    3232public class TaskInfo implements ITaskInfo { 
    33      
    34     /** 
    35      * <p> 
    36      * the task to which the infos belong 
    37      * </p> 
    38      */ 
    39     private ITask task; 
    40      
    41     /** 
    42      * <p> 
    43      * all available measures for the task 
    44      * </p> 
    45      */ 
    46     private ArrayList<Measure> measures = new ArrayList<Measure>(); 
    47  
    48     /** 
    49      * <p> 
    50      * initialized the task infos with the task to which they belong. 
    51      * </p> 
    52      *  
    53      * @param task 
    54      */ 
    55     TaskInfo(ITask task) { 
    56         this.task = task; 
    57     } 
    58  
    59     /* (non-Javadoc) 
    60      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInfo#getTask() 
    61      */ 
    62     @Override 
    63     public ITask getTask() { 
    64         return task; 
    65     } 
    66  
    67     /* (non-Javadoc) 
    68      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInfo#getMeasures() 
    69      */ 
    70     @Override 
    71     public IMeasure[] getMeasures() { 
    72         measures.trimToSize(); 
    73         return measures.toArray(new IMeasure[measures.size()]); 
    74     } 
    75  
    76     /* (non-Javadoc) 
    77      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInfo#getMeasureValue(java.lang.String) 
    78      */ 
    79     @Override 
    80     public int getMeasureValue(TaskMetric metric) { 
    81         Measure measure = getMeasure(metric); 
    82          
    83         if (measure == null) { 
    84             throw new IllegalArgumentException("unknown metric " + metric); 
    85         } 
    86          
    87         return measure.getValue(); 
    88     } 
    89  
    90     /* (non-Javadoc) 
    91      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInfo#getMeasureValue(java.lang.String, de.ugoe.cs.autoquest.tasktrees.treeifc.ITask) 
    92      */ 
    93     @Override 
    94     public int getMeasureValue(TaskMetric metric, ITask context) { 
    95         Measure measure = getMeasure(metric); 
    96          
    97         if (measure == null) { 
    98             throw new IllegalArgumentException("unknown metric " + metric); 
    99         } 
    100          
    101         return measure.getValue(context); 
    102     } 
    103  
    104     /* (non-Javadoc) 
    105      * @see java.lang.Object#toString() 
    106      */ 
    107     @Override 
    108     public synchronized String toString() { 
    109         return "TaskInfo(" + task + ")"; 
    110     } 
    111  
    112     /** 
    113      * <p> 
    114      * must be called to indicate that a new new measures for the provided metric are about to 
    115      * be calculated and added. 
    116      * </p> 
    117      * 
    118      * @param metric the metric for which measures are about to be provided 
    119      */ 
    120     void addMeasure(TaskMetric metric) { 
    121         Measure measure = getMeasure(metric); 
    122          
    123         if (measure != null) { 
    124             throw new IllegalArgumentException("measure for metric " + metric + " already exists."); 
    125         } 
    126          
    127         measure = new Measure(metric); 
    128         measures.add(measure); 
    129     } 
    130  
    131     /** 
    132      * <p> 
    133      * sets a specific value for a measure of a specific metric in the provided context of the task 
    134      * </p> 
    135      *  
    136      * @param metric  the metric to which the value belongs 
    137      * @param context the context of the task in which the measure was recorded 
    138      * @param value   the value of the measure 
    139      */ 
    140     void setCount(TaskMetric metric, ITask context, int value) { 
    141         Measure measure = getMeasure(metric); 
    142          
    143         if (measure == null) { 
    144             throw new IllegalArgumentException("unknown metric. Please create a measure " + 
    145                                                "for the metric before using it."); 
    146         } 
    147          
    148         measure.set(context, value); 
    149     } 
    150  
    151     /** 
    152      * <p> 
    153      * increases a specific value for a measure of a specific metric in the provided context of the 
    154      * task 
    155      * </p> 
    156      *  
    157      * @param metric    the metric to which the value belongs 
    158      * @param context   the context of the task in which the measure was recorded 
    159      * @param increment the increment to be added to the value of the measure 
    160      */ 
    161     void increaseCount(TaskMetric metric, ITask context, int increment) { 
    162         Measure measure = getMeasure(metric); 
    163          
    164         if (measure == null) { 
    165             throw new IllegalArgumentException("unknown metric. Please create a measure " + 
    166                                                "for the metric before using it."); 
    167         } 
    168          
    169         measure.increase(context, increment); 
    170     } 
    171  
    172     /** 
    173      * <p> 
    174      * convenience method to internally determine the measure for a specific metric 
    175      * </p> 
    176      */ 
    177     private Measure getMeasure(TaskMetric metric) { 
    178         for (Measure candidate : measures) { 
    179             if (candidate.getMetric().equals(metric)) { 
    180                 return candidate; 
    181             } 
    182         } 
    183          
    184         return null; 
    185     } 
    186  
    187     /** 
    188      * <p> 
    189      * implementation for the measure interface of the task info interface. Does nothing fancy 
    190      * except implementing the interface 
    191      * </p> 
    192      *  
    193      * @author Patrick Harms 
    194      */ 
    195     private static class Measure implements IMeasure { 
    196  
    197         /** 
    198          * <p> 
    199          * the metric to which the measure belongs 
    200          * </p> 
    201          */ 
    202         private TaskMetric metric; 
    203          
    204         /** 
    205          * <p> 
    206          * the observed values for the difference contexts of the task 
    207          * </p> 
    208          */ 
    209         private HashMap<ITask, Integer> values; 
    210          
    211         /** 
    212          * <p> 
    213          * the context free value of the measure independent of the task context 
    214          * </p> 
    215          */ 
    216         private int contextFreeValue = 0; 
    217          
    218         /** 
    219          * <p> 
    220          * initializes the measure with a specific metric 
    221          * </p> 
    222          */ 
    223         private Measure(TaskMetric metric) { 
    224             super(); 
    225             this.metric = metric; 
    226         } 
    227  
    228         /* (non-Javadoc) 
    229          * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInfo.IMeasure#getMetric() 
    230          */ 
    231         @Override 
    232         public TaskMetric getMetric() { 
    233             return metric; 
    234         } 
    235  
    236         /* (non-Javadoc) 
    237          * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInfo.IMeasure#getValue() 
    238          */ 
    239         @Override 
    240         public int getValue() { 
    241             return contextFreeValue; 
    242         } 
    243  
    244         /* (non-Javadoc) 
    245          * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInfo.IMeasure#getValue(de.ugoe.cs.autoquest.tasktrees.treeifc.ITask) 
    246          */ 
    247         @Override 
    248         public int getValue(ITask context) { 
    249             if ((context != null) && (values != null)) { 
    250                 Integer currentValue = values.get(context); 
    251                  
    252                 if (currentValue != null) { 
    253                     return currentValue; 
    254                 } 
    255             } 
    256              
    257             return Integer.MIN_VALUE; 
    258         } 
    259  
    260         /** 
    261          * <p> 
    262          * sets the value of the measure context free as well as specific to the provided context 
    263          * </p> 
    264          */ 
    265         private void set(ITask context, int value) { 
    266             contextFreeValue = value; 
    267              
    268             if (context != null) { 
    269                 if (values == null) { 
    270                     values = new HashMap<ITask, Integer>(); 
    271                 } 
    272                  
    273                 values.put(context, value); 
    274             } 
    275         } 
    276  
    277         /** 
    278          * <p> 
    279          * increases the value of the measure context free as well as specific to the provided 
    280          * context according to the provided increment 
    281          * </p> 
    282          */ 
    283         private void increase(ITask context, int increment) { 
    284             contextFreeValue += increment; 
    285              
    286             if (context != null) { 
    287                 if (values == null) { 
    288                     values = new HashMap<ITask, Integer>(); 
    289                 } 
    290                  
    291                 Integer currentValue = values.get(context); 
    292                  
    293                 if (currentValue == null) { 
    294                     currentValue = 0; 
    295                 } 
    296                  
    297                 values.put(context, currentValue + increment); 
    298             } 
    299         } 
    300  
    301     } 
     33 
     34        /** 
     35         * <p> 
     36         * implementation for the measure interface of the task info interface. Does 
     37         * nothing fancy except implementing the interface 
     38         * </p> 
     39         *  
     40         * @author Patrick Harms 
     41         */ 
     42        private static class Measure implements IMeasure { 
     43 
     44                /** 
     45                 * <p> 
     46                 * the metric to which the measure belongs 
     47                 * </p> 
     48                 */ 
     49                private final TaskMetric metric; 
     50 
     51                /** 
     52                 * <p> 
     53                 * the observed values for the difference contexts of the task 
     54                 * </p> 
     55                 */ 
     56                private HashMap<ITask, Integer> values; 
     57 
     58                /** 
     59                 * <p> 
     60                 * the context free value of the measure independent of the task context 
     61                 * </p> 
     62                 */ 
     63                private int contextFreeValue = 0; 
     64 
     65                /** 
     66                 * <p> 
     67                 * initializes the measure with a specific metric 
     68                 * </p> 
     69                 */ 
     70                private Measure(TaskMetric metric) { 
     71                        super(); 
     72                        this.metric = metric; 
     73                } 
     74 
     75                /* 
     76                 * (non-Javadoc) 
     77                 *  
     78                 * @see 
     79                 * de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInfo.IMeasure#getMetric() 
     80                 */ 
     81                @Override 
     82                public TaskMetric getMetric() { 
     83                        return metric; 
     84                } 
     85 
     86                /* 
     87                 * (non-Javadoc) 
     88                 *  
     89                 * @see 
     90                 * de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInfo.IMeasure#getValue() 
     91                 */ 
     92                @Override 
     93                public int getValue() { 
     94                        return contextFreeValue; 
     95                } 
     96 
     97                /* 
     98                 * (non-Javadoc) 
     99                 *  
     100                 * @see 
     101                 * de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInfo.IMeasure#getValue 
     102                 * (de.ugoe.cs.autoquest.tasktrees.treeifc.ITask) 
     103                 */ 
     104                @Override 
     105                public int getValue(ITask context) { 
     106                        if ((context != null) && (values != null)) { 
     107                                final Integer currentValue = values.get(context); 
     108 
     109                                if (currentValue != null) { 
     110                                        return currentValue; 
     111                                } 
     112                        } 
     113 
     114                        return Integer.MIN_VALUE; 
     115                } 
     116 
     117                /** 
     118                 * <p> 
     119                 * increases the value of the measure context free as well as specific 
     120                 * to the provided context according to the provided increment 
     121                 * </p> 
     122                 */ 
     123                private void increase(ITask context, int increment) { 
     124                        contextFreeValue += increment; 
     125 
     126                        if (context != null) { 
     127                                if (values == null) { 
     128                                        values = new HashMap<ITask, Integer>(); 
     129                                } 
     130 
     131                                Integer currentValue = values.get(context); 
     132 
     133                                if (currentValue == null) { 
     134                                        currentValue = 0; 
     135                                } 
     136 
     137                                values.put(context, currentValue + increment); 
     138                        } 
     139                } 
     140 
     141                /** 
     142                 * <p> 
     143                 * sets the value of the measure context free as well as specific to the 
     144                 * provided context 
     145                 * </p> 
     146                 */ 
     147                private void set(ITask context, int value) { 
     148                        contextFreeValue = value; 
     149 
     150                        if (context != null) { 
     151                                if (values == null) { 
     152                                        values = new HashMap<ITask, Integer>(); 
     153                                } 
     154 
     155                                values.put(context, value); 
     156                        } 
     157                } 
     158 
     159        } 
     160 
     161        /** 
     162         * <p> 
     163         * the task to which the infos belong 
     164         * </p> 
     165         */ 
     166        private final ITask task; 
     167 
     168        /** 
     169         * <p> 
     170         * all available measures for the task 
     171         * </p> 
     172         */ 
     173        private final ArrayList<Measure> measures = new ArrayList<Measure>(); 
     174 
     175        /** 
     176         * <p> 
     177         * initialized the task infos with the task to which they belong. 
     178         * </p> 
     179         *  
     180         * @param task 
     181         */ 
     182        TaskInfo(ITask task) { 
     183                this.task = task; 
     184        } 
     185 
     186        /** 
     187         * <p> 
     188         * must be called to indicate that a new new measures for the provided 
     189         * metric are about to be calculated and added. 
     190         * </p> 
     191         * 
     192         * @param metric 
     193         *            the metric for which measures are about to be provided 
     194         */ 
     195        void addMeasure(TaskMetric metric) { 
     196                Measure measure = getMeasure(metric); 
     197 
     198                if (measure != null) { 
     199                        throw new IllegalArgumentException("measure for metric " + metric 
     200                                        + " already exists."); 
     201                } 
     202 
     203                measure = new Measure(metric); 
     204                measures.add(measure); 
     205        } 
     206 
     207        /** 
     208         * <p> 
     209         * convenience method to internally determine the measure for a specific 
     210         * metric 
     211         * </p> 
     212         */ 
     213        private Measure getMeasure(TaskMetric metric) { 
     214                for (final Measure candidate : measures) { 
     215                        if (candidate.getMetric().equals(metric)) { 
     216                                return candidate; 
     217                        } 
     218                } 
     219 
     220                return null; 
     221        } 
     222 
     223        /* 
     224         * (non-Javadoc) 
     225         *  
     226         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInfo#getMeasures() 
     227         */ 
     228        @Override 
     229        public IMeasure[] getMeasures() { 
     230                measures.trimToSize(); 
     231                return measures.toArray(new IMeasure[measures.size()]); 
     232        } 
     233 
     234        /* 
     235         * (non-Javadoc) 
     236         *  
     237         * @see 
     238         * de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInfo#getMeasureValue(java 
     239         * .lang.String) 
     240         */ 
     241        @Override 
     242        public int getMeasureValue(TaskMetric metric) { 
     243                final Measure measure = getMeasure(metric); 
     244 
     245                if (measure == null) { 
     246                        throw new IllegalArgumentException("unknown metric " + metric); 
     247                } 
     248 
     249                return measure.getValue(); 
     250        } 
     251 
     252        /* 
     253         * (non-Javadoc) 
     254         *  
     255         * @see 
     256         * de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInfo#getMeasureValue(java 
     257         * .lang.String, de.ugoe.cs.autoquest.tasktrees.treeifc.ITask) 
     258         */ 
     259        @Override 
     260        public int getMeasureValue(TaskMetric metric, ITask context) { 
     261                final Measure measure = getMeasure(metric); 
     262 
     263                if (measure == null) { 
     264                        throw new IllegalArgumentException("unknown metric " + metric); 
     265                } 
     266 
     267                return measure.getValue(context); 
     268        } 
     269 
     270        /* 
     271         * (non-Javadoc) 
     272         *  
     273         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInfo#getTask() 
     274         */ 
     275        @Override 
     276        public ITask getTask() { 
     277                return task; 
     278        } 
     279 
     280        /** 
     281         * <p> 
     282         * increases a specific value for a measure of a specific metric in the 
     283         * provided context of the task 
     284         * </p> 
     285         *  
     286         * @param metric 
     287         *            the metric to which the value belongs 
     288         * @param context 
     289         *            the context of the task in which the measure was recorded 
     290         * @param increment 
     291         *            the increment to be added to the value of the measure 
     292         */ 
     293        void increaseCount(TaskMetric metric, ITask context, int increment) { 
     294                final Measure measure = getMeasure(metric); 
     295 
     296                if (measure == null) { 
     297                        throw new IllegalArgumentException( 
     298                                        "unknown metric. Please create a measure " 
     299                                                        + "for the metric before using it."); 
     300                } 
     301 
     302                measure.increase(context, increment); 
     303        } 
     304 
     305        /** 
     306         * <p> 
     307         * sets a specific value for a measure of a specific metric in the provided 
     308         * context of the task 
     309         * </p> 
     310         *  
     311         * @param metric 
     312         *            the metric to which the value belongs 
     313         * @param context 
     314         *            the context of the task in which the measure was recorded 
     315         * @param value 
     316         *            the value of the measure 
     317         */ 
     318        void setCount(TaskMetric metric, ITask context, int value) { 
     319                final Measure measure = getMeasure(metric); 
     320 
     321                if (measure == null) { 
     322                        throw new IllegalArgumentException( 
     323                                        "unknown metric. Please create a measure " 
     324                                                        + "for the metric before using it."); 
     325                } 
     326 
     327                measure.set(context, value); 
     328        } 
     329 
     330        /* 
     331         * (non-Javadoc) 
     332         *  
     333         * @see java.lang.Object#toString() 
     334         */ 
     335        @Override 
     336        public synchronized String toString() { 
     337                return "TaskInfo(" + task + ")"; 
     338        } 
    302339 
    303340} 
  • branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskInstance.java

    r1405 r1733  
    2828 */ 
    2929class TaskInstance implements ITaskInstance { 
    30      
    31     /** 
    32      * <p> 
    33      * default serial version UID 
    34      * </p> 
    35      */ 
    36     private static final long serialVersionUID = 1L; 
    3730 
    38     /** 
    39      * <p> 
    40      * used as a counter to generate new ids for each newly created task instance. May overflow. 
    41      * </p> 
    42      */ 
    43     private static int temporalId = 0; 
     31        /** 
     32         * <p> 
     33         * creates a new id for a task instance using {@link #temporalId} by 
     34         * incrementing it an returning its current value. Resets the counter if 
     35         * {@link Integer.MAX_VALUE} is reached. 
     36         * </p> 
     37         *  
     38         * @return a new unique id for a task instance as long as 
     39         *         {@link #temporalId} does not overflow 
     40         */ 
     41        private static synchronized int getNewId() { 
     42                if (temporalId == Integer.MAX_VALUE) { 
     43                        temporalId = 0; 
     44                } 
    4445 
    45     /** 
    46      * <p> 
    47      * the task instantiated by this task instance 
    48      * </p> 
    49      */ 
    50     private ITask task; 
    51      
    52     /** 
    53      * <p> 
    54      * the id of the task instance (unique throughout the system as long as {@link #temporalId} 
    55      * does not overflow. 
    56      * </p> 
    57      */ 
    58     private int id; 
     46                return temporalId++; 
     47        } 
    5948 
    60     /** 
    61      * <p> 
    62      * instantiated the task instance with the task that is instantiated by the instance. It also 
    63      * assigns a unique id to the instance using {@link #getNewId()}. 
    64      * </p> 
    65      */ 
    66     TaskInstance(ITask task) { 
    67         this.task = task; 
    68         id = getNewId(); 
    69     } 
     49        /** 
     50         * <p> 
     51         * default serial version UID 
     52         * </p> 
     53         */ 
     54        private static final long serialVersionUID = 1L; 
    7055 
    71     /** 
    72      * <p> 
    73      * creates a new id for a task instance using {@link #temporalId} by incrementing it an 
    74      * returning its current value. Resets the counter if {@link Integer.MAX_VALUE} is reached. 
    75      * </p> 
    76      *  
    77      * @return a new unique id for a task instance as long as {@link #temporalId} does not overflow 
    78      */ 
    79     private static synchronized int getNewId() { 
    80         if (temporalId == Integer.MAX_VALUE) { 
    81             temporalId = 0; 
    82         } 
     56        /** 
     57         * <p> 
     58         * used as a counter to generate new ids for each newly created task 
     59         * instance. May overflow. 
     60         * </p> 
     61         */ 
     62        private static int temporalId = 0; 
    8363 
    84         return temporalId++; 
    85     } 
     64        /** 
     65         * <p> 
     66         * the task instantiated by this task instance 
     67         * </p> 
     68         */ 
     69        private ITask task; 
    8670 
    87     /* (non-Javadoc) 
    88      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance#getTask() 
    89      */ 
    90     @Override 
    91     public ITask getTask() { 
    92         return task; 
    93     } 
     71        /** 
     72         * <p> 
     73         * the id of the task instance (unique throughout the system as long as 
     74         * {@link #temporalId} does not overflow. 
     75         * </p> 
     76         */ 
     77        private final int id; 
    9478 
    95     /* 
    96      * (non-Javadoc) 
    97      *  
    98      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.TaskTreeNode#equals(TaskTreeNode) 
    99      */ 
    100     @Override 
    101     public boolean equals(ITaskInstance taskInstance) { 
    102         // task instances are only equal if they are identical or if they have the same id 
    103         // (may happen, if they are cloned) 
    104         return (this == taskInstance) || (this.hashCode() == taskInstance.hashCode()); 
    105     } 
     79        /** 
     80         * <p> 
     81         * instantiated the task instance with the task that is instantiated by the 
     82         * instance. It also assigns a unique id to the instance using 
     83         * {@link #getNewId()}. 
     84         * </p> 
     85         */ 
     86        TaskInstance(ITask task) { 
     87                this.task = task; 
     88                id = getNewId(); 
     89        } 
    10690 
    107     /* (non-Javadoc) 
    108      * @see java.lang.Object#hashCode() 
    109      */ 
    110     @Override 
    111     public synchronized int hashCode() { 
    112         return id; 
    113     } 
     91        /* 
     92         * (non-Javadoc) 
     93         *  
     94         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance#accept( 
     95         * ITaskInstanceVisitor) 
     96         */ 
     97        @Override 
     98        public void accept(ITaskInstanceVisitor visitor) { 
     99                visitor.visit(this); 
     100        } 
    114101 
    115     /* (non-Javadoc) 
    116      * @see java.lang.Object#toString() 
    117      */ 
    118     @Override 
    119     public synchronized String toString() { 
    120         StringBuffer result = new StringBuffer(); 
    121         result.append(task.getType()); 
    122         result.append(" #"); 
    123         result.append(task.getId()); 
    124          
    125         if (task.getDescription() != null) { 
    126             result.append(" ("); 
    127             result.append(task.getDescription()); 
    128             result.append(')'); 
    129         } 
    130          
    131         /*if (children != null) { 
    132             result.append(", "); 
    133             result.append(children.size()); 
    134             result.append(" children"); 
    135         }*/ 
    136          
    137         return result.toString(); 
    138     } 
     102        /* 
     103         * (non-Javadoc) 
     104         *  
     105         * @see java.lang.Object#clone() 
     106         */ 
     107        @Override 
     108        public synchronized ITaskInstance clone() { 
     109                TaskInstance clone = null; 
     110                try { 
     111                        clone = (TaskInstance) super.clone(); 
     112                } catch (final CloneNotSupportedException e) { 
     113                        // this should never happen. Therefore simply dump the exception 
     114                        e.printStackTrace(); 
     115                } 
    139116 
    140     /* (non-Javadoc) 
    141      * @see java.lang.Object#clone() 
    142      */ 
    143     @Override 
    144     public synchronized ITaskInstance clone() { 
    145         TaskInstance clone = null; 
    146         try { 
    147             clone = (TaskInstance) super.clone(); 
    148         } 
    149         catch (CloneNotSupportedException e) { 
    150             // this should never happen. Therefore simply dump the exception 
    151             e.printStackTrace(); 
    152         } 
     117                return clone; 
     118        } 
    153119 
    154         return clone; 
    155     } 
     120        /* 
     121         * (non-Javadoc) 
     122         *  
     123         * @see 
     124         * de.ugoe.cs.autoquest.tasktrees.treeifc.TaskTreeNode#equals(TaskTreeNode) 
     125         */ 
     126        @Override 
     127        public boolean equals(ITaskInstance taskInstance) { 
     128                // task instances are only equal if they are identical or if they have 
     129                // the same id 
     130                // (may happen, if they are cloned) 
     131                return (this == taskInstance) 
     132                                || (this.hashCode() == taskInstance.hashCode()); 
     133        } 
    156134 
    157     /* (non-Javadoc) 
    158      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance#accept(ITaskInstanceVisitor) 
    159      */ 
    160     @Override 
    161     public void accept(ITaskInstanceVisitor visitor) { 
    162         visitor.visit(this); 
    163     } 
     135        /* 
     136         * (non-Javadoc) 
     137         *  
     138         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance#getTask() 
     139         */ 
     140        @Override 
     141        public ITask getTask() { 
     142                return task; 
     143        } 
    164144 
    165     /** 
    166      * <p> 
    167      * used to update the task represented through this instance 
    168      * </p> 
    169      *  
    170      * @param task the task to set 
    171      */ 
    172     void setTask(ITask task) { 
    173         this.task = task; 
    174     } 
     145        /* 
     146         * (non-Javadoc) 
     147         *  
     148         * @see java.lang.Object#hashCode() 
     149         */ 
     150        @Override 
     151        public synchronized int hashCode() { 
     152                return id; 
     153        } 
     154 
     155        /** 
     156         * <p> 
     157         * used to update the task represented through this instance 
     158         * </p> 
     159         *  
     160         * @param task 
     161         *            the task to set 
     162         */ 
     163        void setTask(ITask task) { 
     164                this.task = task; 
     165        } 
     166 
     167        /* 
     168         * (non-Javadoc) 
     169         *  
     170         * @see java.lang.Object#toString() 
     171         */ 
     172        @Override 
     173        public synchronized String toString() { 
     174                final StringBuffer result = new StringBuffer(); 
     175                result.append(task.getType()); 
     176                result.append(" #"); 
     177                result.append(task.getId()); 
     178 
     179                if (task.getDescription() != null) { 
     180                        result.append(" ("); 
     181                        result.append(task.getDescription()); 
     182                        result.append(')'); 
     183                } 
     184 
     185                /* 
     186                 * if (children != null) { result.append(", "); 
     187                 * result.append(children.size()); result.append(" children"); } 
     188                 */ 
     189 
     190                return result.toString(); 
     191        } 
    175192 
    176193} 
  • branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskModel.java

    r1494 r1733  
    4343 * <p> 
    4444 * this is the default implementation of the interface {@link ITaskModel}. It 
    45  * does not do anything fancy except implementing the interface. It also calculates on 
    46  * initialisations the measures for diverse metrics of the task belonging to the model 
     45 * does not do anything fancy except implementing the interface. It also 
     46 * calculates on initialisations the measures for diverse metrics of the task 
     47 * belonging to the model 
    4748 * </p> 
    4849 *  
     
    5051 */ 
    5152class TaskModel implements ITaskModel { 
    52      
    53     /** 
    54      * <p> 
    55      * default serial version UID 
    56      * </p> 
    57      */ 
    58     private static final long serialVersionUID = 1L; 
    59      
    60     /** 
    61      * <p> 
    62      * all metrics calculated by this type of task model 
    63      * </p> 
    64      */ 
    65     private static final TaskMetric[] taskMetrics = new TaskMetric[] 
    66         { TaskMetric.COUNT, 
    67           TaskMetric.DEPTH, 
    68           TaskMetric.EVENT_COVERAGE, 
    69           TaskMetric.EVENT_COVERAGE_RATIO, 
    70           TaskMetric.EVENT_COVERAGE_QUANTILE }; 
    71  
    72     /** 
    73      * <p> 
    74      * the user sessions belonging to the model 
    75      * </p> 
    76      */ 
    77     private List<IUserSession> userSessions; 
    78  
    79     /** 
    80      * <p> 
    81      * index for effectively accessing the model and calculating statistics about it 
    82      * </p> 
    83      */ 
    84     private transient TaskModelIndex index = null; 
    85      
    86     /** 
    87      * <p> 
    88      * initializes the task model with the user sessions out of which the tasks are extracted 
    89      * </p> 
    90      *  
    91      * @param userSessions as described 
    92      */ 
    93     TaskModel(List<IUserSession> userSessions) { 
    94         if ((userSessions == null) || (userSessions.size() == 0)) { 
    95             throw new IllegalArgumentException("user sessions must not be null"); 
    96         } 
    97          
    98         this.userSessions = userSessions; 
    99     } 
    100  
    101      
    102     /* (non-Javadoc) 
    103      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getUserSessions() 
    104      */ 
    105     @Override 
    106     public List<IUserSession> getUserSessions() { 
    107         ensureInitialized(); 
    108         return Collections.unmodifiableList(userSessions); 
    109     } 
    110  
    111  
    112     /* (non-Javadoc) 
    113      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getTasks() 
    114      */ 
    115     @Override 
    116     public Collection<ITask> getTasks() { 
    117         ensureInitialized(); 
    118         return Collections.unmodifiableCollection(index.taskMap.keySet()); 
    119     } 
    120  
    121  
    122     /* (non-Javadoc) 
    123      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getTaskInfo(ITask) 
    124      */ 
    125     @Override 
    126     public ITaskInfo getTaskInfo(ITask task) { 
    127         ensureInitialized(); 
    128         return index.taskMap.get(task); 
    129     } 
    130  
    131     /* (non-Javadoc) 
    132      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getAllMetrics() 
    133      */ 
    134     @Override 
    135     public TaskMetric[] getAllMetrics() { 
    136         return taskMetrics; 
    137     } 
    138  
    139  
    140     /* (non-Javadoc) 
    141      * @see java.lang.Object#clone() 
    142      */ 
    143     @Override 
    144     public TaskModel clone() { 
    145         return new TaskModel(userSessions); 
    146     } 
    147  
    148     /** 
    149      * <p> 
    150      * internal convenience method that initializes the internal index and calculates all measures 
    151      * for metrics available for the tasks 
    152      * </p> 
    153      */ 
    154     private synchronized void ensureInitialized() { 
    155         if (index == null) { 
    156             index = new TaskModelIndex(); 
    157              
    158             for (IUserSession session : this.userSessions) { 
    159                 for (ITaskInstance taskInstance : session) { 
    160                     index.handleTaskInstance(taskInstance, null); 
    161                 } 
    162             } 
    163              
    164             // count all events covered 
    165             int allEventsCovered = 0; 
    166             Collection<ITask> tasks = getTasks(); 
    167             for (ITask task : tasks) { 
    168                 if (task instanceof IEventTask) { 
    169                     allEventsCovered += task.getInstances().size(); 
    170                 } 
    171             } 
    172              
    173             int[] eventCoverageRatios = new int[tasks.size()]; 
    174             int i = 0; 
    175  
    176             // add some further measures 
    177             for (ITask task : tasks) { 
    178                 TaskInfo info = index.taskMap.get(task); 
    179                 info.addMeasure(TaskMetric.EVENT_COVERAGE_RATIO); 
    180                  
    181                 int coveredEvents = info.getMeasureValue(TaskMetric.EVENT_COVERAGE); 
    182                 int coverageRatio = 0; 
    183                  
    184                 if (allEventsCovered > 0) { 
    185                     coverageRatio = (coveredEvents * 1000) / allEventsCovered; 
    186                 } 
    187                  
    188                 eventCoverageRatios[i++] = coverageRatio; 
    189                 info.setCount(TaskMetric.EVENT_COVERAGE_RATIO, null, coverageRatio); 
    190             } 
    191              
    192             Arrays.sort(eventCoverageRatios); 
    193              
    194             // add some further measures 
    195             for (ITask task : tasks) { 
    196                 TaskInfo info = index.taskMap.get(task); 
    197                 info.addMeasure(TaskMetric.EVENT_COVERAGE_QUANTILE); 
    198                 int quantile = Arrays.binarySearch 
    199                     (eventCoverageRatios, info.getMeasureValue(TaskMetric.EVENT_COVERAGE_RATIO)); 
    200                  
    201                 quantile = 1000 * quantile / eventCoverageRatios.length; 
    202                  
    203                 info.setCount(TaskMetric.EVENT_COVERAGE_QUANTILE, null, quantile); 
    204             } 
    205              
    206             //index.dumpToCSV(System.out); 
    207             /*try { 
    208                 OutputStream stream = new FileOutputStream(new File("tasks.csv")); 
    209                 index.dumpToCSV(new PrintStream(stream)); 
    210                 stream.close(); 
    211             } 
    212             catch (FileNotFoundException e) { 
    213                 e.printStackTrace(); 
    214             }*/ 
    215         } 
    216          
    217     } 
    218  
    219     /** 
    220      * <p> 
    221      * the index of task infos used internally. The index is created once and while that filled 
    222      * with task infos for each observed task containing all measures for metrics belonging 
    223      * to the tasks.  
    224      * </p> 
    225      *  
    226      * @author Patrick Harms 
    227      */ 
    228     private static class TaskModelIndex { 
    229  
    230         /** 
    231          * <p> 
    232          * the tasks contained in the user session belonging to the model as well as statistical 
    233          * infos about them 
    234          * </p> 
    235          */ 
    236         private Map<ITask, TaskInfo> taskMap = new HashMap<ITask, TaskInfo>(); 
    237  
    238         /** 
    239          * <p> 
    240          * called on initialization to fill the index with infos about the given task instance 
    241          * as well as to calculate the appropriate metrics 
    242          * </p> 
    243          */ 
    244         private int[] handleTaskInstance(ITaskInstance taskInstance, ITask context) { 
    245             int eventTaskInstancesCovered = 0; 
    246             int depth = 0; 
    247              
    248             if (taskInstance instanceof ITaskInstanceList) { 
    249                 for (ITaskInstance child : (ITaskInstanceList) taskInstance) { 
    250                     int[] measures = handleTaskInstance(child, taskInstance.getTask()); 
    251                     eventTaskInstancesCovered += measures[0]; 
    252                     depth = Math.max(depth, measures[1]); 
    253                 } 
    254                  
    255                 if ((((ITaskInstanceList) taskInstance).size() == 0) && 
    256                     (taskInstance instanceof IIterationInstance)) 
    257                 { 
    258                     // ensure also empty task infos for unselected variants 
    259                     ensureTaskInfo(((IIteration) taskInstance.getTask()).getMarkedTask(), context); 
    260                 } 
    261             } 
    262             else if (taskInstance instanceof ISelectionInstance) { 
    263                 ITaskInstance child = ((ISelectionInstance) taskInstance).getChild(); 
    264                 int[] measures = handleTaskInstance(child, taskInstance.getTask()); 
    265                 eventTaskInstancesCovered += measures[0]; 
    266                 depth = Math.max(depth, measures[1]); 
    267                  
    268                 // ensure also empty task infos for unselected variants 
    269                 for (ITask otherChildTask : ((ISelection) taskInstance.getTask()).getChildren()) { 
    270                     ensureTaskInfo(otherChildTask, context); 
    271                 } 
    272             } 
    273             else if (taskInstance instanceof IOptionalInstance) { 
    274                 ITaskInstance child = ((IOptionalInstance) taskInstance).getChild(); 
    275                 if (child != null) { 
    276                     int[] measures = handleTaskInstance(child, taskInstance.getTask()); 
    277                     eventTaskInstancesCovered += measures[0]; 
    278                     depth = Math.max(depth, measures[1]); 
    279                 } 
    280                 else { 
    281                     // ensure also empty task infos for unselected variants 
    282                     ensureTaskInfo(((IOptional) taskInstance.getTask()).getMarkedTask(), context); 
    283                 } 
    284             } 
    285             else if (taskInstance instanceof IEventTaskInstance) { 
    286                 eventTaskInstancesCovered = 1; 
    287             } 
    288              
    289             depth++; 
    290              
    291             ensureTaskInfo(taskInstance.getTask(), context, eventTaskInstancesCovered, depth); 
    292              
    293             return new int[] { eventTaskInstancesCovered, depth }; 
    294         } 
    295          
    296         /** 
    297          * <p> 
    298          * internal convenience method to build the task model during initialization 
    299          * </p> 
    300          */ 
    301         private void ensureTaskInfo(ITask task, ITask context) { 
    302             ensureTaskInfo(task, context, 0, 0); 
    303              
    304             if (task instanceof IStructuringTemporalRelationship) { 
    305                 for (ITask child : ((IStructuringTemporalRelationship) task).getChildren()) { 
    306                     ensureTaskInfo(child, task); 
    307                 } 
    308             } 
    309             else if (task instanceof IMarkingTemporalRelationship) { 
    310                 ensureTaskInfo(((IMarkingTemporalRelationship) task).getMarkedTask(), task); 
    311             } 
    312          
    313         } 
    314          
    315         /** 
    316          * <p> 
    317          * internal convenience method to build the task model during initialization. Adds a new 
    318          * task info object to the map for the provided task and fills it with measures. If there 
    319          * are already some task infos for the task, the contained measures are updated according 
    320          * to the parameters. 
    321          * </p> 
    322          */ 
    323         private void ensureTaskInfo(ITask task, 
    324                                     ITask context, 
    325                                     int   eventTaskInstancesCovered, 
    326                                     int   depth) 
    327         { 
    328             TaskInfo taskInfo = taskMap.get(task); 
    329  
    330             if (taskInfo == null) { 
    331                 taskInfo = new TaskInfo(task); 
    332                 taskInfo.addMeasure(TaskMetric.COUNT); 
    333                 taskInfo.addMeasure(TaskMetric.EVENT_COVERAGE); 
    334                 taskInfo.addMeasure(TaskMetric.DEPTH); 
    335                 taskMap.put(task, taskInfo); 
    336                  
    337                 taskInfo.setCount(TaskMetric.DEPTH, null, getDepth(task)); 
    338             } 
    339  
    340             taskInfo.increaseCount(TaskMetric.COUNT, context, 1); 
    341             taskInfo.increaseCount(TaskMetric.EVENT_COVERAGE, context, eventTaskInstancesCovered); 
    342  
    343             taskInfo.setCount(TaskMetric.DEPTH, context, depth); 
    344         } 
    345  
    346         /** 
    347          * <p> 
    348          * internal convenience method to calculate the maximum depth of a task 
    349          * </p> 
    350          */ 
    351         private int getDepth(ITask task) { 
    352             if (task instanceof IMarkingTemporalRelationship) { 
    353                 return getDepth(((IMarkingTemporalRelationship) task).getMarkedTask()) + 1; 
    354             } 
    355             else if (task instanceof IStructuringTemporalRelationship) { 
    356                 int maxDepth = 0; 
    357                  
    358                 for (ITask child : ((IStructuringTemporalRelationship) task).getChildren()) { 
    359                     maxDepth = Math.max(maxDepth, getDepth(child)); 
    360                 } 
    361                  
    362                 return maxDepth + 1; 
    363             } 
    364             else { 
    365                 // event tasks 
    366                 return 1; 
    367             } 
    368         } 
    369  
    370         /** 
    371          * 
    372          */ 
    373         /*private void dumpToCSV(PrintStream out) { 
    374             out.println("taskid;depth;count;eventcoverage;eventcoverageratio"); 
    375              
    376             for (Map.Entry<ITask, TaskInfo> entry : taskMap.entrySet()) { 
    377                 out.print(entry.getKey().getId()); 
    378                 out.print(';'); 
    379                 out.print(entry.getValue().getMeasureValue(TaskMetric.DEPTH)); 
    380                 out.print(';'); 
    381                 out.print(entry.getValue().getMeasureValue(TaskMetric.COUNT)); 
    382                 out.print(';'); 
    383                 out.print(entry.getValue().getMeasureValue(TaskMetric.EVENT_COVERAGE)); 
    384                 out.print(';'); 
    385                 out.print(entry.getValue().getMeasureValue(TaskMetric.EVENT_COVERAGE_RATIO)); 
    386                 out.println(); 
    387             } 
    388         }*/ 
    389  
    390     } 
    391  
     53 
     54        /** 
     55         * <p> 
     56         * the index of task infos used internally. The index is created once and 
     57         * while that filled with task infos for each observed task containing all 
     58         * measures for metrics belonging to the tasks. 
     59         * </p> 
     60         *  
     61         * @author Patrick Harms 
     62         */ 
     63        private static class TaskModelIndex { 
     64 
     65                /** 
     66                 * <p> 
     67                 * the tasks contained in the user session belonging to the model as 
     68                 * well as statistical infos about them 
     69                 * </p> 
     70                 */ 
     71                private final Map<ITask, TaskInfo> taskMap = new HashMap<ITask, TaskInfo>(); 
     72 
     73                /** 
     74                 * <p> 
     75                 * internal convenience method to build the task model during 
     76                 * initialization 
     77                 * </p> 
     78                 */ 
     79                private void ensureTaskInfo(ITask task, ITask context) { 
     80                        ensureTaskInfo(task, context, 0, 0); 
     81 
     82                        if (task instanceof IStructuringTemporalRelationship) { 
     83                                for (final ITask child : ((IStructuringTemporalRelationship) task) 
     84                                                .getChildren()) { 
     85                                        ensureTaskInfo(child, task); 
     86                                } 
     87                        } else if (task instanceof IMarkingTemporalRelationship) { 
     88                                ensureTaskInfo( 
     89                                                ((IMarkingTemporalRelationship) task).getMarkedTask(), 
     90                                                task); 
     91                        } 
     92 
     93                } 
     94 
     95                /** 
     96                 * <p> 
     97                 * internal convenience method to build the task model during 
     98                 * initialization. Adds a new task info object to the map for the 
     99                 * provided task and fills it with measures. If there are already some 
     100                 * task infos for the task, the contained measures are updated according 
     101                 * to the parameters. 
     102                 * </p> 
     103                 */ 
     104                private void ensureTaskInfo(ITask task, ITask context, 
     105                                int eventTaskInstancesCovered, int depth) { 
     106                        TaskInfo taskInfo = taskMap.get(task); 
     107 
     108                        if (taskInfo == null) { 
     109                                taskInfo = new TaskInfo(task); 
     110                                taskInfo.addMeasure(TaskMetric.COUNT); 
     111                                taskInfo.addMeasure(TaskMetric.EVENT_COVERAGE); 
     112                                taskInfo.addMeasure(TaskMetric.DEPTH); 
     113                                taskMap.put(task, taskInfo); 
     114 
     115                                taskInfo.setCount(TaskMetric.DEPTH, null, getDepth(task)); 
     116                        } 
     117 
     118                        taskInfo.increaseCount(TaskMetric.COUNT, context, 1); 
     119                        taskInfo.increaseCount(TaskMetric.EVENT_COVERAGE, context, 
     120                                        eventTaskInstancesCovered); 
     121 
     122                        taskInfo.setCount(TaskMetric.DEPTH, context, depth); 
     123                } 
     124 
     125                /** 
     126                 * <p> 
     127                 * internal convenience method to calculate the maximum depth of a task 
     128                 * </p> 
     129                 */ 
     130                private int getDepth(ITask task) { 
     131                        if (task instanceof IMarkingTemporalRelationship) { 
     132                                return getDepth(((IMarkingTemporalRelationship) task) 
     133                                                .getMarkedTask()) + 1; 
     134                        } else if (task instanceof IStructuringTemporalRelationship) { 
     135                                int maxDepth = 0; 
     136 
     137                                for (final ITask child : ((IStructuringTemporalRelationship) task) 
     138                                                .getChildren()) { 
     139                                        maxDepth = Math.max(maxDepth, getDepth(child)); 
     140                                } 
     141 
     142                                return maxDepth + 1; 
     143                        } else { 
     144                                // event tasks 
     145                                return 1; 
     146                        } 
     147                } 
     148 
     149                /** 
     150                 * <p> 
     151                 * called on initialization to fill the index with infos about the given 
     152                 * task instance as well as to calculate the appropriate metrics 
     153                 * </p> 
     154                 */ 
     155                private int[] handleTaskInstance(ITaskInstance taskInstance, 
     156                                ITask context) { 
     157                        int eventTaskInstancesCovered = 0; 
     158                        int depth = 0; 
     159 
     160                        if (taskInstance instanceof ITaskInstanceList) { 
     161                                for (final ITaskInstance child : (ITaskInstanceList) taskInstance) { 
     162                                        final int[] measures = handleTaskInstance(child, 
     163                                                        taskInstance.getTask()); 
     164                                        eventTaskInstancesCovered += measures[0]; 
     165                                        depth = Math.max(depth, measures[1]); 
     166                                } 
     167 
     168                                if ((((ITaskInstanceList) taskInstance).size() == 0) 
     169                                                && (taskInstance instanceof IIterationInstance)) { 
     170                                        // ensure also empty task infos for unselected variants 
     171                                        ensureTaskInfo( 
     172                                                        ((IIteration) taskInstance.getTask()) 
     173                                                                        .getMarkedTask(), 
     174                                                        context); 
     175                                } 
     176                        } else if (taskInstance instanceof ISelectionInstance) { 
     177                                final ITaskInstance child = ((ISelectionInstance) taskInstance) 
     178                                                .getChild(); 
     179                                final int[] measures = handleTaskInstance(child, 
     180                                                taskInstance.getTask()); 
     181                                eventTaskInstancesCovered += measures[0]; 
     182                                depth = Math.max(depth, measures[1]); 
     183 
     184                                // ensure also empty task infos for unselected variants 
     185                                for (final ITask otherChildTask : ((ISelection) taskInstance 
     186                                                .getTask()).getChildren()) { 
     187                                        ensureTaskInfo(otherChildTask, context); 
     188                                } 
     189                        } else if (taskInstance instanceof IOptionalInstance) { 
     190                                final ITaskInstance child = ((IOptionalInstance) taskInstance) 
     191                                                .getChild(); 
     192                                if (child != null) { 
     193                                        final int[] measures = handleTaskInstance(child, 
     194                                                        taskInstance.getTask()); 
     195                                        eventTaskInstancesCovered += measures[0]; 
     196                                        depth = Math.max(depth, measures[1]); 
     197                                } else { 
     198                                        // ensure also empty task infos for unselected variants 
     199                                        ensureTaskInfo( 
     200                                                        ((IOptional) taskInstance.getTask()) 
     201                                                                        .getMarkedTask(), 
     202                                                        context); 
     203                                } 
     204                        } else if (taskInstance instanceof IEventTaskInstance) { 
     205                                eventTaskInstancesCovered = 1; 
     206                        } 
     207 
     208                        depth++; 
     209 
     210                        ensureTaskInfo(taskInstance.getTask(), context, 
     211                                        eventTaskInstancesCovered, depth); 
     212 
     213                        return new int[] { eventTaskInstancesCovered, depth }; 
     214                } 
     215 
     216                /** 
     217                 * 
     218                 */ 
     219                /* 
     220                 * private void dumpToCSV(PrintStream out) { 
     221                 * out.println("taskid;depth;count;eventcoverage;eventcoverageratio"); 
     222                 *  
     223                 * for (Map.Entry<ITask, TaskInfo> entry : taskMap.entrySet()) { 
     224                 * out.print(entry.getKey().getId()); out.print(';'); 
     225                 * out.print(entry.getValue().getMeasureValue(TaskMetric.DEPTH)); 
     226                 * out.print(';'); 
     227                 * out.print(entry.getValue().getMeasureValue(TaskMetric.COUNT)); 
     228                 * out.print(';'); 
     229                 * out.print(entry.getValue().getMeasureValue(TaskMetric. 
     230                 * EVENT_COVERAGE)); out.print(';'); 
     231                 * out.print(entry.getValue().getMeasureValue 
     232                 * (TaskMetric.EVENT_COVERAGE_RATIO)); out.println(); } } 
     233                 */ 
     234 
     235        } 
     236 
     237        /** 
     238         * <p> 
     239         * default serial version UID 
     240         * </p> 
     241         */ 
     242        private static final long serialVersionUID = 1L; 
     243 
     244        /** 
     245         * <p> 
     246         * all metrics calculated by this type of task model 
     247         * </p> 
     248         */ 
     249        private static final TaskMetric[] taskMetrics = new TaskMetric[] { 
     250                        TaskMetric.COUNT, TaskMetric.DEPTH, TaskMetric.EVENT_COVERAGE, 
     251                        TaskMetric.EVENT_COVERAGE_RATIO, TaskMetric.EVENT_COVERAGE_QUANTILE }; 
     252 
     253        /** 
     254         * <p> 
     255         * the user sessions belonging to the model 
     256         * </p> 
     257         */ 
     258        private final List<IUserSession> userSessions; 
     259 
     260        /** 
     261         * <p> 
     262         * index for effectively accessing the model and calculating statistics 
     263         * about it 
     264         * </p> 
     265         */ 
     266        private transient TaskModelIndex index = null; 
     267 
     268        /** 
     269         * <p> 
     270         * initializes the task model with the user sessions out of which the tasks 
     271         * are extracted 
     272         * </p> 
     273         *  
     274         * @param userSessions 
     275         *            as described 
     276         */ 
     277        TaskModel(List<IUserSession> userSessions) { 
     278                if ((userSessions == null) || (userSessions.size() == 0)) { 
     279                        throw new IllegalArgumentException("user sessions must not be null"); 
     280                } 
     281 
     282                this.userSessions = userSessions; 
     283        } 
     284 
     285        /* 
     286         * (non-Javadoc) 
     287         *  
     288         * @see java.lang.Object#clone() 
     289         */ 
     290        @Override 
     291        public TaskModel clone() { 
     292                return new TaskModel(userSessions); 
     293        } 
     294 
     295        /** 
     296         * <p> 
     297         * internal convenience method that initializes the internal index and 
     298         * calculates all measures for metrics available for the tasks 
     299         * </p> 
     300         */ 
     301        private synchronized void ensureInitialized() { 
     302                if (index == null) { 
     303                        index = new TaskModelIndex(); 
     304 
     305                        for (final IUserSession session : this.userSessions) { 
     306                                for (final ITaskInstance taskInstance : session) { 
     307                                        index.handleTaskInstance(taskInstance, null); 
     308                                } 
     309                        } 
     310 
     311                        // count all events covered 
     312                        int allEventsCovered = 0; 
     313                        final Collection<ITask> tasks = getTasks(); 
     314                        for (final ITask task : tasks) { 
     315                                if (task instanceof IEventTask) { 
     316                                        allEventsCovered += task.getInstances().size(); 
     317                                } 
     318                        } 
     319 
     320                        final int[] eventCoverageRatios = new int[tasks.size()]; 
     321                        int i = 0; 
     322 
     323                        // add some further measures 
     324                        for (final ITask task : tasks) { 
     325                                final TaskInfo info = index.taskMap.get(task); 
     326                                info.addMeasure(TaskMetric.EVENT_COVERAGE_RATIO); 
     327 
     328                                final int coveredEvents = info 
     329                                                .getMeasureValue(TaskMetric.EVENT_COVERAGE); 
     330                                int coverageRatio = 0; 
     331 
     332                                if (allEventsCovered > 0) { 
     333                                        coverageRatio = (coveredEvents * 1000) / allEventsCovered; 
     334                                } 
     335 
     336                                eventCoverageRatios[i++] = coverageRatio; 
     337                                info.setCount(TaskMetric.EVENT_COVERAGE_RATIO, null, 
     338                                                coverageRatio); 
     339                        } 
     340 
     341                        Arrays.sort(eventCoverageRatios); 
     342 
     343                        // add some further measures 
     344                        for (final ITask task : tasks) { 
     345                                final TaskInfo info = index.taskMap.get(task); 
     346                                info.addMeasure(TaskMetric.EVENT_COVERAGE_QUANTILE); 
     347                                int quantile = Arrays.binarySearch(eventCoverageRatios, 
     348                                                info.getMeasureValue(TaskMetric.EVENT_COVERAGE_RATIO)); 
     349 
     350                                quantile = (1000 * quantile) / eventCoverageRatios.length; 
     351 
     352                                info.setCount(TaskMetric.EVENT_COVERAGE_QUANTILE, null, 
     353                                                quantile); 
     354                        } 
     355 
     356                        // index.dumpToCSV(System.out); 
     357                        /* 
     358                         * try { OutputStream stream = new FileOutputStream(new 
     359                         * File("tasks.csv")); index.dumpToCSV(new PrintStream(stream)); 
     360                         * stream.close(); } catch (FileNotFoundException e) { 
     361                         * e.printStackTrace(); } 
     362                         */ 
     363                } 
     364 
     365        } 
     366 
     367        /* 
     368         * (non-Javadoc) 
     369         *  
     370         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getAllMetrics() 
     371         */ 
     372        @Override 
     373        public TaskMetric[] getAllMetrics() { 
     374                return taskMetrics; 
     375        } 
     376 
     377        /* 
     378         * (non-Javadoc) 
     379         *  
     380         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getTaskInfo(ITask) 
     381         */ 
     382        @Override 
     383        public ITaskInfo getTaskInfo(ITask task) { 
     384                ensureInitialized(); 
     385                return index.taskMap.get(task); 
     386        } 
     387 
     388        /* 
     389         * (non-Javadoc) 
     390         *  
     391         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getTasks() 
     392         */ 
     393        @Override 
     394        public Collection<ITask> getTasks() { 
     395                ensureInitialized(); 
     396                return Collections.unmodifiableCollection(index.taskMap.keySet()); 
     397        } 
     398 
     399        /* 
     400         * (non-Javadoc) 
     401         *  
     402         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getUserSessions() 
     403         */ 
     404        @Override 
     405        public List<IUserSession> getUserSessions() { 
     406                ensureInitialized(); 
     407                return Collections.unmodifiableList(userSessions); 
     408        } 
    392409 
    393410} 
  • branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/UserSession.java

    r1407 r1733  
    3333 */ 
    3434class UserSession implements IUserSession { 
    35      
    36     /** 
    37      * <p> 
    38      * default serial version UID 
    39      * </p> 
    40      */ 
    41     private static final long serialVersionUID = 1L; 
    42      
    43     /** 
    44      * <p> 
    45      * the task instances belonging to the user session 
    46      * </p> 
    47      */ 
    48     private List<ITaskInstance> executedTasks = new ArrayList<ITaskInstance>(); 
    4935 
    50     /* (non-Javadoc) 
    51      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#get(int) 
    52      */ 
    53     @Override 
    54     public ITaskInstance get(int index) { 
    55         return executedTasks.get(index); 
    56     } 
     36        /** 
     37         * <p> 
     38         * default serial version UID 
     39         * </p> 
     40         */ 
     41        private static final long serialVersionUID = 1L; 
    5742 
    58     /* (non-Javadoc) 
    59      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#size() 
    60      */ 
    61     @Override 
    62     public int size() { 
    63         return executedTasks.size(); 
    64     } 
     43        /** 
     44         * <p> 
     45         * the task instances belonging to the user session 
     46         * </p> 
     47         */ 
     48        private List<ITaskInstance> executedTasks = new ArrayList<ITaskInstance>(); 
    6549 
    66     /* (non-Javadoc) 
    67      * @see java.lang.Iterable#iterator() 
    68      */ 
    69     @Override 
    70     public Iterator<ITaskInstance> iterator() { 
    71         return executedTasks.iterator(); 
    72     } 
     50        /** 
     51         * <p> 
     52         * used internally to add a task instance to the user session at a specific 
     53         * position 
     54         * </p> 
     55         *  
     56         * @param index 
     57         *            the index the task instance shall be added to 
     58         * @param taskInstance 
     59         *            the task instance to be added 
     60         */ 
     61        void addExecutedTask(int index, ITaskInstance taskInstance) { 
     62                executedTasks.add(index, taskInstance); 
     63        } 
    7364 
    74     /* (non-Javadoc) 
    75      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession#getExecutedTasks() 
    76      */ 
    77     @Override 
    78     public List<ITaskInstance> getExecutedTasks() { 
    79         return Collections.unmodifiableList(executedTasks); 
    80     } 
     65        /** 
     66         * <p> 
     67         * used internally to add a task instance to the user session 
     68         * </p> 
     69         *  
     70         * @param taskInstance 
     71         *            the task instance to be added 
     72         */ 
     73        void addExecutedTask(ITaskInstance taskInstance) { 
     74                executedTasks.add(taskInstance); 
     75        } 
    8176 
    82     /* (non-Javadoc) 
    83      * @see de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession#equals(IUserSession) 
    84      */ 
    85     @Override 
    86     public boolean equals(IUserSession userSession) { 
    87         // task instances are only equal if they are identical or if they have the same id 
    88         // (may happen, if they are cloned) 
    89         return (this == userSession) || (this.hashCode() == userSession.hashCode()); 
    90     } 
     77        /* 
     78         * (non-Javadoc) 
     79         *  
     80         * @see java.lang.Object#clone() 
     81         */ 
     82        @Override 
     83        public synchronized IUserSession clone() { 
     84                UserSession clone = null; 
     85                try { 
     86                        clone = (UserSession) super.clone(); 
    9187 
    92     /* (non-Javadoc) 
    93      * @see java.lang.Object#hashCode() 
    94      */ 
    95     @Override 
    96     public synchronized int hashCode() { 
    97         return super.hashCode(); 
    98     } 
     88                        clone.executedTasks = new LinkedList<ITaskInstance>(); 
    9989 
    100     /* (non-Javadoc) 
    101      * @see java.lang.Object#toString() 
    102      */ 
    103     @Override 
    104     public synchronized String toString() { 
    105         return "session (" + executedTasks.size() + " task instances)"; 
    106     } 
     90                        for (final ITaskInstance child : executedTasks) { 
     91                                clone.executedTasks.add(child.clone()); 
     92                        } 
    10793 
    108     /* (non-Javadoc) 
    109      * @see java.lang.Object#clone() 
    110      */ 
    111     @Override 
    112     public synchronized IUserSession clone() { 
    113         UserSession clone = null; 
    114         try { 
    115             clone = (UserSession) super.clone(); 
     94                } catch (final CloneNotSupportedException e) { 
     95                        // this should never happen. Therefore simply dump the exception 
     96                        e.printStackTrace(); 
     97                } 
    11698 
    117             clone.executedTasks = new LinkedList<ITaskInstance>(); 
    118              
    119             for (ITaskInstance child : executedTasks) { 
    120                 clone.executedTasks.add(child.clone()); 
    121             } 
     99                return clone; 
     100        } 
    122101 
    123         } 
    124         catch (CloneNotSupportedException e) { 
    125             // this should never happen. Therefore simply dump the exception 
    126             e.printStackTrace(); 
    127         } 
     102        /* 
     103         * (non-Javadoc) 
     104         *  
     105         * @see 
     106         * de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession#equals(IUserSession) 
     107         */ 
     108        @Override 
     109        public boolean equals(IUserSession userSession) { 
     110                // task instances are only equal if they are identical or if they have 
     111                // the same id 
     112                // (may happen, if they are cloned) 
     113                return (this == userSession) 
     114                                || (this.hashCode() == userSession.hashCode()); 
     115        } 
    128116 
    129         return clone; 
    130     } 
     117        /* 
     118         * (non-Javadoc) 
     119         *  
     120         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#get(int) 
     121         */ 
     122        @Override 
     123        public ITaskInstance get(int index) { 
     124                return executedTasks.get(index); 
     125        } 
    131126 
    132     /** 
    133      * <p> 
    134      * used internally to add a task instance to the user session 
    135      * </p> 
    136      *  
    137      * @param taskInstance the task instance to be added 
    138      */ 
    139     void addExecutedTask(ITaskInstance taskInstance) { 
    140         executedTasks.add(taskInstance); 
    141     } 
     127        /* 
     128         * (non-Javadoc) 
     129         *  
     130         * @see 
     131         * de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession#getExecutedTasks() 
     132         */ 
     133        @Override 
     134        public List<ITaskInstance> getExecutedTasks() { 
     135                return Collections.unmodifiableList(executedTasks); 
     136        } 
    142137 
    143     /** 
    144      * <p> 
    145      * used internally to add a task instance to the user session at a specific position 
    146      * </p> 
    147      *  
    148      * @param index        the index the task instance shall be added to 
    149      * @param taskInstance the task instance to be added 
    150      */ 
    151     void addExecutedTask(int index, ITaskInstance taskInstance) { 
    152         executedTasks.add(index, taskInstance); 
    153     } 
     138        /* 
     139         * (non-Javadoc) 
     140         *  
     141         * @see java.lang.Object#hashCode() 
     142         */ 
     143        @Override 
     144        public synchronized int hashCode() { 
     145                return super.hashCode(); 
     146        } 
    154147 
    155     /** 
    156      * <p> 
    157      * used internally to remove a task instance from the user session 
    158      * </p> 
    159      *  
    160      * @param index the index of the task instance to be removed 
    161      */ 
    162     void removeExecutedTask(int index) { 
    163         executedTasks.remove(index); 
    164     } 
     148        /* 
     149         * (non-Javadoc) 
     150         *  
     151         * @see java.lang.Iterable#iterator() 
     152         */ 
     153        @Override 
     154        public Iterator<ITaskInstance> iterator() { 
     155                return executedTasks.iterator(); 
     156        } 
     157 
     158        /** 
     159         * <p> 
     160         * used internally to remove a task instance from the user session 
     161         * </p> 
     162         *  
     163         * @param index 
     164         *            the index of the task instance to be removed 
     165         */ 
     166        void removeExecutedTask(int index) { 
     167                executedTasks.remove(index); 
     168        } 
     169 
     170        /* 
     171         * (non-Javadoc) 
     172         *  
     173         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#size() 
     174         */ 
     175        @Override 
     176        public int size() { 
     177                return executedTasks.size(); 
     178        } 
     179 
     180        /* 
     181         * (non-Javadoc) 
     182         *  
     183         * @see java.lang.Object#toString() 
     184         */ 
     185        @Override 
     186        public synchronized String toString() { 
     187                return "session (" + executedTasks.size() + " task instances)"; 
     188        } 
    165189 
    166190} 
Note: See TracChangeset for help on using the changeset viewer.