1 | package de.ugoe.cs.eventbench.commands;
|
---|
2 |
|
---|
3 | import java.security.InvalidParameterException;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import de.ugoe.cs.eventbench.CommandHelpers;
|
---|
7 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
8 | import de.ugoe.cs.eventbench.models.Trie;
|
---|
9 | import de.ugoe.cs.eventbench.models.TrieBasedModel;
|
---|
10 | import de.ugoe.cs.util.console.Command;
|
---|
11 | import de.ugoe.cs.util.console.Console;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * <p>
|
---|
15 | * Command that prints the {@link Trie} of a {@link TrieBasedModel} as dot to
|
---|
16 | * the console.
|
---|
17 | * </p>
|
---|
18 | *
|
---|
19 | * @author Steffen Herbold
|
---|
20 | * @version 1.0
|
---|
21 | */
|
---|
22 | public class CMDprintTrieDot implements Command {
|
---|
23 |
|
---|
24 | /*
|
---|
25 | * (non-Javadoc)
|
---|
26 | *
|
---|
27 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
28 | */
|
---|
29 | @Override
|
---|
30 | public void help() {
|
---|
31 | Console.println("Usage: printTreeDot <modelname>");
|
---|
32 | }
|
---|
33 |
|
---|
34 | /*
|
---|
35 | * (non-Javadoc)
|
---|
36 | *
|
---|
37 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
38 | */
|
---|
39 | @Override
|
---|
40 | public void run(List<Object> parameters) {
|
---|
41 | String modelname = "";
|
---|
42 | try {
|
---|
43 | modelname = (String) parameters.get(0);
|
---|
44 | } catch (Exception e) {
|
---|
45 | throw new InvalidParameterException();
|
---|
46 | }
|
---|
47 |
|
---|
48 | TrieBasedModel model = null;
|
---|
49 | Object dataObject = GlobalDataContainer.getInstance()
|
---|
50 | .getData(modelname);
|
---|
51 | if (dataObject == null) {
|
---|
52 | CommandHelpers.objectNotFoundMessage(modelname);
|
---|
53 | return;
|
---|
54 | }
|
---|
55 | if (!(dataObject instanceof TrieBasedModel)) {
|
---|
56 | CommandHelpers.objectNotType(modelname, "TrieBasedModel");
|
---|
57 | return;
|
---|
58 | }
|
---|
59 |
|
---|
60 | model = (TrieBasedModel) dataObject;
|
---|
61 | Console.println(model.getTrieDotRepresentation());
|
---|
62 | }
|
---|
63 |
|
---|
64 | }
|
---|