@Override protected Collection<Event> analyzePosition(Position position) { Device device = Context.getIdentityManager().getDeviceById(position.getDeviceId()); if (device == null) { return null; } if (!Context.getDeviceManager().isLatestPosition(position) || !position.getValid()) { return null; } Collection<Event> result = null; double speed = position.getSpeed(); double oldSpeed = 0; Position lastPosition = Context.getDeviceManager().getLastPosition(position.getDeviceId()); if (lastPosition != null) { oldSpeed = lastPosition.getSpeed(); } try { if (speed > SPEED_THRESHOLD && oldSpeed <= SPEED_THRESHOLD) { result = new ArrayList<>(); result.add(new Event(Event.TYPE_DEVICE_MOVING, position.getDeviceId(), position.getId())); } else if (speed <= SPEED_THRESHOLD && oldSpeed > SPEED_THRESHOLD) { result = new ArrayList<>(); result.add(new Event(Event.TYPE_DEVICE_STOPPED, position.getDeviceId(), position.getId())); } if (result != null && !result.isEmpty()) { for (Event event : result) { if (!Context.getDataManager() .getLastEvents(position.getDeviceId(), event.getType(), suppressRepeated) .isEmpty()) { event = null; } } } } catch (SQLException error) { Log.warning(error); } return result; }