source: trunk/autoquest-ui-core/src/main/java/de/ugoe/cs/autoquest/commands/usability/CMDgenerateTaskTree.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
File size: 3.1 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.ITaskTree;
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>}";
48    }
49
50    /*
51     * (non-Javadoc)
52     *
53     * @see de.ugoe.cs.util.console.Command#run(java.util.List)
54     */
55    @SuppressWarnings("unchecked")
56    @Override
57    public void run(List<Object> parameters) {
58        String sequencesName;
59        String tasktreeName;
60        try {
61            sequencesName = (String) parameters.get(0);
62            if (parameters.size() > 1) {
63                tasktreeName = (String) parameters.get(1);
64            }
65            else {
66                tasktreeName = "tasktree";
67            }
68        }
69        catch (Exception e) {
70            throw new IllegalArgumentException("must provide a sequences name");
71        }
72
73        Collection<List<Event>> sequences = null;
74        Object dataObject = GlobalDataContainer.getInstance().getData(sequencesName);
75        if (dataObject == null) {
76            CommandHelpers.objectNotFoundMessage(sequencesName);
77            return;
78        }
79        if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) {
80            CommandHelpers.objectNotType(sequencesName, "Collection<List<Event<?>>>");
81            return;
82        }
83
84        sequences = (Collection<List<Event>>) dataObject;
85       
86        ITaskTree taskTree = new TaskTreeManager().createTaskTree(sequences);
87       
88        if (GlobalDataContainer.getInstance().addData(tasktreeName, taskTree)) {
89            CommandHelpers.dataOverwritten(sequencesName);
90        }
91       
92    }
93
94}
Note: See TracBrowser for help on using the repository browser.