diff options
author | Anton Tananaev <anton@traccar.org> | 2024-03-30 19:36:35 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2024-03-30 19:36:35 -0700 |
commit | 0f7ec1247cff1a68ffa57ade3f45b11f6602e262 (patch) | |
tree | 8cd0006e2b9d2313ef6ff4291188e30d40456701 /src/main/java/org/traccar/handler | |
parent | f84e2710e05660822633ec9e61cde44c03a42d7e (diff) | |
download | trackermap-server-0f7ec1247cff1a68ffa57ade3f45b11f6602e262.tar.gz trackermap-server-0f7ec1247cff1a68ffa57ade3f45b11f6602e262.tar.bz2 trackermap-server-0f7ec1247cff1a68ffa57ade3f45b11f6602e262.zip |
Make handlers nullable
Diffstat (limited to 'src/main/java/org/traccar/handler')
-rw-r--r-- | src/main/java/org/traccar/handler/CopyAttributesHandler.java | 18 | ||||
-rw-r--r-- | src/main/java/org/traccar/handler/FilterHandler.java | 4 | ||||
-rw-r--r-- | src/main/java/org/traccar/handler/TimeHandler.java | 22 |
3 files changed, 15 insertions, 29 deletions
diff --git a/src/main/java/org/traccar/handler/CopyAttributesHandler.java b/src/main/java/org/traccar/handler/CopyAttributesHandler.java index 9c31bf56e..f682c99c9 100644 --- a/src/main/java/org/traccar/handler/CopyAttributesHandler.java +++ b/src/main/java/org/traccar/handler/CopyAttributesHandler.java @@ -25,26 +25,22 @@ import org.traccar.session.cache.CacheManager; public class CopyAttributesHandler extends BasePositionHandler { - private final boolean enabled; private final CacheManager cacheManager; @Inject public CopyAttributesHandler(Config config, CacheManager cacheManager) { - enabled = config.getBoolean(Keys.PROCESSING_COPY_ATTRIBUTES_ENABLE); this.cacheManager = cacheManager; } @Override public void handlePosition(Position position, Callback callback) { - if (enabled) { - String attributesString = AttributeUtil.lookup( - cacheManager, Keys.PROCESSING_COPY_ATTRIBUTES, position.getDeviceId()); - Position last = cacheManager.getPosition(position.getDeviceId()); - if (last != null && attributesString != null) { - for (String attribute : attributesString.split("[ ,]")) { - if (last.hasAttribute(attribute) && !position.hasAttribute(attribute)) { - position.getAttributes().put(attribute, last.getAttributes().get(attribute)); - } + String attributesString = AttributeUtil.lookup( + cacheManager, Keys.PROCESSING_COPY_ATTRIBUTES, position.getDeviceId()); + Position last = cacheManager.getPosition(position.getDeviceId()); + if (last != null && attributesString != null) { + for (String attribute : attributesString.split("[ ,]")) { + if (last.hasAttribute(attribute) && !position.hasAttribute(attribute)) { + position.getAttributes().put(attribute, last.getAttributes().get(attribute)); } } } diff --git a/src/main/java/org/traccar/handler/FilterHandler.java b/src/main/java/org/traccar/handler/FilterHandler.java index 4cc6233d0..a9e6024c8 100644 --- a/src/main/java/org/traccar/handler/FilterHandler.java +++ b/src/main/java/org/traccar/handler/FilterHandler.java @@ -40,7 +40,6 @@ public class FilterHandler extends BasePositionHandler { private static final Logger LOGGER = LoggerFactory.getLogger(FilterHandler.class); - private final boolean enabled; private final boolean filterInvalid; private final boolean filterZero; private final boolean filterDuplicate; @@ -65,7 +64,6 @@ public class FilterHandler extends BasePositionHandler { @Inject public FilterHandler( Config config, CacheManager cacheManager, Storage storage, StatisticsManager statisticsManager) { - enabled = config.getBoolean(Keys.FILTER_ENABLE); filterInvalid = config.getBoolean(Keys.FILTER_INVALID); filterZero = config.getBoolean(Keys.FILTER_ZERO); filterDuplicate = config.getBoolean(Keys.FILTER_DUPLICATE); @@ -272,7 +270,7 @@ public class FilterHandler extends BasePositionHandler { @Override public void handlePosition(Position position, Callback callback) { - if (enabled && filter(position)) { + if (filter(position)) { callback.processed(null); } else { callback.processed(position); diff --git a/src/main/java/org/traccar/handler/TimeHandler.java b/src/main/java/org/traccar/handler/TimeHandler.java index 2e703c681..052ad41c3 100644 --- a/src/main/java/org/traccar/handler/TimeHandler.java +++ b/src/main/java/org/traccar/handler/TimeHandler.java @@ -26,18 +26,12 @@ import java.util.Set; public class TimeHandler extends BasePositionHandler { - private final boolean enabled; private final boolean useServerTime; private final Set<String> protocols; @Inject public TimeHandler(Config config) { - enabled = config.hasKey(Keys.TIME_OVERRIDE); - if (enabled) { - useServerTime = config.getString(Keys.TIME_OVERRIDE).equalsIgnoreCase("serverTime"); - } else { - useServerTime = false; - } + useServerTime = config.getString(Keys.TIME_OVERRIDE).equalsIgnoreCase("serverTime"); String protocolList = config.getString(Keys.TIME_PROTOCOLS); if (protocolList != null) { protocols = new HashSet<>(Arrays.asList(protocolList.split("[, ]"))); @@ -49,14 +43,12 @@ public class TimeHandler extends BasePositionHandler { @Override public void handlePosition(Position position, Callback callback) { - if (enabled) { - if (protocols == null || protocols.contains(position.getProtocol())) { - if (useServerTime) { - position.setDeviceTime(position.getServerTime()); - position.setFixTime(position.getServerTime()); - } else { - position.setFixTime(position.getDeviceTime()); - } + if (protocols == null || protocols.contains(position.getProtocol())) { + if (useServerTime) { + position.setDeviceTime(position.getServerTime()); + position.setFixTime(position.getServerTime()); + } else { + position.setFixTime(position.getDeviceTime()); } } callback.processed(position); |