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.CommandHelpers;
|
---|
8 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
9 | import de.ugoe.cs.eventbench.models.IStochasticProcess;
|
---|
10 | import de.ugoe.cs.util.console.Command;
|
---|
11 | import de.ugoe.cs.util.console.Console;
|
---|
12 |
|
---|
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 | */
|
---|
22 | public class CMDlistSymbols implements Command {
|
---|
23 |
|
---|
24 | /*
|
---|
25 | * (non-Javadoc)
|
---|
26 | *
|
---|
27 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
28 | */
|
---|
29 | @Override
|
---|
30 | public void run(List<Object> parameters) {
|
---|
31 | String modelname = "";
|
---|
32 | boolean sort = false;
|
---|
33 | try {
|
---|
34 | modelname = (String) parameters.get(0);
|
---|
35 | if (parameters.size() == 2) {
|
---|
36 | sort = Boolean.parseBoolean((String) parameters.get(1));
|
---|
37 | }
|
---|
38 | } catch (Exception e) {
|
---|
39 | throw new InvalidParameterException();
|
---|
40 | }
|
---|
41 |
|
---|
42 | IStochasticProcess model = null;
|
---|
43 | Object dataObject = GlobalDataContainer.getInstance()
|
---|
44 | .getData(modelname);
|
---|
45 | if (dataObject == null) {
|
---|
46 | CommandHelpers.objectNotFoundMessage(modelname);
|
---|
47 | return;
|
---|
48 | }
|
---|
49 | if (!(dataObject instanceof IStochasticProcess)) {
|
---|
50 | CommandHelpers.objectNotType(modelname, "IStochasticProcess");
|
---|
51 | return;
|
---|
52 | }
|
---|
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 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | /*
|
---|
64 | * (non-Javadoc)
|
---|
65 | *
|
---|
66 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
67 | */
|
---|
68 | @Override
|
---|
69 | public void help() {
|
---|
70 | Console.println("Usage: listStates <modelName> {<sort>}");
|
---|
71 | }
|
---|
72 |
|
---|
73 | }
|
---|