source: trunk/quest-ui-core/src/main/java/de/ugoe/cs/quest/ui/commands/CMDsequenceStatistics.java @ 658

Last change on this file since 658 was 547, checked in by sherbold, 12 years ago
  • countless adaptations throughout nearly all components to remove errors introduced due to the refactoring of the event core
  • Property svn:mime-type set to text/plain
File size: 2.3 KB
RevLine 
[434]1package de.ugoe.cs.quest.ui.commands;
[113]2
[241]3import java.security.InvalidParameterException;
[203]4import java.util.Collection;
[113]5import java.util.List;
6import java.util.Map.Entry;
7import java.util.SortedMap;
8import java.util.TreeMap;
9
[432]10import de.ugoe.cs.quest.CommandHelpers;
11import de.ugoe.cs.quest.SequenceInstanceOf;
[433]12import de.ugoe.cs.quest.eventcore.Event;
[434]13import de.ugoe.cs.quest.ui.GlobalDataContainer;
[113]14import de.ugoe.cs.util.console.Command;
15import de.ugoe.cs.util.console.Console;
16
[171]17/**
18 * <p>
19 * Command to print basic statistical information about stored sequences, e.g.,
20 * how many there are of which lenght.
21 * </p>
22 *
23 * @author Steffen Herbold
24 * @version 1.0
25 */
[113]26public class CMDsequenceStatistics implements Command {
27
[171]28        /*
29         * (non-Javadoc)
30         *
31         * @see de.ugoe.cs.util.console.Command#run(java.util.List)
32         */
[113]33        @SuppressWarnings("unchecked")
34        @Override
35        public void run(List<Object> parameters) {
[241]36                String sequencesName;
37                try {
[113]38                        sequencesName = (String) parameters.get(0);
[241]39                } catch (Exception e) {
40                        throw new InvalidParameterException();
[113]41                }
[171]42
[547]43                Collection<List<Event>> sequences = null;
[171]44                Object dataObject = GlobalDataContainer.getInstance().getData(
45                                sequencesName);
[209]46                if (dataObject == null) {
[240]47                        CommandHelpers.objectNotFoundMessage(sequencesName);
[209]48                        return;
49                }
50                if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) {
[240]51                        CommandHelpers.objectNotType(sequencesName,
52                                        "Collection<List<Event<?>>>");
[209]53                        return;
54                }
[171]55
[547]56                sequences = (Collection<List<Event>>) dataObject;
[241]57                Console.println("Number of Sequences: " + sequences.size());
[209]58                SortedMap<Integer, Integer> lengthMap = new TreeMap<Integer, Integer>();
[547]59                for (List<Event> sequence : sequences) {
[209]60                        Integer currentSize = sequence.size();
61                        if (lengthMap.containsKey(currentSize)) {
62                                lengthMap.put(currentSize, lengthMap.get(currentSize) + 1);
63                        } else {
64                                lengthMap.put(currentSize, 1);
[113]65                        }
66                }
[209]67                for (Entry<Integer, Integer> entry : lengthMap.entrySet()) {
[241]68                        Console.println("Of length " + entry.getKey() + ": "
[209]69                                        + entry.getValue());
70                }
[113]71        }
72
[171]73        /*
74         * (non-Javadoc)
75         *
76         * @see de.ugoe.cs.util.console.Command#help()
77         */
[113]78        @Override
79        public void help() {
[241]80                Console.println("Usage: sequenceStatistics <sequencesName>");
[113]81        }
82
83}
Note: See TracBrowser for help on using the repository browser.