[927] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
| 2 | //
|
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
| 4 | // you may not use this file except in compliance with the License.
|
---|
| 5 | // You may obtain a copy of the License at
|
---|
| 6 | //
|
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
| 8 | //
|
---|
| 9 | // Unless required by applicable law or agreed to in writing, software
|
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
| 12 | // See the License for the specific language governing permissions and
|
---|
| 13 | // limitations under the License.
|
---|
| 14 |
|
---|
[922] | 15 | package de.ugoe.cs.autoquest.commands.usage;
|
---|
[71] | 16 |
|
---|
| 17 | import java.util.Arrays;
|
---|
| 18 | import java.util.List;
|
---|
| 19 |
|
---|
[922] | 20 | import de.ugoe.cs.autoquest.CommandHelpers;
|
---|
| 21 | import de.ugoe.cs.autoquest.usageprofiles.IStochasticProcess;
|
---|
[71] | 22 | import de.ugoe.cs.util.console.Command;
|
---|
| 23 | import de.ugoe.cs.util.console.Console;
|
---|
[667] | 24 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
[71] | 25 |
|
---|
[171] | 26 | /**
|
---|
| 27 | * <p>
|
---|
| 28 | * Command to list all events (symbols) known to a usage profile (stochastic
|
---|
| 29 | * process).
|
---|
| 30 | * </p>
|
---|
| 31 | *
|
---|
| 32 | * @author Steffen Herbold
|
---|
| 33 | * @version 1.0
|
---|
| 34 | */
|
---|
[130] | 35 | public class CMDlistSymbols implements Command {
|
---|
[71] | 36 |
|
---|
[171] | 37 | /*
|
---|
| 38 | * (non-Javadoc)
|
---|
| 39 | *
|
---|
| 40 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 41 | */
|
---|
[71] | 42 | @Override
|
---|
| 43 | public void run(List<Object> parameters) {
|
---|
| 44 | String modelname = "";
|
---|
| 45 | boolean sort = false;
|
---|
| 46 | try {
|
---|
| 47 | modelname = (String) parameters.get(0);
|
---|
[171] | 48 | if (parameters.size() == 2) {
|
---|
[71] | 49 | sort = Boolean.parseBoolean((String) parameters.get(1));
|
---|
| 50 | }
|
---|
| 51 | } catch (Exception e) {
|
---|
[766] | 52 | throw new IllegalArgumentException();
|
---|
[71] | 53 | }
|
---|
[171] | 54 |
|
---|
| 55 | IStochasticProcess model = null;
|
---|
| 56 | Object dataObject = GlobalDataContainer.getInstance()
|
---|
| 57 | .getData(modelname);
|
---|
| 58 | if (dataObject == null) {
|
---|
[240] | 59 | CommandHelpers.objectNotFoundMessage(modelname);
|
---|
[209] | 60 | return;
|
---|
| 61 | }
|
---|
| 62 | if (!(dataObject instanceof IStochasticProcess)) {
|
---|
[240] | 63 | CommandHelpers.objectNotType(modelname, "IStochasticProcess");
|
---|
[209] | 64 | return;
|
---|
[71] | 65 | }
|
---|
[209] | 66 | model = (IStochasticProcess) dataObject;
|
---|
| 67 | String[] stateStrings = model.getSymbolStrings();
|
---|
| 68 | if (sort) {
|
---|
| 69 | Arrays.sort(stateStrings);
|
---|
| 70 | }
|
---|
| 71 | for (String stateString : stateStrings) {
|
---|
| 72 | Console.println(stateString);
|
---|
| 73 | }
|
---|
[71] | 74 | }
|
---|
| 75 |
|
---|
[171] | 76 | /*
|
---|
| 77 | * (non-Javadoc)
|
---|
| 78 | *
|
---|
| 79 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 80 | */
|
---|
[71] | 81 | @Override
|
---|
[664] | 82 | public String help() {
|
---|
[726] | 83 | return "listSymbols <modelname> {<sort>}";
|
---|
[71] | 84 | }
|
---|
| 85 |
|
---|
| 86 | }
|
---|