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