aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/database
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2024-04-03 21:17:52 -0700
committerAnton Tananaev <anton@traccar.org>2024-04-03 21:17:52 -0700
commitfc3a24148526b3d41ba40ed1f55cf40b54c6a255 (patch)
tree6b285bdf25112ada01c7afe0665213be20c27cae /src/main/java/org/traccar/database
parent5606f054244fc1ea2d5929152dd5c997d04f66fa (diff)
downloadtrackermap-server-fc3a24148526b3d41ba40ed1f55cf40b54c6a255.tar.gz
trackermap-server-fc3a24148526b3d41ba40ed1f55cf40b54c6a255.tar.bz2
trackermap-server-fc3a24148526b3d41ba40ed1f55cf40b54c6a255.zip
Handle outdated positions in buffer
Diffstat (limited to 'src/main/java/org/traccar/database')
-rw-r--r--src/main/java/org/traccar/database/BufferingManager.java26
1 files changed, 19 insertions, 7 deletions
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<Holder> {
- private static final Comparator<Position> 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());
}
}