Skip to content

Commit

Permalink
Simplify attribute formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Oct 21, 2024
1 parent eaba09c commit 94d6750
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/main/java/org/traccar/forward/PositionForwarderWialon.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void forward(PositionData positionData, ResultHandler resultHandler) {
(int) position.getCourse(),
(int) position.getAltitude(),
position.getString(Position.KEY_DRIVER_UNIQUE_ID, "NA"),
formatAttributes(position.getAttributes(), "NA"));
formatAttributes(position.getAttributes()));

String message;
if (version.startsWith("2")) {
Expand All @@ -111,26 +111,22 @@ public void forward(PositionData positionData, ResultHandler resultHandler) {
}
}

public static String formatAttributes(Map<String, Object> attributes, String defaultValue) {
public static String formatAttributes(Map<String, Object> attributes) {
if (attributes.isEmpty()) {
return defaultValue;
return "NA";
}

return attributes.entrySet().stream()
.map(entry -> {
String key = entry.getKey();
Object value = entry.getValue();

String type;
if (value instanceof Integer || value instanceof Long) {
type = "1";
} else if (value instanceof Double || value instanceof Float) {
type = "2";
int type;
if (value instanceof Double || value instanceof Float) {
type = 2;
} else if (value instanceof Number) {
type = 1;
} else {
type = "3";
type = 3;
}

return key + ":" + type + ":" + value.toString();
return entry.getKey() + ":" + type + ":" + value;
})
.collect(Collectors.joining(","));
}
Expand Down

0 comments on commit 94d6750

Please sign in to comment.