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