source: trunk/autoquest-ui-core/src/main/java/de/ugoe/cs/autoquest/commands/sequences/CMDremoveStartEndSymbols.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: 2.6 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.sequences;
16
17import java.util.Collection;
18import java.util.Iterator;
19import java.util.List;
20
21import de.ugoe.cs.autoquest.CommandHelpers;
22import de.ugoe.cs.autoquest.SequenceInstanceOf;
23import de.ugoe.cs.autoquest.eventcore.Event;
24import de.ugoe.cs.util.console.Command;
25import de.ugoe.cs.util.console.GlobalDataContainer;
26
27/**
28 * <p>
29 * Command to remove the {@link Event#STARTEVENT} and {@link Event#ENDEVENT} from a sequence.
30 * </p>
31 *
32 * @version 1.0
33 * @author Steffen Herbold
34 */
35public class CMDremoveStartEndSymbols implements Command {
36
37    /*
38     * (non-Javadoc)
39     *
40     * @see de.ugoe.cs.util.console.Command#run(java.util.List)
41     */
42    @SuppressWarnings("unchecked")
43    @Override
44    public void run(List<Object> parameters) {
45        String sequencesName;
46        try {
47            sequencesName = (String) parameters.get(0);
48        }
49        catch (Exception e) {
50            throw new IllegalArgumentException();
51        }
52
53        Collection<List<Event>> sequences = null;
54        Object dataObject = GlobalDataContainer.getInstance().getData(sequencesName);
55        if (dataObject == null) {
56            CommandHelpers.objectNotFoundMessage(sequencesName);
57            return;
58        }
59        if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) {
60            CommandHelpers.objectNotType(sequencesName, "Collection<List<Event<?>>>");
61            return;
62        }
63
64        sequences = (Collection<List<Event>>) dataObject;
65
66        for (List<Event> sequence : sequences) {
67            Iterator<Event> iter = sequence.iterator();
68            while (iter.hasNext()) {
69                Event event = iter.next();
70                if (Event.ENDEVENT.equals(event) || Event.STARTEVENT.equals(event)) {
71                    iter.remove();
72                }
73            }
74        }
75
76    }
77
78    /*
79     * (non-Javadoc)
80     *
81     * @see de.ugoe.cs.util.console.Command#help()
82     */
83    @Override
84    public String help() {
85        return "removeStartEndSymbols <sequences>";
86    }
87
88}
Note: See TracBrowser for help on using the repository browser.