1 | package de.ugoe.cs.eventbench.commands;
|
---|
2 |
|
---|
3 | import java.security.InvalidParameterException;
|
---|
4 | import java.util.Collection;
|
---|
5 | import java.util.List;
|
---|
6 |
|
---|
7 | import de.ugoe.cs.eventbench.data.Event;
|
---|
8 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
9 | import de.ugoe.cs.eventbench.models.TrieBasedModel;
|
---|
10 | import de.ugoe.cs.util.console.Command;
|
---|
11 | import de.ugoe.cs.util.console.Console;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * <p>
|
---|
15 | * Command to update a {@link TrieBasedModel}.
|
---|
16 | * </p>
|
---|
17 | *
|
---|
18 | * @author Steffen Herbold
|
---|
19 | * @version 1.0
|
---|
20 | */
|
---|
21 | public class CMDupdateModel implements Command {
|
---|
22 |
|
---|
23 | /*
|
---|
24 | * (non-Javadoc)
|
---|
25 | *
|
---|
26 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
27 | */
|
---|
28 | @SuppressWarnings("unchecked")
|
---|
29 | @Override
|
---|
30 | public void run(List<Object> parameters) {
|
---|
31 | String modelname;
|
---|
32 | String sequencesName;
|
---|
33 |
|
---|
34 | try {
|
---|
35 | modelname = (String) parameters.get(0);
|
---|
36 | sequencesName = (String) parameters.get(1);
|
---|
37 | } catch (Exception e) {
|
---|
38 | throw new InvalidParameterException();
|
---|
39 | }
|
---|
40 |
|
---|
41 | Collection<List<Event<?>>> sequences = null;
|
---|
42 | Object dataObject = GlobalDataContainer.getInstance().getData(
|
---|
43 | sequencesName);
|
---|
44 | if (dataObject == null) {
|
---|
45 | Console.println("Object " + sequencesName
|
---|
46 | + " not found in storage.");
|
---|
47 | return;
|
---|
48 | }
|
---|
49 | try {
|
---|
50 | sequences = (Collection<List<Event<?>>>) dataObject;
|
---|
51 | } catch (ClassCastException e) {
|
---|
52 | Console.println("Object " + sequencesName
|
---|
53 | + "not of type Collection<List<Event<?>>>.");
|
---|
54 | }
|
---|
55 | if (sequences.size() == 0
|
---|
56 | || !(sequences.iterator().next().get(0) instanceof Event)) {
|
---|
57 | Console.println("Object " + sequencesName
|
---|
58 | + "not of type Collection<List<Event<?>>>.");
|
---|
59 | return;
|
---|
60 | }
|
---|
61 |
|
---|
62 | dataObject = GlobalDataContainer.getInstance().getData(modelname);
|
---|
63 | if (dataObject == null) {
|
---|
64 | Console.println("Model " + modelname + " not found in storage.");
|
---|
65 | return;
|
---|
66 | }
|
---|
67 | if (!(dataObject instanceof TrieBasedModel)) {
|
---|
68 | Console.println("Object " + modelname
|
---|
69 | + " not of type TrieBasedModel!");
|
---|
70 | return;
|
---|
71 | }
|
---|
72 | TrieBasedModel model = (TrieBasedModel) dataObject;
|
---|
73 | model.update(sequences);
|
---|
74 | }
|
---|
75 |
|
---|
76 | /*
|
---|
77 | * (non-Javadoc)
|
---|
78 | *
|
---|
79 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
80 | */
|
---|
81 | @Override
|
---|
82 | public void help() {
|
---|
83 | Console.println("Usage: updateModel <modelname> <sequencesName>");
|
---|
84 | }
|
---|
85 |
|
---|
86 | }
|
---|