aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/events/AlertEventHandler.java8
-rw-r--r--src/org/traccar/events/CommandResultEventHandler.java8
-rw-r--r--src/org/traccar/events/IgnitionEventHandler.java10
-rw-r--r--src/org/traccar/events/MaintenanceEventHandler.java8
-rw-r--r--src/org/traccar/events/MotionEventHandler.java13
-rw-r--r--src/org/traccar/events/OverspeedEventHandler.java8
6 files changed, 27 insertions, 28 deletions
diff --git a/src/org/traccar/events/AlertEventHandler.java b/src/org/traccar/events/AlertEventHandler.java
index 296fe488c..7d0bd669b 100644
--- a/src/org/traccar/events/AlertEventHandler.java
+++ b/src/org/traccar/events/AlertEventHandler.java
@@ -15,8 +15,8 @@
*/
package org.traccar.events;
-import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import org.traccar.BaseEventHandler;
import org.traccar.model.Event;
@@ -28,9 +28,9 @@ public class AlertEventHandler extends BaseEventHandler {
protected Collection<Event> analyzePosition(Position position) {
Object alarm = position.getAttributes().get(Position.KEY_ALARM);
if (alarm != null) {
- Collection<Event> events = new ArrayList<>();
- events.add(new Event(Event.TYPE_ALARM, position.getDeviceId(), position.getId()));
- return events;
+ Event event = new Event(Event.TYPE_ALARM, position.getDeviceId(), position.getId());
+ event.set(Position.KEY_ALARM, (String) alarm);
+ return Collections.singleton(event);
}
return null;
}
diff --git a/src/org/traccar/events/CommandResultEventHandler.java b/src/org/traccar/events/CommandResultEventHandler.java
index aaa1d23f0..077c389c9 100644
--- a/src/org/traccar/events/CommandResultEventHandler.java
+++ b/src/org/traccar/events/CommandResultEventHandler.java
@@ -15,8 +15,8 @@
*/
package org.traccar.events;
-import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import org.traccar.BaseEventHandler;
import org.traccar.model.Event;
@@ -28,9 +28,9 @@ public class CommandResultEventHandler extends BaseEventHandler {
protected Collection<Event> analyzePosition(Position position) {
Object commandResult = position.getAttributes().get(Position.KEY_RESULT);
if (commandResult != null) {
- Collection<Event> events = new ArrayList<>();
- events.add(new Event(Event.TYPE_COMMAND_RESULT, position.getDeviceId(), position.getId()));
- return events;
+ Event event = new Event(Event.TYPE_COMMAND_RESULT, position.getDeviceId(), position.getId());
+ event.set(Position.KEY_RESULT, (String) commandResult);
+ return Collections.singleton(event);
}
return null;
}
diff --git a/src/org/traccar/events/IgnitionEventHandler.java b/src/org/traccar/events/IgnitionEventHandler.java
index 3086adb13..8464c3aef 100644
--- a/src/org/traccar/events/IgnitionEventHandler.java
+++ b/src/org/traccar/events/IgnitionEventHandler.java
@@ -16,8 +16,8 @@
*/
package org.traccar.events;
-import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import org.traccar.BaseEventHandler;
import org.traccar.Context;
@@ -48,11 +48,11 @@ public class IgnitionEventHandler extends BaseEventHandler {
}
if (ignition && !oldIgnition) {
- result = new ArrayList<>();
- result.add(new Event(Event.TYPE_IGNITION_ON, position.getDeviceId(), position.getId()));
+ result = Collections.singleton(
+ new Event(Event.TYPE_IGNITION_ON, position.getDeviceId(), position.getId()));
} else if (!ignition && oldIgnition) {
- result = new ArrayList<>();
- result.add(new Event(Event.TYPE_IGNITION_OFF, position.getDeviceId(), position.getId()));
+ result = Collections.singleton(
+ new Event(Event.TYPE_IGNITION_OFF, position.getDeviceId(), position.getId()));
}
return result;
}
diff --git a/src/org/traccar/events/MaintenanceEventHandler.java b/src/org/traccar/events/MaintenanceEventHandler.java
index 9e0da97f5..4d0d93080 100644
--- a/src/org/traccar/events/MaintenanceEventHandler.java
+++ b/src/org/traccar/events/MaintenanceEventHandler.java
@@ -16,8 +16,8 @@
*/
package org.traccar.events;
-import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import org.traccar.BaseEventHandler;
import org.traccar.Context;
@@ -45,7 +45,6 @@ public class MaintenanceEventHandler extends BaseEventHandler {
double maintenanceStart = Context.getDeviceManager()
.lookupAttributeDouble(device.getId(), ATTRIBUTE_MAINTENANCE_START, 0, false);
- Collection<Event> events = new ArrayList<>();
double oldTotalDistance = 0.0;
double newTotalDistance = 0.0;
@@ -57,11 +56,12 @@ public class MaintenanceEventHandler extends BaseEventHandler {
oldTotalDistance -= maintenanceStart;
newTotalDistance -= maintenanceStart;
+
if ((long) (oldTotalDistance / maintenanceInterval) < (long) (newTotalDistance / maintenanceInterval)) {
- events.add(new Event(Event.TYPE_MAINTENANCE, position.getDeviceId(), position.getId()));
+ return Collections.singleton(new Event(Event.TYPE_MAINTENANCE, position.getDeviceId(), position.getId()));
}
- return events;
+ return null;
}
}
diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java
index db19535a0..be8218985 100644
--- a/src/org/traccar/events/MotionEventHandler.java
+++ b/src/org/traccar/events/MotionEventHandler.java
@@ -15,8 +15,8 @@
*/
package org.traccar.events;
-import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import org.traccar.BaseEventHandler;
import org.traccar.Context;
@@ -43,7 +43,6 @@ public class MotionEventHandler extends BaseEventHandler {
return null;
}
- Collection<Event> result = null;
double speed = position.getSpeed();
double oldSpeed = 0;
Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
@@ -51,13 +50,13 @@ public class MotionEventHandler extends BaseEventHandler {
oldSpeed = lastPosition.getSpeed();
}
if (speed > speedThreshold && oldSpeed <= speedThreshold) {
- result = new ArrayList<>();
- result.add(new Event(Event.TYPE_DEVICE_MOVING, position.getDeviceId(), position.getId()));
+ return Collections.singleton(
+ new Event(Event.TYPE_DEVICE_MOVING, position.getDeviceId(), position.getId()));
} else if (speed <= speedThreshold && oldSpeed > speedThreshold) {
- result = new ArrayList<>();
- result.add(new Event(Event.TYPE_DEVICE_STOPPED, position.getDeviceId(), position.getId()));
+ return Collections.singleton(
+ new Event(Event.TYPE_DEVICE_STOPPED, position.getDeviceId(), position.getId()));
}
- return result;
+ return null;
}
}
diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java
index 505d706f4..67aa0e758 100644
--- a/src/org/traccar/events/OverspeedEventHandler.java
+++ b/src/org/traccar/events/OverspeedEventHandler.java
@@ -15,8 +15,8 @@
*/
package org.traccar.events;
-import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import org.traccar.BaseEventHandler;
import org.traccar.Context;
@@ -45,7 +45,6 @@ public class OverspeedEventHandler extends BaseEventHandler {
return null;
}
- Collection<Event> events = new ArrayList<>();
double speed = position.getSpeed();
double speedLimit = Context.getDeviceManager()
.lookupAttributeDouble(device.getId(), ATTRIBUTE_SPEED_LIMIT, 0, false);
@@ -60,9 +59,10 @@ public class OverspeedEventHandler extends BaseEventHandler {
}
}
if (speed > speedLimit && oldSpeed <= speedLimit) {
- events.add(new Event(Event.TYPE_DEVICE_OVERSPEED, position.getDeviceId(), position.getId()));
+ return Collections.singleton(
+ new Event(Event.TYPE_DEVICE_OVERSPEED, position.getDeviceId(), position.getId()));
}
- return events;
+ return null;
}
}