From fc3a24148526b3d41ba40ed1f55cf40b54c6a255 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 3 Apr 2024 21:17:52 -0700 Subject: Handle outdated positions in buffer --- .../org/traccar/database/BufferingManager.java | 26 ++++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/main/java/org/traccar/database') diff --git a/src/main/java/org/traccar/database/BufferingManager.java b/src/main/java/org/traccar/database/BufferingManager.java index 3e3cf587a..4d288c8d0 100644 --- a/src/main/java/org/traccar/database/BufferingManager.java +++ b/src/main/java/org/traccar/database/BufferingManager.java @@ -25,7 +25,7 @@ import org.traccar.config.Config; import org.traccar.config.Keys; import org.traccar.model.Position; -import java.util.Comparator; +import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.TreeSet; @@ -41,11 +41,6 @@ public class BufferingManager { private static final class Holder implements Comparable { - private static final Comparator COMPARATOR = Comparator - .comparing(Position::getFixTime) - .thenComparing(Position::getDeviceTime) - .thenComparing(Position::getServerTime); - private final ChannelHandlerContext context; private final Position position; private Timeout timeout; @@ -55,9 +50,26 @@ public class BufferingManager { this.position = position; } + private int compareTime(Date left, Date right) { + if (left != null && right != null) { + return left.compareTo(right); + } + return 0; + } + @Override public int compareTo(Holder other) { - return COMPARATOR.compare(position, other.position); + int fixTimeResult = compareTime(position.getFixTime(), other.position.getFixTime()); + if (fixTimeResult != 0) { + return fixTimeResult; + } + + int deviceTimeResult = compareTime(position.getDeviceTime(), other.position.getDeviceTime()); + if (deviceTimeResult != 0) { + return deviceTimeResult; + } + + return position.getServerTime().compareTo(other.position.getServerTime()); } } -- cgit v1.2.3