1 | package de.ugoe.cs.eventbench.commands;
|
---|
2 |
|
---|
3 | import java.util.Collection;
|
---|
4 | import java.util.List;
|
---|
5 | import java.util.Map.Entry;
|
---|
6 | import java.util.SortedMap;
|
---|
7 | import java.util.TreeMap;
|
---|
8 |
|
---|
9 | import de.ugoe.cs.eventbench.SequenceInstanceOf;
|
---|
10 | import de.ugoe.cs.eventbench.data.Event;
|
---|
11 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
12 | import de.ugoe.cs.util.console.Command;
|
---|
13 | import 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 | */
|
---|
24 | public 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 | }
|
---|