[71] | 1 | package de.ugoe.cs.eventbench.commands;
|
---|
| 2 |
|
---|
| 3 | import java.security.InvalidParameterException;
|
---|
| 4 | import java.util.Arrays;
|
---|
| 5 | import java.util.List;
|
---|
| 6 |
|
---|
| 7 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
| 8 | import de.ugoe.cs.eventbench.models.IStochasticProcess;
|
---|
| 9 | import de.ugoe.cs.util.console.Command;
|
---|
| 10 | import de.ugoe.cs.util.console.Console;
|
---|
| 11 |
|
---|
[171] | 12 | /**
|
---|
| 13 | * <p>
|
---|
| 14 | * Command to list all events (symbols) known to a usage profile (stochastic
|
---|
| 15 | * process).
|
---|
| 16 | * </p>
|
---|
| 17 | *
|
---|
| 18 | * @author Steffen Herbold
|
---|
| 19 | * @version 1.0
|
---|
| 20 | */
|
---|
[130] | 21 | public class CMDlistSymbols implements Command {
|
---|
[71] | 22 |
|
---|
[171] | 23 | /*
|
---|
| 24 | * (non-Javadoc)
|
---|
| 25 | *
|
---|
| 26 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 27 | */
|
---|
[71] | 28 | @Override
|
---|
| 29 | public void run(List<Object> parameters) {
|
---|
| 30 | String modelname = "";
|
---|
| 31 | boolean sort = false;
|
---|
| 32 | try {
|
---|
| 33 | modelname = (String) parameters.get(0);
|
---|
[171] | 34 | if (parameters.size() == 2) {
|
---|
[71] | 35 | sort = Boolean.parseBoolean((String) parameters.get(1));
|
---|
| 36 | }
|
---|
| 37 | } catch (Exception e) {
|
---|
| 38 | throw new InvalidParameterException();
|
---|
| 39 | }
|
---|
[171] | 40 |
|
---|
| 41 | IStochasticProcess model = null;
|
---|
| 42 | Object dataObject = GlobalDataContainer.getInstance()
|
---|
| 43 | .getData(modelname);
|
---|
| 44 | if (dataObject == null) {
|
---|
[71] | 45 | Console.println("Model " + modelname + "not found in storage.");
|
---|
[171] | 46 | } else if (!(dataObject instanceof IStochasticProcess)) {
|
---|
| 47 | Console.println("Object " + modelname
|
---|
| 48 | + " is not a stochastic process!");
|
---|
[71] | 49 | } else {
|
---|
| 50 | model = (IStochasticProcess) dataObject;
|
---|
[130] | 51 | String[] stateStrings = model.getSymbolStrings();
|
---|
[171] | 52 | if (sort) {
|
---|
[71] | 53 | Arrays.sort(stateStrings);
|
---|
| 54 | }
|
---|
[171] | 55 | for (String stateString : stateStrings) {
|
---|
[71] | 56 | Console.println(stateString);
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[171] | 61 | /*
|
---|
| 62 | * (non-Javadoc)
|
---|
| 63 | *
|
---|
| 64 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 65 | */
|
---|
[71] | 66 | @Override
|
---|
| 67 | public void help() {
|
---|
| 68 | Console.println("Usage: listStates <modelName>");
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | }
|
---|