source: trunk/autoquest-ui-core/src/main/java/de/ugoe/cs/autoquest/commands/usage/CMDgenerateFixedLengthSequences.java @ 927

Last change on this file since 927 was 927, checked in by sherbold, 12 years ago
  • added copyright under the Apache License, Version 2.0
  • Property svn:mime-type set to text/plain
File size: 3.3 KB
Line 
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
15package de.ugoe.cs.autoquest.commands.usage;
16
17import java.util.Collection;
18import java.util.List;
19
20import de.ugoe.cs.autoquest.CommandHelpers;
21import de.ugoe.cs.autoquest.eventcore.Event;
22import de.ugoe.cs.autoquest.testgeneration.DrawFromAllSequencesGenerator;
23import de.ugoe.cs.autoquest.usageprofiles.IStochasticProcess;
24import de.ugoe.cs.util.console.Command;
25import de.ugoe.cs.util.console.Console;
26import de.ugoe.cs.util.console.GlobalDataContainer;
27
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 */
36public class CMDgenerateFixedLengthSequences implements Command {
37
38        /*
39         * (non-Javadoc)
40         *
41         * @see de.ugoe.cs.util.console.Command#run(java.util.List)
42         */
43        @Override
44        public void run(List<Object> parameters) {
45                String modelname;
46                String sequencesName;
47                int minLength;
48                int maxLength;
49                boolean all = true;
50                int numSequences = -1;
51                boolean validEnd = true;
52                try {
53                        modelname = (String) parameters.get(0);
54                        sequencesName = (String) parameters.get(1);
55                        minLength = Integer.parseInt((String) parameters.get(2));
56                        maxLength = Integer.parseInt((String) parameters.get(3));
57                        if (parameters.size() >= 5) {
58                                all = Boolean.parseBoolean((String) parameters.get(4));
59                        }
60                        if (parameters.size() >= 6) {
61                                numSequences = Integer.parseInt((String) parameters.get(5));
62                        }
63                        if (parameters.size() >= 7) {
64                                validEnd = Boolean.parseBoolean((String) parameters.get(6));
65                        }
66                } catch (Exception e) {
67                        throw new IllegalArgumentException();
68                }
69
70                IStochasticProcess model = null;
71                Object dataObject = GlobalDataContainer.getInstance()
72                                .getData(modelname);
73                if (dataObject == null) {
74                        CommandHelpers.objectNotFoundMessage(modelname);
75                        return;
76                } else if (!(dataObject instanceof IStochasticProcess)) {
77                        CommandHelpers.objectNotType(modelname, "IStochasticProcess");
78                        return;
79                }
80                model = (IStochasticProcess) dataObject;
81                DrawFromAllSequencesGenerator generator = new DrawFromAllSequencesGenerator(
82                                numSequences, minLength, maxLength, validEnd, all);
83                Collection<List<Event>> sequences = generator
84                                .generateTestSuite(model);
85
86                if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) {
87                        CommandHelpers.dataOverwritten(sequencesName);
88                }
89                Console.println("" + sequences.size() + " sequences generated");
90        }
91
92        /*
93         * (non-Javadoc)
94         *
95         * @see de.ugoe.cs.util.console.Command#help()
96         */
97        @Override
98        public String help() {
99                return "generateFixedLengthSequences <modelname> <sequencesName> <minlenght> <maxlength> {<all>} {<numSequences>} {<validEnd>}";
100        }
101
102}
Note: See TracBrowser for help on using the repository browser.