1 | package de.ugoe.cs.quest.commands.usage;
|
---|
2 |
|
---|
3 | import java.security.InvalidParameterException;
|
---|
4 | import java.util.Collection;
|
---|
5 | import java.util.List;
|
---|
6 |
|
---|
7 | import de.ugoe.cs.quest.CommandHelpers;
|
---|
8 | import de.ugoe.cs.quest.SequenceInstanceOf;
|
---|
9 | import de.ugoe.cs.quest.eventcore.Event;
|
---|
10 | import de.ugoe.cs.quest.usageprofiles.TrieBasedModel;
|
---|
11 | import de.ugoe.cs.util.console.Command;
|
---|
12 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
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 | CommandHelpers.objectNotFoundMessage(sequencesName);
|
---|
46 | return;
|
---|
47 | }
|
---|
48 | if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) {
|
---|
49 | CommandHelpers.objectNotType(sequencesName,
|
---|
50 | "Collection<List<Event<?>>>");
|
---|
51 | return;
|
---|
52 | }
|
---|
53 | Collection<List<Event>> sequences = (Collection<List<Event>>) dataObject;
|
---|
54 |
|
---|
55 | dataObject = GlobalDataContainer.getInstance().getData(modelname);
|
---|
56 | if (dataObject == null) {
|
---|
57 | CommandHelpers.objectNotFoundMessage(modelname);
|
---|
58 | return;
|
---|
59 | }
|
---|
60 | if (!(dataObject instanceof TrieBasedModel)) {
|
---|
61 | CommandHelpers.objectNotType(modelname, "TrieBasedModel");
|
---|
62 | return;
|
---|
63 | }
|
---|
64 |
|
---|
65 | TrieBasedModel model = (TrieBasedModel) dataObject;
|
---|
66 | model.update(sequences);
|
---|
67 | }
|
---|
68 |
|
---|
69 | /*
|
---|
70 | * (non-Javadoc)
|
---|
71 | *
|
---|
72 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
73 | */
|
---|
74 | @Override
|
---|
75 | public String help() {
|
---|
76 | return "updateModel <modelname> <sequencesName>";
|
---|
77 | }
|
---|
78 |
|
---|
79 | }
|
---|