From 6a401344bf926063138e56b884e4a857a8b4d68f Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Thu, 9 Dec 2021 10:07:04 +0100 Subject: [PATCH] Remove flex stops when flex is disabled --- .../RepairStopTimesForEachTripOperation.java | 18 ++++++++++++------ .../gtfs/mapping/TripMapper.java | 4 ---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/opentripplanner/gtfs/RepairStopTimesForEachTripOperation.java b/src/main/java/org/opentripplanner/gtfs/RepairStopTimesForEachTripOperation.java index d6ff1351f78..9803e051d36 100644 --- a/src/main/java/org/opentripplanner/gtfs/RepairStopTimesForEachTripOperation.java +++ b/src/main/java/org/opentripplanner/gtfs/RepairStopTimesForEachTripOperation.java @@ -2,6 +2,9 @@ import gnu.trove.list.TIntList; import gnu.trove.list.array.TIntArrayList; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; import org.opentripplanner.common.geometry.SphericalDistanceLibrary; import org.opentripplanner.ext.flex.trip.FlexTrip; import org.opentripplanner.graph_builder.DataImportIssue; @@ -12,20 +15,17 @@ import org.opentripplanner.graph_builder.issues.NegativeDwellTime; import org.opentripplanner.graph_builder.issues.NegativeHopTime; import org.opentripplanner.graph_builder.issues.RepeatedStops; -import org.opentripplanner.model.StopLocation; +import org.opentripplanner.model.Stop; import org.opentripplanner.model.StopTime; import org.opentripplanner.model.Trip; import org.opentripplanner.model.TripStopTimes; +import org.opentripplanner.util.OTPFeature; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - /** * This class is responsible for cleaning stop times, removing duplicates, correcting bad data - * and so on. This do only apply to GTFS imports. + * and so on. This only applies to GTFS imports. */ public class RepairStopTimesForEachTripOperation { private static final Logger LOG = LoggerFactory.getLogger(RepairStopTimesForEachTripOperation.class); @@ -53,6 +53,12 @@ public void run() { /* Fetch the stop times for this trip. Copy the list since it's immutable. */ List stopTimes = new ArrayList<>(stopTimesByTrip.get(trip)); + // if we don't have flex routing enabled then remove all the flex locations and location + // groups + if(OTPFeature.FlexRouting.isOff()) { + stopTimes.removeIf(st -> !(st.getStop() instanceof Stop)); + } + /* Stop times frequently contain duplicate, missing, or incorrect entries. Repair them. */ TIntList removedStopSequences = removeRepeatedStops(stopTimes); if (!removedStopSequences.isEmpty()) { diff --git a/src/main/java/org/opentripplanner/gtfs/mapping/TripMapper.java b/src/main/java/org/opentripplanner/gtfs/mapping/TripMapper.java index fe25a98235c..5709e758fb5 100644 --- a/src/main/java/org/opentripplanner/gtfs/mapping/TripMapper.java +++ b/src/main/java/org/opentripplanner/gtfs/mapping/TripMapper.java @@ -31,10 +31,6 @@ Trip map(org.onebusaway.gtfs.model.Trip orginal) { return orginal == null ? null : mappedTrips.computeIfAbsent(orginal, this::doMap); } - Collection mappedTrips() { - return mappedTrips.values(); - } - private Trip doMap(org.onebusaway.gtfs.model.Trip rhs) { Trip lhs = new Trip(AgencyAndIdMapper.mapAgencyAndId(rhs.getId()));