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

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