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