Ignore:
Timestamp:
01/28/20 15:59:17 (4 years ago)
Author:
pharms
Message:

added a sorting of events based on timestamps

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-ui-core/src/main/java/de/ugoe/cs/autoquest/commands/sequences/CMDcheckEventTimestamps.java

    r1438 r2287  
    1818import java.util.LinkedList; 
    1919import java.util.List; 
     20import java.util.ListIterator; 
    2021import java.util.logging.Level; 
    2122 
     
    8485            Console.println("sequences with timestamp issues listed"); 
    8586        } 
     87        else if ("sort".equals(command)) { 
     88            sortEventsUsingTimestamps(sequences, newSequencesName); 
     89        } 
    8690        else if ("delete".equals(command)) { 
    8791            deleteSequencesWithInvalidTimestamps(sequences, newSequencesName); 
     
    156160                } 
    157161            } 
     162        } 
     163    } 
     164 
     165    /** 
     166     * <p> 
     167     * sorts events in sequences with invalid timestamps from the provided collection of sequences and 
     168     * stores them under new name 
     169     * </p> 
     170     * 
     171     * @param sequences        the collection of sequences to sort the events in 
     172     * @param newSequencesName the name for the new corrected collection of sequences 
     173     */ 
     174    private void sortEventsUsingTimestamps(Collection<List<Event>> sequences, 
     175                                           String                  newSequencesName) 
     176    { 
     177        Collection<List<Event>> newSequences = new LinkedList<List<Event>>(); 
     178         
     179        for (List<Event> sequence : sequences) { 
     180             
     181            List<Event> newSequence = new LinkedList<>(); 
     182             
     183            for (Event currentEvent : sequence) { 
     184                boolean added = false; 
     185                 
     186                ListIterator<Event> iterator = newSequence.listIterator(); 
     187                 
     188                while (iterator.hasNext()) { 
     189                    if (iterator.next().getTimestamp() > currentEvent.getTimestamp()) { 
     190                        iterator.previous(); 
     191                        iterator.add(currentEvent); 
     192                        added = true; 
     193                        break; 
     194                    }; 
     195                } 
     196                 
     197                if (!added) { 
     198                    newSequence.add(currentEvent); 
     199                } 
     200                 
     201            } 
     202             
     203            newSequences.add(newSequence); 
     204        } 
     205         
     206        Console.traceln(Level.WARNING, sequences.size() + 
     207                        " sequences sorted based on event timestamps"); 
     208             
     209        if (GlobalDataContainer.getInstance().addData(newSequencesName, newSequences)) { 
     210            CommandHelpers.dataOverwritten(newSequencesName); 
    158211        } 
    159212    } 
Note: See TracChangeset for help on using the changeset viewer.