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

Used Eclipse code cleanup

File:
1 edited

Legend:

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

    r1731 r1733  
    1515package de.ugoe.cs.autoquest.tasktrees.temporalrelation; 
    1616 
    17 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 
    18 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; 
    1917import de.ugoe.cs.autoquest.tasktrees.treeifc.IMarkingTemporalRelationship; 
    2018import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 
     
    2422import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
    2523import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance; 
    26 import de.ugoe.cs.autoquest.tasktrees.treeifc.IStructuringTemporalRelationship; 
    2724import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
    2825import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; 
     
    4239        /** 
    4340         * <p> 
    44          * counter for generating unique ids. Starts at 0 for each new program start 
    45          * </p> 
    46          */ 
    47         private static int idCounter = 0; 
    48  
    49         public static int missedOptionals = 0; 
    50          
     41         * replaces a sub sequence for a specified range of elements in the provided 
     42         * task instances list by a sub task instance 
     43         * </p> 
     44         * 
     45         * @param parent 
     46         *            the list of which the range shall be replaced 
     47         * @param startIndex 
     48         *            the start index of the range 
     49         * @param endIndex 
     50         *            the end index of the range (inclusive) 
     51         * @param model 
     52         *            the task model (required for instantiating the sub sequence) 
     53         * @param taskFactory 
     54         *            the task factory used for instantiating the sub sequence 
     55         * @param taskBuilder 
     56         *            the task builder to perform changes in the task structure 
     57         *  
     58         * @return the replacement for the range 
     59         * @throws 
     60         */ 
     61        static ISequenceInstance createNewSubSequenceInRange( 
     62                        ITaskInstanceList parent, int startIndex, int endIndex, 
     63                        ISequence model, ITaskFactory taskFactory, ITaskBuilder taskBuilder) { 
     64                final ISequenceInstance subsequence = taskFactory 
     65                                .createNewTaskInstance(model); 
     66 
     67                // TODO: Debug output 
     68                /* 
     69                 * System.out.println("PRINTING MODEL: "); for (int i = 0; i < 
     70                 * subsequence.getSequence().getChildren().size(); i++) { 
     71                 * System.out.println(subsequence.getSequence().getChildren().get(i)); 
     72                 *  
     73                 * if (subsequence.getSequence().getChildren().get(i).getType() == 
     74                 * "selection") { for (int j = 0; j < ((ISelection) 
     75                 * subsequence.getSequence().getChildren().get(i)) 
     76                 * .getChildren().size(); j++) { if(((IStructuringTemporalRelationship) 
     77                 * subsequence 
     78                 * .getSequence().getChildren().get(i)).getChildren().get(j).getType() 
     79                 * =="sequence") { ISequence foo = (ISequence) ((ISelection) 
     80                 * (subsequence 
     81                 * .getSequence().getChildren().get(i))).getChildren().get(j); 
     82                 * System.out.println("\t" + foo); for(int k=0; k< 
     83                 * foo.getChildren().size();k++) { System.out.println("\t\t" 
     84                 * +foo.getChildren().get(k)); } System.out.println(); } else{ 
     85                 * System.out.println("\t" + ((ISelection) 
     86                 * subsequence.getSequence().getChildren().get(i)) 
     87                 * .getChildren().get(j)); } 
     88                 *  
     89                 * } } 
     90                 *  
     91                 * } System.out.println(); 
     92                 */ 
     93 
     94                // TODO: This is dirty! 
     95                missedOptionals = 0; 
     96                int modelindex = 0; 
     97                for (int i = startIndex; i <= endIndex; i++) { 
     98 
     99                        if (modelindex == model.getChildren().size()) { 
     100                                break; 
     101                        } 
     102                        final ITask tempTask = model.getChildren().get(modelindex); 
     103                        // System.out.println("Trying to add " + parent.get(startIndex) 
     104                        // + " to the model instance " + tempTask); 
     105                        if (tempTask.getType() == "optionality") { 
     106 
     107                                if (((IMarkingTemporalRelationship) tempTask).getMarkedTask() == parent 
     108                                                .get(startIndex).getTask()) { 
     109                                        // System.out.println("Adding OptionalInstance " + 
     110                                        // parent.get(startIndex) + " to " + tempTask.getType()); 
     111                                        final IOptionalInstance optional = taskFactory 
     112                                                        .createNewTaskInstance((IOptional) tempTask); 
     113                                        taskBuilder.setChild(optional, parent.get(startIndex)); 
     114                                        taskBuilder.addChild(subsequence, optional); 
     115                                } else { 
     116                                        // System.out.println("Adding Empty optional, not deleting anything from the input sequence"); 
     117                                        final IOptionalInstance optional = taskFactory 
     118                                                        .createNewTaskInstance((IOptional) tempTask); 
     119                                        taskBuilder.addChild(subsequence, optional); 
     120                                        modelindex++; 
     121                                        missedOptionals++; 
     122                                        continue; 
     123                                } 
     124                        } else if (tempTask.getType() == "selection") { 
     125                                final ISelectionInstance selection = taskFactory 
     126                                                .createNewTaskInstance((ISelection) tempTask); 
     127                                final ISelection tmpSel = (ISelection) tempTask; 
     128                                if ((tmpSel.getChildren().get(0).getType() == "sequence") 
     129                                                && (tmpSel.getChildren().get(1).getType() == "sequence")) { 
     130                                        ISequenceInstance selseq = null; 
     131                                        // The selection I create can just have 2 children 
     132                                        if (parent.get(startIndex).getTask().getId() == ((ISequence) tmpSel 
     133                                                        .getChildren().get(0)).getChildren().get(0).getId()) { 
     134                                                selseq = taskFactory 
     135                                                                .createNewTaskInstance((ISequence) tmpSel 
     136                                                                                .getChildren().get(0)); 
     137                                        } else if (parent.get(startIndex).getTask().getId() == ((ISequence) tmpSel 
     138                                                        .getChildren().get(1)).getChildren().get(0).getId()) { 
     139                                                selseq = taskFactory 
     140                                                                .createNewTaskInstance((ISequence) tmpSel 
     141                                                                                .getChildren().get(1)); 
     142                                        } else if ((parent.get(startIndex).getTask().getId() == tmpSel 
     143                                                        .getChildren().get(0).getId()) 
     144                                                        || (parent.get(startIndex).getTask().getId() == tmpSel 
     145                                                                        .getChildren().get(1).getId())) { 
     146                                                // System.out.println("Session ID: " + 
     147                                                // parent.get(startIndex).getTask().getId() + 
     148                                                // " tmpSel(0): " + tmpSel.getChildren().get(0).getId() 
     149                                                // + " tmpSel(1): " +tmpSel.getChildren().get(1).getId() 
     150                                                // ); 
     151                                                continue; 
     152                                        } 
     153 
     154                                        for (int k = 0; k < selseq.getSequence().getChildren() 
     155                                                        .size(); k++) { 
     156                                                // System.out.println("Trying to add " + 
     157                                                // parent.get(startIndex) + " to " + selseq); 
     158                                                taskBuilder.addChild(selseq, parent.get(startIndex)); 
     159                                                taskBuilder.removeTaskInstance(parent, startIndex); 
     160                                                i++; 
     161                                                // System.out.println("I:" + i); 
     162                                        } 
     163                                        // System.out.println("Trying to add " + selseq + " to " + 
     164                                        // tmpSel); 
     165                                        taskBuilder.setChild(selection, selseq); 
     166                                        taskBuilder.addChild(subsequence, selection); 
     167                                        modelindex++; 
     168                                        continue; 
     169                                } else { 
     170                                        // System.out.println("Trying to adding SelectionInstance " 
     171                                        // + parent.get(startIndex) + " to " + tempTask); 
     172                                        taskBuilder.setChild(selection, parent.get(startIndex)); 
     173                                        taskBuilder.addChild(subsequence, selection); 
     174                                } 
     175                        } else if (tempTask.getType() == "sequence") { 
     176                                // System.out.println("Adding SequenceInstance " + 
     177                                // parent.get(startIndex) + " to " + tempTask); 
     178                                taskBuilder.addChild(subsequence, parent.get(startIndex)); 
     179                        } else if (tempTask.getType() == "iteration") { 
     180                                // System.out.println("Adding IterationInstance " + 
     181                                // parent.get(startIndex) + " to " + tempTask); 
     182                                taskBuilder.addChild(subsequence, parent.get(startIndex)); 
     183                        } else { 
     184                                // System.out.println("Adding EventInstance " + 
     185                                // parent.get(startIndex) + " to " + tempTask); 
     186                                // System.out.println("Foo"); 
     187                                taskBuilder.addChild(subsequence, parent.get(startIndex)); 
     188                        } 
     189                        taskBuilder.removeTaskInstance(parent, startIndex); 
     190                        modelindex++; 
     191                } 
     192 
     193                taskBuilder.addTaskInstance(parent, startIndex, subsequence); 
     194 
     195                return subsequence; 
     196        } 
     197 
     198        /** 
     199         * <p> 
     200         * returns the next available id (uses the id counter) 
     201         * </p> 
     202         *  
     203         * @return the next available id 
     204         */ 
     205        static synchronized String getNewId() { 
     206                return Integer.toString(idCounter++); 
     207        } 
     208 
    51209        /** 
    52210         * <p> 
     
    73231                        int startIndex, int endIndex, ISequence model, 
    74232                        ITaskFactory taskFactory, ITaskBuilder taskBuilder) { 
    75                 ISequenceInstance subsequence = taskFactory 
     233                final ISequenceInstance subsequence = taskFactory 
    76234                                .createNewTaskInstance(model); 
    77235 
     
    83241        } 
    84242 
    85         /** 
    86          * <p> 
    87          * replaces a sub sequence for a specified range of elements in the provided 
    88          * task instances list by a sub task instance 
    89          * </p> 
    90          * 
    91          * @param parent 
    92          *            the list of which the range shall be replaced 
    93          * @param startIndex 
    94          *            the start index of the range 
    95          * @param endIndex 
    96          *            the end index of the range (inclusive) 
    97          * @param model 
    98          *            the task model (required for instantiating the sub sequence) 
    99          * @param taskFactory 
    100          *            the task factory used for instantiating the sub sequence 
    101          * @param taskBuilder 
    102          *            the task builder to perform changes in the task structure 
    103          *  
    104          * @return the replacement for the range 
    105          * @throws   
    106          */ 
    107         static ISequenceInstance createNewSubSequenceInRange( 
    108                         ITaskInstanceList parent, int startIndex, int endIndex, 
    109                         ISequence model, ITaskFactory taskFactory, ITaskBuilder taskBuilder)   { 
    110                 ISequenceInstance subsequence = taskFactory 
    111                                 .createNewTaskInstance(model); 
    112                  
    113                  
    114                 // TODO: Debug output 
    115                 /* 
    116                 System.out.println("PRINTING MODEL: "); 
    117                 for (int i = 0; i < subsequence.getSequence().getChildren().size(); i++) { 
    118                         System.out.println(subsequence.getSequence().getChildren().get(i)); 
    119  
    120                         if (subsequence.getSequence().getChildren().get(i).getType() == "selection") { 
    121                                 for (int j = 0; j < ((ISelection) subsequence.getSequence().getChildren().get(i)) 
    122                                                 .getChildren().size(); j++) { 
    123                                         if(((IStructuringTemporalRelationship) subsequence.getSequence().getChildren().get(i)).getChildren().get(j).getType() =="sequence") 
    124                                         { 
    125                                                 ISequence foo =  (ISequence) ((ISelection) (subsequence.getSequence().getChildren().get(i))).getChildren().get(j); 
    126                                                 System.out.println("\t" + foo); 
    127                                                 for(int k=0; k< foo.getChildren().size();k++) { 
    128                                                         System.out.println("\t\t" +foo.getChildren().get(k)); 
    129                                                 } 
    130                                                 System.out.println(); 
    131                                         } 
    132                                         else{ 
    133                                                 System.out.println("\t" 
    134                                                                 + ((ISelection) subsequence.getSequence().getChildren().get(i)) 
    135                                                                                 .getChildren().get(j)); 
    136                                         } 
    137                                  
    138                                 } 
    139                         } 
    140                  
    141                 } 
    142                 System.out.println(); 
    143                 */ 
    144                  
    145                 //TODO: This is dirty! 
    146                 missedOptionals=0; 
    147                 int modelindex=0; 
    148                 for (int i = startIndex; i <= endIndex; i++) { 
    149                          
    150                         if(modelindex == model.getChildren().size()) { 
    151                                 break; 
    152                         } 
    153                         ITask tempTask = model.getChildren().get(modelindex); 
    154                         //System.out.println("Trying to add " + parent.get(startIndex) 
    155                         //      + " to the model instance " + tempTask); 
    156                         if (tempTask.getType() == "optionality") { 
    157                                                  
    158                                         if(((IMarkingTemporalRelationship) tempTask).getMarkedTask() == parent.get(startIndex).getTask()) { 
    159                                                 //System.out.println("Adding OptionalInstance " + parent.get(startIndex) + " to " + tempTask.getType()); 
    160                                                 IOptionalInstance optional = taskFactory.createNewTaskInstance((IOptional) tempTask); 
    161                                                 taskBuilder.setChild(optional, parent.get(startIndex)); 
    162                                                 taskBuilder.addChild(subsequence, optional); 
    163                                         } 
    164                                         else { 
    165                                                 //System.out.println("Adding Empty optional, not deleting anything from the input sequence"); 
    166                                                 IOptionalInstance optional = taskFactory.createNewTaskInstance((IOptional) tempTask); 
    167                                                 taskBuilder.addChild(subsequence, optional); 
    168                                                 modelindex++; 
    169                                                 missedOptionals++; 
    170                                                 continue; 
    171                                         }                                
    172                         } else if (tempTask.getType() == "selection") { 
    173                                 ISelectionInstance selection = taskFactory.createNewTaskInstance((ISelection) tempTask); 
    174                                 ISelection tmpSel = (ISelection)tempTask; 
    175                                 if(tmpSel.getChildren().get(0).getType() == "sequence" && tmpSel.getChildren().get(1).getType()=="sequence") { 
    176                                         ISequenceInstance selseq = null; 
    177                                         //The selection I create can just have 2 children 
    178                                         if(parent.get(startIndex).getTask().getId() == ((ISequence)tmpSel.getChildren().get(0)).getChildren().get(0).getId()) { 
    179                                                 selseq = taskFactory.createNewTaskInstance((ISequence) tmpSel.getChildren().get(0)); 
    180                                         } 
    181                                         else if(parent.get(startIndex).getTask().getId() == ((ISequence)tmpSel.getChildren().get(1)).getChildren().get(0).getId()) { 
    182                                                 selseq = taskFactory.createNewTaskInstance((ISequence) tmpSel.getChildren().get(1)); 
    183                                         } 
    184                                         else if(parent.get(startIndex).getTask().getId() == tmpSel.getChildren().get(0).getId() || parent.get(startIndex).getTask().getId() == tmpSel.getChildren().get(1).getId() ) { 
    185                                                 //System.out.println("Session ID: " + parent.get(startIndex).getTask().getId() + " tmpSel(0): " + tmpSel.getChildren().get(0).getId() + " tmpSel(1): " +tmpSel.getChildren().get(1).getId()  ); 
    186                                                 continue; 
    187                                         } 
    188                                                  
    189                                         for (int k=0;k<selseq.getSequence().getChildren().size();k++) { 
    190                                                 //System.out.println("Trying to add " + parent.get(startIndex) + " to " + selseq); 
    191                                                 taskBuilder.addChild(selseq,parent.get(startIndex)); 
    192                                                 taskBuilder.removeTaskInstance(parent, startIndex); 
    193                                                 i++; 
    194                                                 //System.out.println("I:" + i); 
    195                                         } 
    196                                         //System.out.println("Trying to add " + selseq + " to " + tmpSel); 
    197                                         taskBuilder.setChild(selection, selseq); 
    198                                         taskBuilder.addChild(subsequence, selection); 
    199                                         modelindex++; 
    200                                         continue; 
    201                                 } 
    202                                 else 
    203                                 { 
    204                                         //System.out.println("Trying to adding SelectionInstance " + parent.get(startIndex) + " to " + tempTask); 
    205                                         taskBuilder.setChild(selection, parent.get(startIndex)); 
    206                                         taskBuilder.addChild(subsequence,selection); 
    207                                 } 
    208                         } else if (tempTask.getType() == "sequence") { 
    209                                 //System.out.println("Adding SequenceInstance " + parent.get(startIndex) + " to " + tempTask); 
    210                                 taskBuilder.addChild(subsequence, parent.get(startIndex)); 
    211                         } else if (tempTask.getType() == "iteration") { 
    212                                 //System.out.println("Adding IterationInstance " + parent.get(startIndex) + " to " + tempTask); 
    213                                 taskBuilder.addChild(subsequence, parent.get(startIndex)); 
    214                         } else { 
    215                                 //System.out.println("Adding EventInstance " + parent.get(startIndex) + " to " + tempTask); 
    216                                 //System.out.println("Foo"); 
    217                                 taskBuilder.addChild(subsequence, parent.get(startIndex)); 
    218                         } 
    219                         taskBuilder.removeTaskInstance(parent, startIndex); 
    220                         modelindex++; 
    221                 } 
    222                  
    223                 taskBuilder.addTaskInstance(parent, startIndex, subsequence); 
    224  
    225                 return subsequence; 
    226         } 
    227  
    228          
    229243        // Print out the progress 
    230         static void printProgressPercentage(String message,int count, int size) { 
     244        static void printProgressPercentage(String message, int count, int size) { 
    231245                if (size > 100) { 
    232                         if ((count % (size / 100) == 0)) { 
     246                        if (((count % (size / 100)) == 0)) { 
    233247                                // Console.traceln(Level.INFO,("Thread" + 
    234248                                // Thread.currentThread().getName() + ": " + Math.round((float) 
    235249                                // count/size*100))+ "%"); 
    236                                 System.out.println(message + " in thread" + Thread.currentThread().getName() 
    237                                                 + ": " + Math.round((float) count / size * 100) + "%"); 
     250                                System.out.println(message + " in thread" 
     251                                                + Thread.currentThread().getName() + ": " 
     252                                                + Math.round(((float) count / size) * 100) + "%"); 
    238253                        } 
    239254                } else { 
     
    241256                        // Thread.currentThread().getName() + ": " +Math.round((float) 
    242257                        // count/size*100))+ "%"); 
    243                         System.out.println(message + " in thread" + Thread.currentThread().getName() 
    244                                         + ": " + Math.round((float) count / size * 100) + "%"); 
     258                        System.out.println(message + " in thread" 
     259                                        + Thread.currentThread().getName() + ": " 
     260                                        + Math.round(((float) count / size) * 100) + "%"); 
    245261 
    246262                } 
    247263        } 
    248264 
    249          
    250         /** 
    251          * <p> 
    252          * returns the next available id (uses the id counter) 
    253          * </p> 
    254          *  
    255          * @return the next available id 
    256          */ 
    257         static synchronized String getNewId() { 
    258                 return Integer.toString(idCounter++); 
    259         } 
     265        /** 
     266         * <p> 
     267         * counter for generating unique ids. Starts at 0 for each new program start 
     268         * </p> 
     269         */ 
     270        private static int idCounter = 0; 
     271 
     272        public static int missedOptionals = 0; 
    260273 
    261274        /** 
Note: See TracChangeset for help on using the changeset viewer.