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 | public class CMDsequenceStatistics implements Command {
|
---|
14 |
|
---|
15 | @SuppressWarnings("unchecked")
|
---|
16 | @Override
|
---|
17 | public void run(List<Object> parameters) {
|
---|
18 | String sequencesName = "sequences";
|
---|
19 | if( parameters.size()==1 ) {
|
---|
20 | sequencesName = (String) parameters.get(0);
|
---|
21 | }
|
---|
22 |
|
---|
23 |
|
---|
24 | List<List<Event<?>>> sequences = null;
|
---|
25 | Object dataObject = GlobalDataContainer.getInstance().getData(sequencesName);
|
---|
26 |
|
---|
27 | try {
|
---|
28 | sequences = (List<List<Event<?>>>) dataObject;
|
---|
29 | Console.traceln("Number of Sequences: " + sequences.size());
|
---|
30 | SortedMap<Integer,Integer> lengthMap = new TreeMap<Integer, Integer>();
|
---|
31 | for( List<Event<?>> sequence : sequences ) {
|
---|
32 | Integer currentSize = sequence.size();
|
---|
33 | if( lengthMap.containsKey(currentSize) ) {
|
---|
34 | lengthMap.put(currentSize, lengthMap.get(currentSize)+1);
|
---|
35 | } else {
|
---|
36 | lengthMap.put(currentSize, 1);
|
---|
37 | }
|
---|
38 | }
|
---|
39 | for( Entry<Integer, Integer> entry : lengthMap.entrySet() ) {
|
---|
40 | Console.traceln("Of length " + entry.getKey() + ": " + entry.getValue());
|
---|
41 | }
|
---|
42 |
|
---|
43 | }
|
---|
44 | catch(ClassCastException e) {
|
---|
45 | Console.println("Sequences not found");
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 | @Override
|
---|
50 | public void help() {
|
---|
51 | Console.println("Usage: sequenceStatistics {<sequencesName>}");
|
---|
52 | }
|
---|
53 |
|
---|
54 | }
|
---|