aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/handler
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-07-13 09:39:22 -0700
committerAnton Tananaev <anton@traccar.org>2022-07-13 09:39:22 -0700
commit33733f835e88a62c4a5259ab330723b88037adf1 (patch)
treef12c710dc4dd6c21a1434f3d699a2fcdd76bb0fa /src/main/java/org/traccar/handler
parentadbeacc62ecb91c94f6cfe7dea8e79b8f5e1c802 (diff)
downloadtrackermap-server-33733f835e88a62c4a5259ab330723b88037adf1.tar.gz
trackermap-server-33733f835e88a62c4a5259ab330723b88037adf1.tar.bz2
trackermap-server-33733f835e88a62c4a5259ab330723b88037adf1.zip
Simplify attribute check
Diffstat (limited to 'src/main/java/org/traccar/handler')
-rw-r--r--src/main/java/org/traccar/handler/CopyAttributesHandler.java3
-rw-r--r--src/main/java/org/traccar/handler/DistanceHandler.java4
-rw-r--r--src/main/java/org/traccar/handler/EngineHoursHandler.java2
-rw-r--r--src/main/java/org/traccar/handler/FilterHandler.java4
-rw-r--r--src/main/java/org/traccar/handler/MotionHandler.java2
-rw-r--r--src/main/java/org/traccar/handler/events/FuelDropEventHandler.java4
-rw-r--r--src/main/java/org/traccar/handler/events/IgnitionEventHandler.java4
-rw-r--r--src/main/java/org/traccar/handler/events/MotionEventHandler.java2
8 files changed, 12 insertions, 13 deletions
diff --git a/src/main/java/org/traccar/handler/CopyAttributesHandler.java b/src/main/java/org/traccar/handler/CopyAttributesHandler.java
index 50d36471a..1fa47cfaa 100644
--- a/src/main/java/org/traccar/handler/CopyAttributesHandler.java
+++ b/src/main/java/org/traccar/handler/CopyAttributesHandler.java
@@ -46,8 +46,7 @@ public class CopyAttributesHandler extends BaseDataHandler {
Position last = cacheManager.getPosition(position.getDeviceId());
if (last != null && attributesString != null) {
for (String attribute : attributesString.split("[ ,]")) {
- if (last.getAttributes().containsKey(attribute)
- && !position.getAttributes().containsKey(attribute)) {
+ if (last.hasAttribute(attribute) && !position.hasAttribute(attribute)) {
position.getAttributes().put(attribute, last.getAttributes().get(attribute));
}
}
diff --git a/src/main/java/org/traccar/handler/DistanceHandler.java b/src/main/java/org/traccar/handler/DistanceHandler.java
index fb82b5d8e..87c4a81c9 100644
--- a/src/main/java/org/traccar/handler/DistanceHandler.java
+++ b/src/main/java/org/traccar/handler/DistanceHandler.java
@@ -49,7 +49,7 @@ public class DistanceHandler extends BaseDataHandler {
protected Position handlePosition(Position position) {
double distance = 0.0;
- if (position.getAttributes().containsKey(Position.KEY_DISTANCE)) {
+ if (position.hasAttribute(Position.KEY_DISTANCE)) {
distance = position.getDouble(Position.KEY_DISTANCE);
}
double totalDistance = 0.0;
@@ -57,7 +57,7 @@ public class DistanceHandler extends BaseDataHandler {
Position last = cacheManager.getPosition(position.getDeviceId());
if (last != null) {
totalDistance = last.getDouble(Position.KEY_TOTAL_DISTANCE);
- if (!position.getAttributes().containsKey(Position.KEY_DISTANCE)) {
+ if (!position.hasAttribute(Position.KEY_DISTANCE)) {
distance = DistanceCalculator.distance(
position.getLatitude(), position.getLongitude(),
last.getLatitude(), last.getLongitude());
diff --git a/src/main/java/org/traccar/handler/EngineHoursHandler.java b/src/main/java/org/traccar/handler/EngineHoursHandler.java
index bfffdcb0c..54a1a0c25 100644
--- a/src/main/java/org/traccar/handler/EngineHoursHandler.java
+++ b/src/main/java/org/traccar/handler/EngineHoursHandler.java
@@ -35,7 +35,7 @@ public class EngineHoursHandler extends BaseDataHandler {
@Override
protected Position handlePosition(Position position) {
- if (!position.getAttributes().containsKey(Position.KEY_HOURS)) {
+ if (!position.hasAttribute(Position.KEY_HOURS)) {
Position last = cacheManager.getPosition(position.getDeviceId());
if (last != null) {
long hours = last.getLong(Position.KEY_HOURS);
diff --git a/src/main/java/org/traccar/handler/FilterHandler.java b/src/main/java/org/traccar/handler/FilterHandler.java
index 00cbf92a0..0bd57319a 100644
--- a/src/main/java/org/traccar/handler/FilterHandler.java
+++ b/src/main/java/org/traccar/handler/FilterHandler.java
@@ -103,7 +103,7 @@ public class FilterHandler extends BaseDataHandler {
private boolean filterDuplicate(Position position, Position last) {
if (filterDuplicate && last != null && position.getFixTime().equals(last.getFixTime())) {
for (String key : position.getAttributes().keySet()) {
- if (!last.getAttributes().containsKey(key)) {
+ if (!last.hasAttribute(key)) {
return false;
}
}
@@ -163,7 +163,7 @@ public class FilterHandler extends BaseDataHandler {
if (skipAttributes) {
String string = AttributeUtil.lookup(cacheManager, Keys.FILTER_SKIP_ATTRIBUTES, position.getDeviceId());
for (String attribute : string.split("[ ,]")) {
- if (position.getAttributes().containsKey(attribute)) {
+ if (position.hasAttribute(attribute)) {
return true;
}
}
diff --git a/src/main/java/org/traccar/handler/MotionHandler.java b/src/main/java/org/traccar/handler/MotionHandler.java
index 7b2c04ecf..25ee615c5 100644
--- a/src/main/java/org/traccar/handler/MotionHandler.java
+++ b/src/main/java/org/traccar/handler/MotionHandler.java
@@ -35,7 +35,7 @@ public class MotionHandler extends BaseDataHandler {
@Override
protected Position handlePosition(Position position) {
- if (!position.getAttributes().containsKey(Position.KEY_MOTION)) {
+ if (!position.hasAttribute(Position.KEY_MOTION)) {
position.set(Position.KEY_MOTION, position.getSpeed() > speedThreshold);
}
return position;
diff --git a/src/main/java/org/traccar/handler/events/FuelDropEventHandler.java b/src/main/java/org/traccar/handler/events/FuelDropEventHandler.java
index 2d105af3e..25ae1fadb 100644
--- a/src/main/java/org/traccar/handler/events/FuelDropEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/FuelDropEventHandler.java
@@ -53,8 +53,8 @@ public class FuelDropEventHandler extends BaseEventHandler {
cacheManager, Keys.EVENT_FUEL_DROP_THRESHOLD, position.getDeviceId());
if (fuelDropThreshold > 0) {
Position lastPosition = cacheManager.getPosition(position.getDeviceId());
- if (position.getAttributes().containsKey(Position.KEY_FUEL_LEVEL)
- && lastPosition != null && lastPosition.getAttributes().containsKey(Position.KEY_FUEL_LEVEL)) {
+ if (position.hasAttribute(Position.KEY_FUEL_LEVEL)
+ && lastPosition != null && lastPosition.hasAttribute(Position.KEY_FUEL_LEVEL)) {
double drop = lastPosition.getDouble(Position.KEY_FUEL_LEVEL)
- position.getDouble(Position.KEY_FUEL_LEVEL);
diff --git a/src/main/java/org/traccar/handler/events/IgnitionEventHandler.java b/src/main/java/org/traccar/handler/events/IgnitionEventHandler.java
index 6e411539c..3c5ac3545 100644
--- a/src/main/java/org/traccar/handler/events/IgnitionEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/IgnitionEventHandler.java
@@ -47,11 +47,11 @@ public class IgnitionEventHandler extends BaseEventHandler {
Map<Event, Position> result = null;
- if (position.getAttributes().containsKey(Position.KEY_IGNITION)) {
+ if (position.hasAttribute(Position.KEY_IGNITION)) {
boolean ignition = position.getBoolean(Position.KEY_IGNITION);
Position lastPosition = cacheManager.getPosition(position.getDeviceId());
- if (lastPosition != null && lastPosition.getAttributes().containsKey(Position.KEY_IGNITION)) {
+ if (lastPosition != null && lastPosition.hasAttribute(Position.KEY_IGNITION)) {
boolean oldIgnition = lastPosition.getBoolean(Position.KEY_IGNITION);
if (ignition && !oldIgnition) {
diff --git a/src/main/java/org/traccar/handler/events/MotionEventHandler.java b/src/main/java/org/traccar/handler/events/MotionEventHandler.java
index bc9d5f722..1be1896ef 100644
--- a/src/main/java/org/traccar/handler/events/MotionEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/MotionEventHandler.java
@@ -92,7 +92,7 @@ public class MotionEventHandler extends BaseEventHandler {
double distance = PositionUtil.calculateDistance(motionPosition, position, false);
Boolean ignition = null;
if (tripsConfig.getUseIgnition()
- && position.getAttributes().containsKey(Position.KEY_IGNITION)) {
+ && position.hasAttribute(Position.KEY_IGNITION)) {
ignition = position.getBoolean(Position.KEY_IGNITION);
}
if (newMotion) {