[434] | 1 | package de.ugoe.cs.quest.ui.commands;
|
---|
[184] | 2 |
|
---|
| 3 | import java.security.InvalidParameterException;
|
---|
[203] | 4 | import java.util.Collection;
|
---|
[184] | 5 | import java.util.List;
|
---|
| 6 |
|
---|
[432] | 7 | import de.ugoe.cs.quest.CommandHelpers;
|
---|
| 8 | import de.ugoe.cs.quest.SequenceInstanceOf;
|
---|
[433] | 9 | import de.ugoe.cs.quest.eventcore.Event;
|
---|
[434] | 10 | import de.ugoe.cs.quest.ui.GlobalDataContainer;
|
---|
[433] | 11 | import de.ugoe.cs.quest.usageprofiles.TrieBasedModel;
|
---|
[184] | 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) {
|
---|
[240] | 46 | CommandHelpers.objectNotFoundMessage(sequencesName);
|
---|
[184] | 47 | return;
|
---|
| 48 | }
|
---|
[209] | 49 | if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) {
|
---|
[240] | 50 | CommandHelpers.objectNotType(sequencesName,
|
---|
| 51 | "Collection<List<Event<?>>>");
|
---|
[184] | 52 | return;
|
---|
| 53 | }
|
---|
[547] | 54 | Collection<List<Event>> sequences = (Collection<List<Event>>) dataObject;
|
---|
[184] | 55 |
|
---|
| 56 | dataObject = GlobalDataContainer.getInstance().getData(modelname);
|
---|
| 57 | if (dataObject == null) {
|
---|
[240] | 58 | CommandHelpers.objectNotFoundMessage(modelname);
|
---|
[184] | 59 | return;
|
---|
| 60 | }
|
---|
| 61 | if (!(dataObject instanceof TrieBasedModel)) {
|
---|
[240] | 62 | CommandHelpers.objectNotType(modelname, "TrieBasedModel");
|
---|
[184] | 63 | return;
|
---|
| 64 | }
|
---|
[209] | 65 |
|
---|
[184] | 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 | }
|
---|