diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-06-30 09:41:41 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-06-30 09:41:41 +1200 |
commit | 54c54703d66e8991472c1f7476ba4acb424b27d9 (patch) | |
tree | b43f2f0225b7722a1543a973a568ee2854e7b413 /src/org/traccar/protocol/commands | |
parent | c646926a7fb0e66407c1ed7aa18daa1c9fc41cd8 (diff) | |
download | trackermap-server-54c54703d66e8991472c1f7476ba4acb424b27d9.tar.gz trackermap-server-54c54703d66e8991472c1f7476ba4acb424b27d9.tar.bz2 trackermap-server-54c54703d66e8991472c1f7476ba4acb424b27d9.zip |
Move commands related classes
Diffstat (limited to 'src/org/traccar/protocol/commands')
3 files changed, 0 insertions, 69 deletions
diff --git a/src/org/traccar/protocol/commands/CommandTemplate.java b/src/org/traccar/protocol/commands/CommandTemplate.java deleted file mode 100644 index 5d461b276..000000000 --- a/src/org/traccar/protocol/commands/CommandTemplate.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.traccar.protocol.commands; - -import org.traccar.database.ActiveDevice; -import org.traccar.http.commands.GpsCommand; - -public interface CommandTemplate<T extends GpsCommand> { - Object applyTo(ActiveDevice activeDevice, T command); -} diff --git a/src/org/traccar/protocol/commands/CommandValueConversion.java b/src/org/traccar/protocol/commands/CommandValueConversion.java deleted file mode 100644 index cfbf3ce5a..000000000 --- a/src/org/traccar/protocol/commands/CommandValueConversion.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.traccar.protocol.commands; - -public interface CommandValueConversion<T> { - public String convert(T value); -} diff --git a/src/org/traccar/protocol/commands/StringCommandTemplate.java b/src/org/traccar/protocol/commands/StringCommandTemplate.java deleted file mode 100644 index 2ac0ce9a8..000000000 --- a/src/org/traccar/protocol/commands/StringCommandTemplate.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.traccar.protocol.commands; - -import org.traccar.database.ActiveDevice; -import org.traccar.http.commands.GpsCommand; -import org.traccar.protocol.commands.CommandValueConversion; - -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<Class<?>, CommandValueConversion>(); - - 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); - } - -} |