From 1b8e05ce34ff7c576c29e383601f74cb8c01d728 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 16 Jun 2016 11:23:41 +0500 Subject: Moved variables from parent to inheritor --- src/org/traccar/BaseEventHandler.java | 21 --------------------- src/org/traccar/events/GeofenceEventHandler.java | 13 +++++++------ src/org/traccar/events/MotionEventHandler.java | 14 ++++++++------ src/org/traccar/events/OverspeedEventHandler.java | 11 +++++++++-- 4 files changed, 24 insertions(+), 35 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/BaseEventHandler.java b/src/org/traccar/BaseEventHandler.java index 143c2dc2b..1ae9d2c6d 100644 --- a/src/org/traccar/BaseEventHandler.java +++ b/src/org/traccar/BaseEventHandler.java @@ -17,35 +17,14 @@ package org.traccar; import java.util.Collection; -import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Position; public abstract class BaseEventHandler extends BaseDataHandler { - private boolean isLastPosition = false; - - public boolean isLastPosition() { - return isLastPosition; - } - - private Device device; - - public Device getDevice() { - return device; - } - @Override protected Position handlePosition(Position position) { - device = Context.getDataManager().getDeviceById(position.getDeviceId()); - if (device != null) { - long lastPositionId = device.getPositionId(); - if (position.getId() == lastPositionId) { - isLastPosition = true; - } - } - Collection events = analyzePosition(position); if (events != null) { for (Event event : events) { diff --git a/src/org/traccar/events/GeofenceEventHandler.java b/src/org/traccar/events/GeofenceEventHandler.java index 7d24c4efe..e9a4a640f 100644 --- a/src/org/traccar/events/GeofenceEventHandler.java +++ b/src/org/traccar/events/GeofenceEventHandler.java @@ -25,6 +25,7 @@ import org.traccar.Context; import org.traccar.database.DataManager; import org.traccar.database.GeofenceManager; import org.traccar.helper.Log; +import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Position; @@ -42,24 +43,24 @@ public class GeofenceEventHandler extends BaseEventHandler { @Override protected Collection analyzePosition(Position position) { - if (!isLastPosition() || !position.getValid()) { + Device device = dataManager.getDeviceById(position.getDeviceId()); + if (device == null) { return null; } - - if (getDevice() == null) { + if (position.getId() != device.getPositionId() || !position.getValid()) { return null; } List currentGeofences = geofenceManager.getCurrentDeviceGeofences(position); List oldGeofences = new ArrayList(); - if (getDevice().getGeofenceIds() != null) { - oldGeofences.addAll(getDevice().getGeofenceIds()); + if (device.getGeofenceIds() != null) { + oldGeofences.addAll(device.getGeofenceIds()); } List newGeofences = new ArrayList(currentGeofences); newGeofences.removeAll(oldGeofences); oldGeofences.removeAll(currentGeofences); - getDevice().setGeofenceIds(currentGeofences); + device.setGeofenceIds(currentGeofences); Collection events = new ArrayList<>(); try { diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java index c05bd4843..d10513d26 100644 --- a/src/org/traccar/events/MotionEventHandler.java +++ b/src/org/traccar/events/MotionEventHandler.java @@ -37,17 +37,19 @@ public class MotionEventHandler extends BaseEventHandler { @Override protected Collection analyzePosition(Position position) { - Collection result = null; - if (!isLastPosition()) { + + Device device = Context.getDataManager().getDeviceById(position.getDeviceId()); + if (device == null) { + return null; + } + if (position.getId() != device.getPositionId() || !position.getValid()) { return null; } + Collection result = null; double speed = position.getSpeed(); boolean valid = position.getValid(); - if (getDevice() == null) { - return null; - } - String motion = getDevice().getMotion(); + String motion = device.getMotion(); if (motion == null) { motion = Device.STATUS_STOPPED; } diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java index f4676b995..e14d4bcea 100644 --- a/src/org/traccar/events/OverspeedEventHandler.java +++ b/src/org/traccar/events/OverspeedEventHandler.java @@ -21,6 +21,7 @@ import java.util.Collection; import org.traccar.BaseEventHandler; import org.traccar.Context; +import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Position; import org.traccar.helper.Log; @@ -38,10 +39,16 @@ public class OverspeedEventHandler extends BaseEventHandler { @Override protected Collection analyzePosition(Position position) { - Collection events = new ArrayList<>(); - if (!isLastPosition()) { + + Device device = Context.getDataManager().getDeviceById(position.getDeviceId()); + if (device == null) { + return null; + } + if (position.getId() != device.getPositionId() || !position.getValid()) { return null; } + + Collection events = new ArrayList<>(); double speed = position.getSpeed(); boolean valid = position.getValid(); -- cgit v1.2.3