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 |
|
---|
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 | */
|
---|
21 | public class CMDlistSymbols implements Command {
|
---|
22 |
|
---|
23 | /*
|
---|
24 | * (non-Javadoc)
|
---|
25 | *
|
---|
26 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
27 | */
|
---|
28 | @Override
|
---|
29 | public void run(List<Object> parameters) {
|
---|
30 | String modelname = "";
|
---|
31 | boolean sort = false;
|
---|
32 | try {
|
---|
33 | modelname = (String) parameters.get(0);
|
---|
34 | if (parameters.size() == 2) {
|
---|
35 | sort = Boolean.parseBoolean((String) parameters.get(1));
|
---|
36 | }
|
---|
37 | } catch (Exception e) {
|
---|
38 | throw new InvalidParameterException();
|
---|
39 | }
|
---|
40 |
|
---|
41 | IStochasticProcess model = null;
|
---|
42 | Object dataObject = GlobalDataContainer.getInstance()
|
---|
43 | .getData(modelname);
|
---|
44 | if (dataObject == null) {
|
---|
45 | Console.println("Model " + modelname + "not found in storage.");
|
---|
46 | } else if (!(dataObject instanceof IStochasticProcess)) {
|
---|
47 | Console.println("Object " + modelname
|
---|
48 | + " is not a stochastic process!");
|
---|
49 | } else {
|
---|
50 | model = (IStochasticProcess) dataObject;
|
---|
51 | String[] stateStrings = model.getSymbolStrings();
|
---|
52 | if (sort) {
|
---|
53 | Arrays.sort(stateStrings);
|
---|
54 | }
|
---|
55 | for (String stateString : stateStrings) {
|
---|
56 | Console.println(stateString);
|
---|
57 | }
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | /*
|
---|
62 | * (non-Javadoc)
|
---|
63 | *
|
---|
64 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
65 | */
|
---|
66 | @Override
|
---|
67 | public void help() {
|
---|
68 | Console.println("Usage: listStates <modelName>");
|
---|
69 | }
|
---|
70 |
|
---|
71 | }
|
---|