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.data.Event;
|
---|
10 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
11 | import de.ugoe.cs.util.console.Command;
|
---|
12 | import 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 | */
|
---|
23 | public 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 | }
|
---|