1 | |
---|
2 | package de.ugoe.cs.quest.commands.sequences; |
---|
3 | |
---|
4 | import java.util.Collection; |
---|
5 | import java.util.Iterator; |
---|
6 | import java.util.List; |
---|
7 | |
---|
8 | import de.ugoe.cs.quest.CommandHelpers; |
---|
9 | import de.ugoe.cs.quest.SequenceInstanceOf; |
---|
10 | import de.ugoe.cs.quest.eventcore.Event; |
---|
11 | import de.ugoe.cs.util.console.Command; |
---|
12 | import de.ugoe.cs.util.console.GlobalDataContainer; |
---|
13 | |
---|
14 | /** |
---|
15 | * <p> |
---|
16 | * Command to remove the {@link Event#STARTEVENT} and {@link Event#ENDEVENT} from a sequence. |
---|
17 | * </p> |
---|
18 | * |
---|
19 | * @version 1.0 |
---|
20 | * @author Steffen Herbold |
---|
21 | */ |
---|
22 | public class CMDremoveStartEndSymbols implements Command { |
---|
23 | |
---|
24 | /* |
---|
25 | * (non-Javadoc) |
---|
26 | * |
---|
27 | * @see de.ugoe.cs.util.console.Command#run(java.util.List) |
---|
28 | */ |
---|
29 | @SuppressWarnings("unchecked") |
---|
30 | @Override |
---|
31 | public void run(List<Object> parameters) { |
---|
32 | String sequencesName; |
---|
33 | try { |
---|
34 | sequencesName = (String) parameters.get(0); |
---|
35 | } |
---|
36 | catch (Exception e) { |
---|
37 | throw new IllegalArgumentException(); |
---|
38 | } |
---|
39 | |
---|
40 | Collection<List<Event>> sequences = null; |
---|
41 | Object dataObject = GlobalDataContainer.getInstance().getData(sequencesName); |
---|
42 | if (dataObject == null) { |
---|
43 | CommandHelpers.objectNotFoundMessage(sequencesName); |
---|
44 | return; |
---|
45 | } |
---|
46 | if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) { |
---|
47 | CommandHelpers.objectNotType(sequencesName, "Collection<List<Event<?>>>"); |
---|
48 | return; |
---|
49 | } |
---|
50 | |
---|
51 | sequences = (Collection<List<Event>>) dataObject; |
---|
52 | |
---|
53 | for (List<Event> sequence : sequences) { |
---|
54 | Iterator<Event> iter = sequence.iterator(); |
---|
55 | while (iter.hasNext()) { |
---|
56 | Event event = iter.next(); |
---|
57 | if (Event.ENDEVENT.equals(event) || Event.STARTEVENT.equals(event)) { |
---|
58 | iter.remove(); |
---|
59 | } |
---|
60 | } |
---|
61 | } |
---|
62 | |
---|
63 | } |
---|
64 | |
---|
65 | /* |
---|
66 | * (non-Javadoc) |
---|
67 | * |
---|
68 | * @see de.ugoe.cs.util.console.Command#help() |
---|
69 | */ |
---|
70 | @Override |
---|
71 | public String help() { |
---|
72 | return "removeStartEndSymbols <sequences>"; |
---|
73 | } |
---|
74 | |
---|
75 | } |
---|