[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;
|
---|
[96] | 16 |
|
---|
[103] | 17 | import java.util.Collection;
|
---|
[96] | 18 | import java.util.List;
|
---|
| 19 |
|
---|
[922] | 20 | import de.ugoe.cs.autoquest.CommandHelpers;
|
---|
| 21 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
| 22 | import de.ugoe.cs.autoquest.testgeneration.DrawFromAllSequencesGenerator;
|
---|
| 23 | import de.ugoe.cs.autoquest.usageprofiles.IStochasticProcess;
|
---|
[96] | 24 | import de.ugoe.cs.util.console.Command;
|
---|
| 25 | import de.ugoe.cs.util.console.Console;
|
---|
[667] | 26 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
[96] | 27 |
|
---|
[171] | 28 | /**
|
---|
| 29 | * <p>
|
---|
| 30 | * Command to generate all sequences of a given length.
|
---|
| 31 | * </p>
|
---|
| 32 | *
|
---|
| 33 | * @author Steffen Herbold
|
---|
| 34 | * @version 1.0
|
---|
| 35 | */
|
---|
[96] | 36 | public class CMDgenerateFixedLengthSequences implements Command {
|
---|
| 37 |
|
---|
[171] | 38 | /*
|
---|
| 39 | * (non-Javadoc)
|
---|
| 40 | *
|
---|
| 41 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 42 | */
|
---|
[96] | 43 | @Override
|
---|
| 44 | public void run(List<Object> parameters) {
|
---|
| 45 | String modelname;
|
---|
| 46 | String sequencesName;
|
---|
[120] | 47 | int minLength;
|
---|
| 48 | int maxLength;
|
---|
| 49 | boolean all = true;
|
---|
| 50 | int numSequences = -1;
|
---|
[393] | 51 | boolean validEnd = true;
|
---|
[96] | 52 | try {
|
---|
| 53 | modelname = (String) parameters.get(0);
|
---|
| 54 | sequencesName = (String) parameters.get(1);
|
---|
[120] | 55 | minLength = Integer.parseInt((String) parameters.get(2));
|
---|
| 56 | maxLength = Integer.parseInt((String) parameters.get(3));
|
---|
[171] | 57 | if (parameters.size() >= 5) {
|
---|
[120] | 58 | all = Boolean.parseBoolean((String) parameters.get(4));
|
---|
| 59 | }
|
---|
[393] | 60 | if (parameters.size() >= 6) {
|
---|
[171] | 61 | numSequences = Integer.parseInt((String) parameters.get(5));
|
---|
[120] | 62 | }
|
---|
[393] | 63 | if (parameters.size() >= 7) {
|
---|
| 64 | validEnd = Boolean.parseBoolean((String) parameters.get(6));
|
---|
| 65 | }
|
---|
[171] | 66 | } catch (Exception e) {
|
---|
[766] | 67 | throw new IllegalArgumentException();
|
---|
[96] | 68 | }
|
---|
[171] | 69 |
|
---|
| 70 | IStochasticProcess model = null;
|
---|
| 71 | Object dataObject = GlobalDataContainer.getInstance()
|
---|
| 72 | .getData(modelname);
|
---|
| 73 | if (dataObject == null) {
|
---|
[240] | 74 | CommandHelpers.objectNotFoundMessage(modelname);
|
---|
[209] | 75 | return;
|
---|
[171] | 76 | } else if (!(dataObject instanceof IStochasticProcess)) {
|
---|
[240] | 77 | CommandHelpers.objectNotType(modelname, "IStochasticProcess");
|
---|
[209] | 78 | return;
|
---|
| 79 | }
|
---|
| 80 | model = (IStochasticProcess) dataObject;
|
---|
[524] | 81 | DrawFromAllSequencesGenerator generator = new DrawFromAllSequencesGenerator(
|
---|
| 82 | numSequences, minLength, maxLength, validEnd, all);
|
---|
[547] | 83 | Collection<List<Event>> sequences = generator
|
---|
[524] | 84 | .generateTestSuite(model);
|
---|
| 85 |
|
---|
[209] | 86 | if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) {
|
---|
[240] | 87 | CommandHelpers.dataOverwritten(sequencesName);
|
---|
[209] | 88 | }
|
---|
| 89 | Console.println("" + sequences.size() + " sequences generated");
|
---|
[96] | 90 | }
|
---|
| 91 |
|
---|
[171] | 92 | /*
|
---|
| 93 | * (non-Javadoc)
|
---|
| 94 | *
|
---|
| 95 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 96 | */
|
---|
[96] | 97 | @Override
|
---|
[664] | 98 | public String help() {
|
---|
| 99 | return "generateFixedLengthSequences <modelname> <sequencesName> <minlenght> <maxlength> {<all>} {<numSequences>} {<validEnd>}";
|
---|
[96] | 100 | }
|
---|
| 101 |
|
---|
| 102 | }
|
---|