aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/handler/ComputedAttributesHandler.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/handler/ComputedAttributesHandler.java')
-rw-r--r--src/main/java/org/traccar/handler/ComputedAttributesHandler.java64
1 files changed, 24 insertions, 40 deletions
diff --git a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java
index d286866a5..f4079f127 100644
--- a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java
+++ b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java
@@ -146,57 +146,41 @@ public class ComputedAttributesHandler extends BasePositionHandler {
.collect(Collectors.toUnmodifiableList());
for (Attribute attribute : attributes) {
if (attribute.getAttribute() != null) {
- Object result = null;
try {
- result = computeAttribute(attribute, position);
- } catch (JexlException error) {
- LOGGER.warn("Attribute computation error", error);
- }
- if (result != null) {
- try {
+ Object result = computeAttribute(attribute, position);
+ if (result != null) {
switch (attribute.getAttribute()) {
- case "valid":
- position.setValid((Boolean) result);
- break;
- case "latitude":
- position.setLatitude(((Number) result).doubleValue());
- break;
- case "longitude":
- position.setLongitude(((Number) result).doubleValue());
- break;
- case "altitude":
- position.setAltitude(((Number) result).doubleValue());
- break;
- case "speed":
- position.setSpeed(((Number) result).doubleValue());
- break;
- case "course":
- position.setCourse(((Number) result).doubleValue());
- break;
- case "address":
- position.setAddress((String) result);
- break;
- case "accuracy":
- position.setAccuracy(((Number) result).doubleValue());
- break;
- default:
+ case "valid" -> position.setValid((Boolean) result);
+ case "latitude" -> position.setLatitude(((Number) result).doubleValue());
+ case "longitude" -> position.setLongitude(((Number) result).doubleValue());
+ case "altitude" -> position.setAltitude(((Number) result).doubleValue());
+ case "speed" -> position.setSpeed(((Number) result).doubleValue());
+ case "course" -> position.setCourse(((Number) result).doubleValue());
+ case "address" -> position.setAddress((String) result);
+ case "accuracy" -> position.setAccuracy(((Number) result).doubleValue());
+ default -> {
switch (attribute.getType()) {
- case "number":
+ case "number" -> {
Number numberValue = (Number) result;
position.getAttributes().put(attribute.getAttribute(), numberValue);
- break;
- case "boolean":
+ }
+ case "boolean" -> {
Boolean booleanValue = (Boolean) result;
position.getAttributes().put(attribute.getAttribute(), booleanValue);
- break;
- default:
+ }
+ default -> {
position.getAttributes().put(attribute.getAttribute(), result.toString());
+ }
}
- break;
+ }
}
- } catch (ClassCastException error) {
- LOGGER.warn("Attribute cast error", error);
+ } else {
+ position.getAttributes().remove(attribute.getAttribute());
}
+ } catch (JexlException error) {
+ LOGGER.warn("Attribute computation error", error);
+ } catch (ClassCastException error) {
+ LOGGER.warn("Attribute cast error", error);
}
}
}