Ignore:
Timestamp:
08/09/14 17:40:11 (10 years ago)
Author:
rkrimmel
Message:

Commit before making dramatic changes. (Not really)

File:
1 edited

Legend:

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

    r1654 r1655  
    1717import java.util.Iterator; 
    1818 
     19import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 
     20import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance; 
    1921import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
    2022import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance; 
     23import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
    2124import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; 
    2225import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
     
    3235 */ 
    3336class RuleUtils { 
    34      
    35     /** 
    36      * <p> 
    37      * counter for generating unique ids. Starts at 0 for each new program start 
    38      * </p> 
    39      */ 
    40     private static int idCounter = 0; 
    4137 
    42     /** 
    43      * <p> 
    44      * generates a sub sequence for a specified range of elements in the provided task instances 
    45      * list. 
    46      * </p> 
    47      * 
    48      * @param parent      the list of which the range shall be extracted 
    49      * @param startIndex  the start index of the range 
    50      * @param endIndex    the end index of the range (inclusive) 
    51      * @param model       the task model (required for instantiating the sub sequence) 
    52      * @param taskFactory the task factory used for instantiating the sub sequence 
    53      * @param taskBuilder the task builder to perform changes in the task structure 
    54      *  
    55      * @return a task instance representing the requested sub sequence 
    56      */ 
    57     static ITaskInstance getSubSequenceInRange(ITaskInstanceList parent, 
    58                                                int               startIndex, 
    59                                                int               endIndex, 
    60                                                ISequence         model, 
    61                                                ITaskFactory      taskFactory, 
    62                                                ITaskBuilder      taskBuilder) 
    63     { 
    64         ISequenceInstance subsequence = taskFactory.createNewTaskInstance(model); 
     38        /** 
     39         * <p> 
     40         * counter for generating unique ids. Starts at 0 for each new program start 
     41         * </p> 
     42         */ 
     43        private static int idCounter = 0; 
    6544 
    66         for (int i = startIndex; i <= endIndex; i++) { 
    67             taskBuilder.addChild(subsequence, parent.get(i)); 
    68         } 
     45        /** 
     46         * <p> 
     47         * generates a sub sequence for a specified range of elements in the 
     48         * provided task instances list. 
     49         * </p> 
     50         * 
     51         * @param parent 
     52         *            the list of which the range shall be extracted 
     53         * @param startIndex 
     54         *            the start index of the range 
     55         * @param endIndex 
     56         *            the end index of the range (inclusive) 
     57         * @param model 
     58         *            the task model (required for instantiating the sub sequence) 
     59         * @param taskFactory 
     60         *            the task factory used for instantiating the sub sequence 
     61         * @param taskBuilder 
     62         *            the task builder to perform changes in the task structure 
     63         *  
     64         * @return a task instance representing the requested sub sequence 
     65         */ 
     66        static ITaskInstance getSubSequenceInRange(ITaskInstanceList parent, 
     67                        int startIndex, int endIndex, ISequence model, 
     68                        ITaskFactory taskFactory, ITaskBuilder taskBuilder) { 
     69                ISequenceInstance subsequence = taskFactory 
     70                                .createNewTaskInstance(model); 
    6971 
    70         return subsequence; 
    71     } 
     72                for (int i = startIndex; i <= endIndex; i++) { 
     73                        taskBuilder.addChild(subsequence, parent.get(i)); 
     74                } 
    7275 
    73     /** 
    74      * <p> 
    75      * replaces a sub sequence for a specified range of elements in the provided task instances 
    76      * list by a sub task instance 
    77      * </p> 
    78      * 
    79      * @param parent      the list of which the range shall be replaced 
    80      * @param startIndex  the start index of the range 
    81      * @param endIndex    the end index of the range (inclusive) 
    82      * @param model       the task model (required for instantiating the sub sequence) 
    83      * @param taskFactory the task factory used for instantiating the sub sequence 
    84      * @param taskBuilder the task builder to perform changes in the task structure 
    85      *  
    86      * @return the replacement for the range 
    87      */ 
    88     static ISequenceInstance createNewSubSequenceInRange(ITaskInstanceList parent, 
    89                                                          int               startIndex, 
    90                                                          int               endIndex, 
    91                                                          ISequence         model, 
    92                                                          ITaskFactory      taskFactory, 
    93                                                          ITaskBuilder      taskBuilder) 
    94     { 
    95         ISequenceInstance subsequence = taskFactory.createNewTaskInstance(model); 
    96          
    97        for (Iterator<ITaskInstance> it = subsequence.iterator();it.hasNext();) { 
    98            ITaskInstance foo =  it.next(); 
    99            System.out.println(foo); 
    100        } 
    101          
    102         System.out.println("Got model: " + model.toString()); 
    103          
    104         
    105          
    106         System.out.println(parent); 
    107         //System.out.println(parent.get(startIndex)); 
    108         for (int i = startIndex; i <= endIndex; i++) { 
    109                 System.out.println("Trying to add "+ parent.get(startIndex) + " to the model"); 
    110             taskBuilder.addChild(subsequence, parent.get(startIndex)); 
    111              
    112             taskBuilder.removeTaskInstance(parent, startIndex); 
    113         } 
     76                return subsequence; 
     77        } 
    11478 
    115         taskBuilder.addTaskInstance(parent, startIndex, subsequence); 
     79        /** 
     80         * <p> 
     81         * replaces a sub sequence for a specified range of elements in the provided 
     82         * task instances list by a sub task instance 
     83         * </p> 
     84         * 
     85         * @param parent 
     86         *            the list of which the range shall be replaced 
     87         * @param startIndex 
     88         *            the start index of the range 
     89         * @param endIndex 
     90         *            the end index of the range (inclusive) 
     91         * @param model 
     92         *            the task model (required for instantiating the sub sequence) 
     93         * @param taskFactory 
     94         *            the task factory used for instantiating the sub sequence 
     95         * @param taskBuilder 
     96         *            the task builder to perform changes in the task structure 
     97         *  
     98         * @return the replacement for the range 
     99         */ 
     100        static ISequenceInstance createNewSubSequenceInRange( 
     101                        ITaskInstanceList parent, int startIndex, int endIndex, 
     102                        ISequence model, ITaskFactory taskFactory, ITaskBuilder taskBuilder) { 
     103                ISequenceInstance subsequence = taskFactory 
     104                                .createNewTaskInstance(model); 
    116105 
    117         return subsequence; 
    118     } 
     106                int modelindex=0; 
     107                for (int i = startIndex; i <= endIndex; i++) { 
     108                        System.out.println("Trying to add " + parent.get(startIndex) 
     109                                        + " to the model instance"); 
     110                        ITask tempTask = model.getChildren().get(modelindex); 
     111                        if (tempTask.getType() == "optionality") { 
     112                                        IOptionalInstance optional = taskFactory.createNewTaskInstance((IOptional) tempTask); 
     113                        } else if (tempTask.getType() == "selection") { 
    119114 
    120     /** 
    121      * <p> 
    122      * returns the next available id (uses the id counter) 
    123      * </p> 
    124      *  
    125      * @return the next available id 
    126      */ 
    127     static synchronized String getNewId() { 
    128         return Integer.toString(idCounter++); 
    129     } 
     115                        } else if (tempTask.getType() == "sequence") { 
     116                                taskBuilder.addChild(subsequence, parent.get(startIndex)); 
     117                        } else if (tempTask.getType() == "iteration") { 
    130118 
    131     /** 
    132      * <p> 
    133      * prevent instantiation 
    134      * </p> 
    135      */ 
    136     private RuleUtils() { 
    137         // prevent instantiation 
    138     } 
     119                        } else { 
     120 
     121                        } 
     122                        taskBuilder.removeTaskInstance(parent, startIndex); 
     123                        modelindex++; 
     124                } 
     125 
     126                taskBuilder.addTaskInstance(parent, startIndex, subsequence); 
     127 
     128                return subsequence; 
     129        } 
     130 
     131        /** 
     132         * <p> 
     133         * returns the next available id (uses the id counter) 
     134         * </p> 
     135         *  
     136         * @return the next available id 
     137         */ 
     138        static synchronized String getNewId() { 
     139                return Integer.toString(idCounter++); 
     140        } 
     141 
     142        /** 
     143         * <p> 
     144         * prevent instantiation 
     145         * </p> 
     146         */ 
     147        private RuleUtils() { 
     148                // prevent instantiation 
     149        } 
    139150 
    140151} 
Note: See TracChangeset for help on using the changeset viewer.