From 4f19d170b8c6fd5118c68f14e99080cd56493d93 Mon Sep 17 00:00:00 2001 From: Lukas Connolly Date: Thu, 13 Jun 2024 22:46:17 +0200 Subject: [PATCH] FIX: NAV-100 - Fix edge case where two legs have same departure times because one leg has 0s travel time. --- src/main/java/ch/naviqore/raptor/Connection.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/naviqore/raptor/Connection.java b/src/main/java/ch/naviqore/raptor/Connection.java index f64ecd81..fbe0365e 100644 --- a/src/main/java/ch/naviqore/raptor/Connection.java +++ b/src/main/java/ch/naviqore/raptor/Connection.java @@ -115,7 +115,16 @@ public record Leg(String routeId, @Nullable String tripId, String fromStopId, St @Override public int compareTo(@NotNull Connection.Leg other) { - return Integer.compare(this.departureTime, other.departureTime); + // sort legs first by departure time than by arrival time since there some legs that actually have the same + // departure and arrival time (really short distance local service) and therefore the following leg may + // have the same departure time but a later arrival time + int comparison = Integer.compare(this.departureTime, other.departureTime); + if (comparison != 0) { + return comparison; + } else { + return Integer.compare(this.arrivalTime, other.arrivalTime); + } + } }