From fd6d1aa06ba983e17833b11393cfb344e5825fba Mon Sep 17 00:00:00 2001 From: Gavriel Fleischer Date: Sat, 9 Nov 2019 23:50:29 +0200 Subject: replace missing command keys with empty string --- src/main/java/org/traccar/StringProtocolEncoder.java | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/main/java/org/traccar/StringProtocolEncoder.java b/src/main/java/org/traccar/StringProtocolEncoder.java index d9acce7f0..7041a31ab 100644 --- a/src/main/java/org/traccar/StringProtocolEncoder.java +++ b/src/main/java/org/traccar/StringProtocolEncoder.java @@ -17,7 +17,10 @@ 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 { @@ -33,6 +36,7 @@ public abstract class StringProtocolEncoder extends BaseProtocolEncoder { String result = String.format(format, (Object[]) keys); + Set missingKeys = new HashSet<>(Arrays.asList(keys)); result = result.replaceAll("\\{" + Command.KEY_UNIQUE_ID + "}", getUniqueId(command.getDeviceId())); for (Map.Entry entry : command.getAttributes().entrySet()) { String value = null; @@ -43,6 +47,10 @@ public abstract class StringProtocolEncoder extends BaseProtocolEncoder { value = entry.getValue().toString(); } result = result.replaceAll("\\{" + entry.getKey() + "}", value); + missingKeys.remove(entry.getKey()); + } + for (String key : missingKeys) { + result = result.replaceAll("\\{" + key + "}", ""); } return result; -- cgit v1.2.3