[31] | 1 | package de.ugoe.cs.eventbench.commands;
|
---|
| 2 |
|
---|
| 3 | import java.security.InvalidParameterException;
|
---|
| 4 | import java.util.List;
|
---|
| 5 |
|
---|
[240] | 6 | import de.ugoe.cs.eventbench.CommandHelpers;
|
---|
[31] | 7 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
[171] | 8 | import de.ugoe.cs.eventbench.models.Trie;
|
---|
[31] | 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 |
|
---|
[171] | 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
|
---|
[223] | 20 | * @version 1.0
|
---|
[171] | 21 | */
|
---|
[31] | 22 | public class CMDprintTrieDot implements Command {
|
---|
[171] | 23 |
|
---|
| 24 | /*
|
---|
| 25 | * (non-Javadoc)
|
---|
| 26 | *
|
---|
| 27 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 28 | */
|
---|
[31] | 29 | @Override
|
---|
| 30 | public void help() {
|
---|
| 31 | Console.println("Usage: printTreeDot <modelname>");
|
---|
| 32 | }
|
---|
| 33 |
|
---|
[171] | 34 | /*
|
---|
| 35 | * (non-Javadoc)
|
---|
| 36 | *
|
---|
| 37 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 38 | */
|
---|
[31] | 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 | }
|
---|
[171] | 47 |
|
---|
| 48 | TrieBasedModel model = null;
|
---|
| 49 | Object dataObject = GlobalDataContainer.getInstance()
|
---|
| 50 | .getData(modelname);
|
---|
| 51 | if (dataObject == null) {
|
---|
[240] | 52 | CommandHelpers.objectNotFoundMessage(modelname);
|
---|
[209] | 53 | return;
|
---|
| 54 | }
|
---|
| 55 | if (!(dataObject instanceof TrieBasedModel)) {
|
---|
[240] | 56 | CommandHelpers.objectNotType(modelname, "TrieBasedModel");
|
---|
[209] | 57 | return;
|
---|
[31] | 58 | }
|
---|
[209] | 59 |
|
---|
| 60 | model = (TrieBasedModel) dataObject;
|
---|
| 61 | Console.println(model.getTrieDotRepresentation());
|
---|
[31] | 62 | }
|
---|
[171] | 63 |
|
---|
[31] | 64 | }
|
---|