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

added a sorting of events based on timestamps

Location:
trunk/autoquest-ui-core/src/main
Files:
2 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    } 
  • trunk/autoquest-ui-core/src/main/resources/manuals/checkEventTimestamps

    r1438 r2287  
    1 checks all sequences of a collection of sequences for correct timestamps and event order. It supports counting the number of invalid sequences, listing details about invalid sequences and timestamps, as well as deleting invalid sequences. 
     1checks all sequences of a collection of sequences for correct timestamps and event order. It supports counting the number of invalid sequences, listing details about invalid sequences and timestamps, sorting sequences based on the timestamps, as well as deleting invalid sequences. 
    22 
    33$USAGE$ 
    4 <command> one of "count", "list", and "delete" 
     4<command> one of "count", "list", "sort" and "delete" 
    55<sequencesName> the name of the collection of sequences that shall be checked 
    6 <newSequences> optional; the name of the collection of sequences into which the resulting sequences shall be stored in case the delete command is selected; if left out, the result is stored in the collection identified by <sequencesName> 
     6<newSequences> optional; the name of the collection of sequences into which the resulting sequences shall be stored in case the sort or delete command is selected; if left out, the result is stored in the collection identified by <sequencesName> 
    77 
    88Example(s): 
    99checkEventTimestamps count someSequences 
    1010checkEventTimestamps list someSequences 
     11checkEventTimestamps sort someSequences someNewSequences 
    1112checkEventTimestamps delete someSequences someNewSequences 
Note: See TracChangeset for help on using the changeset viewer.