diff options
author | Gavriel Fleischer <flocsy@gmail.com> | 2019-11-11 00:20:13 +0200 |
---|---|---|
committer | Gavriel Fleischer <flocsy@gmail.com> | 2019-11-11 00:20:13 +0200 |
commit | 8a696af4d92821ccf741c21dcbe118861008743a (patch) | |
tree | 74cd5697a87603c4b17ca84206cea9fc34d91f9f /src/main/java/org/traccar/StringProtocolEncoder.java | |
parent | 47a1af1554b0216eae8248227407486c0eba8ef3 (diff) | |
parent | 81a7195b2efe148d47e3cf0cead0de415529bbab (diff) | |
download | trackermap-server-8a696af4d92821ccf741c21dcbe118861008743a.tar.gz trackermap-server-8a696af4d92821ccf741c21dcbe118861008743a.tar.bz2 trackermap-server-8a696af4d92821ccf741c21dcbe118861008743a.zip |
Merge branch 'master' into set-language
# Conflicts:
# src/main/java/org/traccar/StringProtocolEncoder.java
# src/main/java/org/traccar/protocol/WatchProtocolEncoder.java
Diffstat (limited to 'src/main/java/org/traccar/StringProtocolEncoder.java')
-rw-r--r-- | src/main/java/org/traccar/StringProtocolEncoder.java | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/src/main/java/org/traccar/StringProtocolEncoder.java b/src/main/java/org/traccar/StringProtocolEncoder.java index 7041a31ab..40dfb25b6 100644 --- a/src/main/java/org/traccar/StringProtocolEncoder.java +++ b/src/main/java/org/traccar/StringProtocolEncoder.java @@ -17,11 +17,6 @@ package org.traccar; import org.traccar.model.Command; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - public abstract class StringProtocolEncoder extends BaseProtocolEncoder { public StringProtocolEncoder(Protocol protocol) { @@ -34,26 +29,27 @@ public abstract class StringProtocolEncoder extends BaseProtocolEncoder { protected String formatCommand(Command command, String format, ValueFormatter valueFormatter, String... keys) { - String result = String.format(format, (Object[]) keys); - - Set<String> missingKeys = new HashSet<>(Arrays.asList(keys)); - result = result.replaceAll("\\{" + Command.KEY_UNIQUE_ID + "}", getUniqueId(command.getDeviceId())); - for (Map.Entry<String, Object> entry : command.getAttributes().entrySet()) { + Object[] values = new String[keys.length]; + for (int i = 0; i < keys.length; i++) { String value = null; - if (valueFormatter != null) { - value = valueFormatter.formatValue(entry.getKey(), entry.getValue()); + if (keys[i].equals(Command.KEY_UNIQUE_ID)) { + value = getUniqueId(command.getDeviceId()); + } else { + Object object = command.getAttributes().get(keys[i]); + if (valueFormatter != null) { + value = valueFormatter.formatValue(keys[i], object); + } + if (value == null) { + value = object.toString(); + } + if (value == null) { + value = ""; + } } - if (value == null) { - value = entry.getValue().toString(); - } - result = result.replaceAll("\\{" + entry.getKey() + "}", value); - missingKeys.remove(entry.getKey()); - } - for (String key : missingKeys) { - result = result.replaceAll("\\{" + key + "}", ""); + values[i] = value; } - return result; + return String.format(format, values); } protected String formatCommand(Command command, String format, String... keys) { |