1 | package de.ugoe.cs.quest.commands.usage;
|
---|
2 |
|
---|
3 | import java.util.Arrays;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import de.ugoe.cs.quest.CommandHelpers;
|
---|
7 | import de.ugoe.cs.quest.usageprofiles.IStochasticProcess;
|
---|
8 | import de.ugoe.cs.util.console.Command;
|
---|
9 | import de.ugoe.cs.util.console.Console;
|
---|
10 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
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 IllegalArgumentException();
|
---|
39 | }
|
---|
40 |
|
---|
41 | IStochasticProcess model = null;
|
---|
42 | Object dataObject = GlobalDataContainer.getInstance()
|
---|
43 | .getData(modelname);
|
---|
44 | if (dataObject == null) {
|
---|
45 | CommandHelpers.objectNotFoundMessage(modelname);
|
---|
46 | return;
|
---|
47 | }
|
---|
48 | if (!(dataObject instanceof IStochasticProcess)) {
|
---|
49 | CommandHelpers.objectNotType(modelname, "IStochasticProcess");
|
---|
50 | return;
|
---|
51 | }
|
---|
52 | model = (IStochasticProcess) dataObject;
|
---|
53 | String[] stateStrings = model.getSymbolStrings();
|
---|
54 | if (sort) {
|
---|
55 | Arrays.sort(stateStrings);
|
---|
56 | }
|
---|
57 | for (String stateString : stateStrings) {
|
---|
58 | Console.println(stateString);
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | /*
|
---|
63 | * (non-Javadoc)
|
---|
64 | *
|
---|
65 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
66 | */
|
---|
67 | @Override
|
---|
68 | public String help() {
|
---|
69 | return "listSymbols <modelname> {<sort>}";
|
---|
70 | }
|
---|
71 |
|
---|
72 | }
|
---|