aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/command
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-07-17 16:28:36 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-07-17 16:28:36 +1200
commit3f6f92cedd969e741e65bb6e14737b98722b214e (patch)
tree97b19d441bb9f79c73db493d6ad52b2e422ec1ba /src/org/traccar/command
parentb6ba5a8ac60e8013e22ed44b15ffdc5ad8097060 (diff)
downloadtrackermap-server-3f6f92cedd969e741e65bb6e14737b98722b214e.tar.gz
trackermap-server-3f6f92cedd969e741e65bb6e14737b98722b214e.tar.bz2
trackermap-server-3f6f92cedd969e741e65bb6e14737b98722b214e.zip
Start re-factoring commands
Diffstat (limited to 'src/org/traccar/command')
-rw-r--r--src/org/traccar/command/CommandTemplate.java8
-rw-r--r--src/org/traccar/command/CommandType.java25
-rw-r--r--src/org/traccar/command/CommandValueConversion.java5
-rw-r--r--src/org/traccar/command/Duration.java38
-rw-r--r--src/org/traccar/command/FixPositioningCommand.java25
-rw-r--r--src/org/traccar/command/GpsCommand.java27
-rw-r--r--src/org/traccar/command/NoParameterCommand.java11
-rw-r--r--src/org/traccar/command/StringCommandTemplate.java54
8 files changed, 0 insertions, 193 deletions
diff --git a/src/org/traccar/command/CommandTemplate.java b/src/org/traccar/command/CommandTemplate.java
deleted file mode 100644
index cdc9be7ab..000000000
--- a/src/org/traccar/command/CommandTemplate.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package org.traccar.command;
-
-import org.traccar.database.ActiveDevice;
-import org.traccar.command.GpsCommand;
-
-public interface CommandTemplate<T extends GpsCommand> {
- Object applyTo(ActiveDevice activeDevice, T command);
-}
diff --git a/src/org/traccar/command/CommandType.java b/src/org/traccar/command/CommandType.java
deleted file mode 100644
index 56596fa41..000000000
--- a/src/org/traccar/command/CommandType.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.traccar.command;
-
-import org.traccar.model.Factory;
-
-public enum CommandType implements Factory {
- STOP_POSITIONING(NoParameterCommand.class),
- FIX_POSITIONING(FixPositioningCommand.class),
- STOP_ENGINE(NoParameterCommand.class),
- RESUME_ENGINE(NoParameterCommand.class);
-
- private final Class<? extends GpsCommand> commandClass;
-
- CommandType(Class<? extends GpsCommand> commandClass) {
- this.commandClass = commandClass;
- }
-
- @Override
- public Object create() {
- try {
- return commandClass.newInstance();
- } catch (InstantiationException | IllegalAccessException error) {
- throw new RuntimeException(error);
- }
- }
-}
diff --git a/src/org/traccar/command/CommandValueConversion.java b/src/org/traccar/command/CommandValueConversion.java
deleted file mode 100644
index 5c8b75313..000000000
--- a/src/org/traccar/command/CommandValueConversion.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package org.traccar.command;
-
-public interface CommandValueConversion<T> {
- public String convert(T value);
-}
diff --git a/src/org/traccar/command/Duration.java b/src/org/traccar/command/Duration.java
deleted file mode 100644
index a2ed2c991..000000000
--- a/src/org/traccar/command/Duration.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package org.traccar.command;
-
-public class Duration {
-
- public enum TimeUnit {
- SECOND("s"), MINUTE("m"), HOUR("h");
-
- private final String commandFormat;
-
- TimeUnit(String commandFormat) {
- this.commandFormat = commandFormat;
- }
-
- public String getCommandFormat() {
- return commandFormat;
- }
- }
-
-
- private TimeUnit unit;
- private int value;
-
- public TimeUnit getUnit() {
- return unit;
- }
-
- public void setUnit(TimeUnit unit) {
- this.unit = unit;
- }
-
- public int getValue() {
- return value;
- }
-
- public void setValue(int value) {
- this.value = value;
- }
-}
diff --git a/src/org/traccar/command/FixPositioningCommand.java b/src/org/traccar/command/FixPositioningCommand.java
deleted file mode 100644
index 18d5f32fb..000000000
--- a/src/org/traccar/command/FixPositioningCommand.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.traccar.command;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class FixPositioningCommand extends GpsCommand {
- public static final String FREQUENCY = "frequency";
-
- private Duration data;
-
- @Override
- public Map<String, Object> getReplacements() {
- Map<String, Object> replacements = new HashMap<>();
- replacements.put(FREQUENCY, data);
- return replacements;
- }
-
- public Duration getData() {
- return data;
- }
-
- public void setData(Duration data) {
- this.data = data;
- }
-}
diff --git a/src/org/traccar/command/GpsCommand.java b/src/org/traccar/command/GpsCommand.java
deleted file mode 100644
index 7097c4807..000000000
--- a/src/org/traccar/command/GpsCommand.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package org.traccar.command;
-
-import java.util.Map;
-
-public abstract class GpsCommand {
- public static final String UNIQUE_ID = "uniqueId";
- private String uniqueId;
- private CommandType type;
-
- public String getUniqueId() {
- return uniqueId;
- }
-
- public void setUniqueId(String uniqueId) {
- this.uniqueId = uniqueId;
- }
-
- public CommandType getType() {
- return type;
- }
-
- public void setType(CommandType type) {
- this.type = type;
- }
-
- public abstract Map<String, Object> getReplacements();
-}
diff --git a/src/org/traccar/command/NoParameterCommand.java b/src/org/traccar/command/NoParameterCommand.java
deleted file mode 100644
index f4e139b7b..000000000
--- a/src/org/traccar/command/NoParameterCommand.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package org.traccar.command;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class NoParameterCommand extends GpsCommand {
- @Override
- public Map<String, Object> getReplacements() {
- return new HashMap<>();
- }
-}
diff --git a/src/org/traccar/command/StringCommandTemplate.java b/src/org/traccar/command/StringCommandTemplate.java
deleted file mode 100644
index 3f326e534..000000000
--- a/src/org/traccar/command/StringCommandTemplate.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package org.traccar.command;
-
-import org.traccar.database.ActiveDevice;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class StringCommandTemplate<T extends GpsCommand> implements CommandTemplate<T> {
-
- private String messageTemplate;
- private Map<Class<?>, CommandValueConversion> converters = new HashMap<>();
-
- public StringCommandTemplate(String template, Object... replacements) {
- this.messageTemplate = String.format(template, replacements);
- }
-
- @Override
- public Object applyTo(ActiveDevice activeDevice, T command) {
- String currentMessage = messageTemplate;
- currentMessage = this.replace(currentMessage, GpsCommand.UNIQUE_ID, activeDevice.getUniqueId());
-
- Map<String, Object> replacements = command.getReplacements();
-
- for (Map.Entry<String, Object> entry : replacements.entrySet()) {
- currentMessage = this.replace(currentMessage, entry.getKey(), entry.getValue());
- }
-
- return currentMessage;
- }
-
- public CommandTemplate addConverter(Class<?> type, CommandValueConversion converter) {
- converters.put(type, converter);
- return this;
- }
-
- protected CommandValueConversion getConverter(Class<?> type) {
- return converters.containsKey(type) ? converters.get(type) : idConverter();
- }
-
- private CommandValueConversion idConverter() {
- return new CommandValueConversion() {
- @Override
- public String convert(Object value) {
- return value.toString();
- }
- };
- }
-
- private String replace(String currentMessage, String key, Object value) {
- String replacementValue = getConverter(value.getClass()).convert(value);
- return currentMessage.replace("[" + key + "]", replacementValue);
- }
-
-}