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.SequenceInstanceOf;
|
---|
8 | import de.ugoe.cs.eventbench.data.Event;
|
---|
9 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
10 | import de.ugoe.cs.eventbench.models.TrieBasedModel;
|
---|
11 | import de.ugoe.cs.util.console.Command;
|
---|
12 | import de.ugoe.cs.util.console.Console;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * <p>
|
---|
16 | * Command to update a {@link TrieBasedModel}.
|
---|
17 | * </p>
|
---|
18 | *
|
---|
19 | * @author Steffen Herbold
|
---|
20 | * @version 1.0
|
---|
21 | */
|
---|
22 | public class CMDupdateModel 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 modelname;
|
---|
33 | String sequencesName;
|
---|
34 |
|
---|
35 | try {
|
---|
36 | modelname = (String) parameters.get(0);
|
---|
37 | sequencesName = (String) parameters.get(1);
|
---|
38 | } catch (Exception e) {
|
---|
39 | throw new InvalidParameterException();
|
---|
40 | }
|
---|
41 |
|
---|
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 | if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) {
|
---|
50 | Console.println("Object " + sequencesName
|
---|
51 | + "not of type Collection<List<Event<?>>>.");
|
---|
52 | return;
|
---|
53 | }
|
---|
54 | Collection<List<Event<?>>> sequences = (Collection<List<Event<?>>>) dataObject;
|
---|
55 |
|
---|
56 | dataObject = GlobalDataContainer.getInstance().getData(modelname);
|
---|
57 | if (dataObject == null) {
|
---|
58 | Console.println("Object " + modelname + " not found in storage.");
|
---|
59 | return;
|
---|
60 | }
|
---|
61 | if (!(dataObject instanceof TrieBasedModel)) {
|
---|
62 | Console.println("Object " + modelname
|
---|
63 | + " not of type TrieBasedModel");
|
---|
64 | return;
|
---|
65 | }
|
---|
66 |
|
---|
67 | TrieBasedModel model = (TrieBasedModel) dataObject;
|
---|
68 | model.update(sequences);
|
---|
69 | }
|
---|
70 |
|
---|
71 | /*
|
---|
72 | * (non-Javadoc)
|
---|
73 | *
|
---|
74 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
75 | */
|
---|
76 | @Override
|
---|
77 | public void help() {
|
---|
78 | Console.println("Usage: updateModel <modelname> <sequencesName>");
|
---|
79 | }
|
---|
80 |
|
---|
81 | }
|
---|