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