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.CommandHelpers;
|
---|
8 | import de.ugoe.cs.eventbench.SequenceInstanceOf;
|
---|
9 | import de.ugoe.cs.eventbench.data.Event;
|
---|
10 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
11 | import de.ugoe.cs.eventbench.models.TrieBasedModel;
|
---|
12 | import de.ugoe.cs.util.console.Command;
|
---|
13 | import de.ugoe.cs.util.console.Console;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * <p>
|
---|
17 | * Command to update a {@link TrieBasedModel}.
|
---|
18 | * </p>
|
---|
19 | *
|
---|
20 | * @author Steffen Herbold
|
---|
21 | * @version 1.0
|
---|
22 | */
|
---|
23 | public class CMDupdateModel implements Command {
|
---|
24 |
|
---|
25 | /*
|
---|
26 | * (non-Javadoc)
|
---|
27 | *
|
---|
28 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
29 | */
|
---|
30 | @SuppressWarnings("unchecked")
|
---|
31 | @Override
|
---|
32 | public void run(List<Object> parameters) {
|
---|
33 | String modelname;
|
---|
34 | String sequencesName;
|
---|
35 |
|
---|
36 | try {
|
---|
37 | modelname = (String) parameters.get(0);
|
---|
38 | sequencesName = (String) parameters.get(1);
|
---|
39 | } catch (Exception e) {
|
---|
40 | throw new InvalidParameterException();
|
---|
41 | }
|
---|
42 |
|
---|
43 | Object dataObject = GlobalDataContainer.getInstance().getData(
|
---|
44 | sequencesName);
|
---|
45 | if (dataObject == null) {
|
---|
46 | CommandHelpers.objectNotFoundMessage(sequencesName);
|
---|
47 | return;
|
---|
48 | }
|
---|
49 | if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) {
|
---|
50 | CommandHelpers.objectNotType(sequencesName,
|
---|
51 | "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 | CommandHelpers.objectNotFoundMessage(modelname);
|
---|
59 | return;
|
---|
60 | }
|
---|
61 | if (!(dataObject instanceof TrieBasedModel)) {
|
---|
62 | CommandHelpers.objectNotType(modelname, "TrieBasedModel");
|
---|
63 | return;
|
---|
64 | }
|
---|
65 |
|
---|
66 | TrieBasedModel model = (TrieBasedModel) dataObject;
|
---|
67 | model.update(sequences);
|
---|
68 | }
|
---|
69 |
|
---|
70 | /*
|
---|
71 | * (non-Javadoc)
|
---|
72 | *
|
---|
73 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
74 | */
|
---|
75 | @Override
|
---|
76 | public void help() {
|
---|
77 | Console.println("Usage: updateModel <modelname> <sequencesName>");
|
---|
78 | }
|
---|
79 |
|
---|
80 | }
|
---|