source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDsequenceStatistics.java @ 230

Last change on this file since 230 was 209, checked in by sherbold, 13 years ago
  • greatly improved type checking and consistency of type checking for objects checked out of the GlobalDataContainer?
  • Property svn:mime-type set to text/plain
File size: 2.2 KB
Line 
1package de.ugoe.cs.eventbench.commands;
2
3import java.util.Collection;
4import java.util.List;
5import java.util.Map.Entry;
6import java.util.SortedMap;
7import java.util.TreeMap;
8
9import de.ugoe.cs.eventbench.SequenceInstanceOf;
10import de.ugoe.cs.eventbench.data.Event;
11import de.ugoe.cs.eventbench.data.GlobalDataContainer;
12import de.ugoe.cs.util.console.Command;
13import de.ugoe.cs.util.console.Console;
14
15/**
16 * <p>
17 * Command to print basic statistical information about stored sequences, e.g.,
18 * how many there are of which lenght.
19 * </p>
20 *
21 * @author Steffen Herbold
22 * @version 1.0
23 */
24public class CMDsequenceStatistics implements Command {
25
26        /*
27         * (non-Javadoc)
28         *
29         * @see de.ugoe.cs.util.console.Command#run(java.util.List)
30         */
31        @SuppressWarnings("unchecked")
32        @Override
33        public void run(List<Object> parameters) {
34                String sequencesName = "sequences";
35                if (parameters.size() == 1) {
36                        sequencesName = (String) parameters.get(0);
37                }
38
39                Collection<List<Event<?>>> sequences = null;
40                Object dataObject = GlobalDataContainer.getInstance().getData(
41                                sequencesName);
42                if (dataObject == null) {
43                        Console.println("Object " + sequencesName
44                                        + " not found in storage.");
45                        return;
46                }
47                if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) {
48                        Console.println("Object " + sequencesName
49                                        + "not of type Collection<List<Event<?>>>.");
50                        return;
51                }
52
53                sequences = (Collection<List<Event<?>>>) dataObject;
54                Console.traceln("Number of Sequences: " + sequences.size());
55                SortedMap<Integer, Integer> lengthMap = new TreeMap<Integer, Integer>();
56                for (List<Event<?>> sequence : sequences) {
57                        Integer currentSize = sequence.size();
58                        if (lengthMap.containsKey(currentSize)) {
59                                lengthMap.put(currentSize, lengthMap.get(currentSize) + 1);
60                        } else {
61                                lengthMap.put(currentSize, 1);
62                        }
63                }
64                for (Entry<Integer, Integer> entry : lengthMap.entrySet()) {
65                        Console.traceln("Of length " + entry.getKey() + ": "
66                                        + entry.getValue());
67                }
68        }
69
70        /*
71         * (non-Javadoc)
72         *
73         * @see de.ugoe.cs.util.console.Command#help()
74         */
75        @Override
76        public void help() {
77                Console.println("Usage: sequenceStatistics {<sequencesName>}");
78        }
79
80}
Note: See TracBrowser for help on using the repository browser.