1 | package de.ugoe.cs.eventbench.commands;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 | import java.util.Map.Entry;
|
---|
5 | import java.util.SortedMap;
|
---|
6 | import java.util.TreeMap;
|
---|
7 |
|
---|
8 | import de.ugoe.cs.eventbench.data.Event;
|
---|
9 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
10 | import de.ugoe.cs.util.console.Command;
|
---|
11 | import de.ugoe.cs.util.console.Console;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * <p>
|
---|
15 | * Command to print basic statistical information about stored sequences, e.g.,
|
---|
16 | * how many there are of which lenght.
|
---|
17 | * </p>
|
---|
18 | *
|
---|
19 | * @author Steffen Herbold
|
---|
20 | * @version 1.0
|
---|
21 | */
|
---|
22 | public class CMDsequenceStatistics implements Command {
|
---|
23 |
|
---|
24 | /*
|
---|
25 | * (non-Javadoc)
|
---|
26 | *
|
---|
27 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
28 | */
|
---|
29 | @SuppressWarnings("unchecked")
|
---|
30 | @Override
|
---|
31 | public void run(List<Object> parameters) {
|
---|
32 | String sequencesName = "sequences";
|
---|
33 | if (parameters.size() == 1) {
|
---|
34 | sequencesName = (String) parameters.get(0);
|
---|
35 | }
|
---|
36 |
|
---|
37 | List<List<Event<?>>> sequences = null;
|
---|
38 | Object dataObject = GlobalDataContainer.getInstance().getData(
|
---|
39 | sequencesName);
|
---|
40 |
|
---|
41 | try {
|
---|
42 | sequences = (List<List<Event<?>>>) dataObject;
|
---|
43 | Console.traceln("Number of Sequences: " + sequences.size());
|
---|
44 | SortedMap<Integer, Integer> lengthMap = new TreeMap<Integer, Integer>();
|
---|
45 | for (List<Event<?>> sequence : sequences) {
|
---|
46 | Integer currentSize = sequence.size();
|
---|
47 | if (lengthMap.containsKey(currentSize)) {
|
---|
48 | lengthMap.put(currentSize, lengthMap.get(currentSize) + 1);
|
---|
49 | } else {
|
---|
50 | lengthMap.put(currentSize, 1);
|
---|
51 | }
|
---|
52 | }
|
---|
53 | for (Entry<Integer, Integer> entry : lengthMap.entrySet()) {
|
---|
54 | Console.traceln("Of length " + entry.getKey() + ": "
|
---|
55 | + entry.getValue());
|
---|
56 | }
|
---|
57 |
|
---|
58 | } catch (ClassCastException e) {
|
---|
59 | Console.println("Sequences not found");
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | /*
|
---|
64 | * (non-Javadoc)
|
---|
65 | *
|
---|
66 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
67 | */
|
---|
68 | @Override
|
---|
69 | public void help() {
|
---|
70 | Console.println("Usage: sequenceStatistics {<sequencesName>}");
|
---|
71 | }
|
---|
72 |
|
---|
73 | }
|
---|