source: trunk/autoquest-ui-core/src/main/java/de/ugoe/cs/autoquest/commands/usability/CMDgenerateTaskTree.java @ 2132

Last change on this file since 2132 was 2132, checked in by pharms, 8 years ago
  • added possibility to select the minimal amount of action instances a detected sequence must cover
File size: 5.0 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.usability;
16
17import java.util.Collection;
18import java.util.List;
19
20import de.ugoe.cs.autoquest.CommandHelpers;
21import de.ugoe.cs.autoquest.SequenceInstanceOf;
22import de.ugoe.cs.autoquest.eventcore.Event;
23import de.ugoe.cs.autoquest.tasktrees.manager.TaskTreeManager;
24import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
25import de.ugoe.cs.util.console.Command;
26import de.ugoe.cs.util.console.GlobalDataContainer;
27
28/**
29 * <p>
30 * This command generates a task tree based on the provided sequences. It uses the
31 * {@link TaskTreeManager} for this purpose. Please consult the documentation of the task tree
32 * manager for more details.
33 * </p>
34 *
35 * @author Patrick Harms
36 * @version 1.0
37 */
38public class CMDgenerateTaskTree implements Command {
39
40    /*
41     * (non-Javadoc)
42     *
43     * @see de.ugoe.cs.util.console.Command#help()
44     */
45    @Override
46    public String help() {
47        return "generateTaskTree <sequences> {<tasktree>} {-considerEventEquality} " +
48            "{-minimumSequenceCoverage=<some integer>}";
49    }
50
51    /*
52     * (non-Javadoc)
53     *
54     * @see de.ugoe.cs.util.console.Command#run(java.util.List)
55     */
56    @SuppressWarnings("unchecked")
57    @Override
58    public void run(List<Object> parameters) {
59        String sequencesName = null;
60        String tasktreeName = null;
61        boolean useEventEqualityForTaskComparison = false;
62        int minimumSequenceCoverage = 0;
63       
64        try {
65            for (int i = 0; i < parameters.size(); i++) {
66                String parameter = (String) parameters.get(i);
67                if (!parameter.startsWith("-")) {
68                    if (sequencesName == null) {
69                        sequencesName = parameter;
70                    }
71                    else if (tasktreeName == null) {
72                        tasktreeName = parameter;
73                    }
74                    else {
75                        throw new IllegalArgumentException("unrecognized parameter: " + parameter);
76                    }
77                }
78                else {
79                    if ("-considerEventEquality".equals(parameter)) {
80                        useEventEqualityForTaskComparison = true;
81                    }
82                    else if (parameter.startsWith("-minimumSequenceCoverage=")) {
83                        try {
84                            minimumSequenceCoverage = Integer.parseInt
85                                (parameter.substring("-minimumSequenceCoverage=".length()));
86                        }
87                        catch (Exception e) {
88                            throw new IllegalArgumentException
89                                ("invalid value for parameter minimumSequenceCoverage: " +
90                                 parameter.substring("-minimumSequenceCoverage=".length()));
91                        }
92                    }
93                    else {
94                        throw new IllegalArgumentException("unrecognized parameter: " + parameter);
95                    }
96                }
97            }
98        }
99        catch (IllegalArgumentException e) {
100            throw e;
101        }
102        catch (Exception e) {
103            throw new IllegalArgumentException("could not process parameters", e);
104        }
105       
106        if (sequencesName == null) {
107            throw new IllegalArgumentException("must provide a sequences name");
108        }
109       
110        if (tasktreeName == null) {
111            tasktreeName = "tasktree";
112        }
113
114        Collection<List<Event>> sequences = null;
115        Object dataObject = GlobalDataContainer.getInstance().getData(sequencesName);
116        if (dataObject == null) {
117            CommandHelpers.objectNotFoundMessage(sequencesName);
118            return;
119        }
120        if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) {
121            CommandHelpers.objectNotType(sequencesName, "Collection<List<Event<?>>>");
122            return;
123        }
124
125        sequences = (Collection<List<Event>>) dataObject;
126       
127        ITaskModel taskModel = new TaskTreeManager().createTaskModel
128            (sequences, useEventEqualityForTaskComparison, minimumSequenceCoverage);
129       
130        if (GlobalDataContainer.getInstance().addData(tasktreeName, taskModel)) {
131            CommandHelpers.dataOverwritten(tasktreeName);
132        }
133       
134    }
135
136}
Note: See TracBrowser for help on using the repository browser.