From b399f9e9e5813531f1cc621eda999b2d1816f50d Mon Sep 17 00:00:00 2001 From: Hannes Junnila Date: Mon, 12 Sep 2022 18:38:05 +0300 Subject: [PATCH 1/7] Extract AbstractRaptorTransfer to improve performance --- .../raptoradapter/transit/AccessEgress.java | 36 ++++--------------- .../transit/request/TransferWithDuration.java | 25 ++----------- .../api/transit/AbstractRaptorTransfer.java | 34 ++++++++++++++++++ .../raptor/util/ReversedRaptorTransfer.java | 21 ++--------- 4 files changed, 47 insertions(+), 69 deletions(-) create mode 100644 src/main/java/org/opentripplanner/transit/raptor/api/transit/AbstractRaptorTransfer.java diff --git a/src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/AccessEgress.java b/src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/AccessEgress.java index cb7783262ab..15e51388329 100644 --- a/src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/AccessEgress.java +++ b/src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/AccessEgress.java @@ -2,19 +2,10 @@ import org.opentripplanner.routing.algorithm.raptoradapter.transit.cost.RaptorCostConverter; import org.opentripplanner.routing.core.State; -import org.opentripplanner.transit.raptor.api.transit.RaptorTransfer; +import org.opentripplanner.transit.raptor.api.transit.AbstractRaptorTransfer; import org.opentripplanner.util.lang.ToStringBuilder; -public class AccessEgress implements RaptorTransfer { - - /** - * "To stop" in the case of access, "from stop" in the case of egress. - */ - private final int toFromStop; - - private final int durationInSeconds; - - private final int generalizedCost; +public class AccessEgress extends AbstractRaptorTransfer { /** * This should be the last state both in the case of access and egress. @@ -22,27 +13,14 @@ public class AccessEgress implements RaptorTransfer { private final State lastState; public AccessEgress(int toFromStop, State lastState) { - this.toFromStop = toFromStop; - this.durationInSeconds = (int) lastState.getElapsedTimeSeconds(); - this.generalizedCost = RaptorCostConverter.toRaptorCost(lastState.getWeight()); + super( + toFromStop, + (int) lastState.getElapsedTimeSeconds(), + RaptorCostConverter.toRaptorCost(lastState.getWeight()) + ); this.lastState = lastState; } - @Override - public int stop() { - return toFromStop; - } - - @Override - public int generalizedCost() { - return generalizedCost; - } - - @Override - public int durationInSeconds() { - return durationInSeconds; - } - @Override public boolean hasOpeningHours() { return false; diff --git a/src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/request/TransferWithDuration.java b/src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/request/TransferWithDuration.java index 00103462560..a53152eafa6 100644 --- a/src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/request/TransferWithDuration.java +++ b/src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/request/TransferWithDuration.java @@ -1,40 +1,21 @@ package org.opentripplanner.routing.algorithm.raptoradapter.transit.request; import org.opentripplanner.routing.algorithm.raptoradapter.transit.Transfer; -import org.opentripplanner.transit.raptor.api.transit.RaptorTransfer; +import org.opentripplanner.transit.raptor.api.transit.AbstractRaptorTransfer; -public class TransferWithDuration implements RaptorTransfer { - - private final int durationSeconds; - private final int cost; +public class TransferWithDuration extends AbstractRaptorTransfer { private final Transfer transfer; public TransferWithDuration(Transfer transfer, int durationSeconds, int cost) { + super(transfer.getToStop(), durationSeconds, cost); this.transfer = transfer; - this.durationSeconds = durationSeconds; - this.cost = cost; } public Transfer transfer() { return transfer; } - @Override - public int stop() { - return transfer.getToStop(); - } - - @Override - public int generalizedCost() { - return cost; - } - - @Override - public int durationInSeconds() { - return this.durationSeconds; - } - @Override public boolean hasOpeningHours() { return false; diff --git a/src/main/java/org/opentripplanner/transit/raptor/api/transit/AbstractRaptorTransfer.java b/src/main/java/org/opentripplanner/transit/raptor/api/transit/AbstractRaptorTransfer.java new file mode 100644 index 00000000000..23548fc4e30 --- /dev/null +++ b/src/main/java/org/opentripplanner/transit/raptor/api/transit/AbstractRaptorTransfer.java @@ -0,0 +1,34 @@ +package org.opentripplanner.transit.raptor.api.transit; + +/** + * This class exists purely due to performance reasons. By declaring the getters as final, we avoid + * the itable stub to decide which RaptorTransfer implementation to use when fetching performance + * critical fields from an transfer. + */ +public abstract class AbstractRaptorTransfer implements RaptorTransfer { + + private final int stop; + private final int durationInSeconds; + private final int generalizedCost; + + protected AbstractRaptorTransfer(int stop, int durationInSeconds, int generalizedCost) { + this.stop = stop; + this.durationInSeconds = durationInSeconds; + this.generalizedCost = generalizedCost; + } + + @Override + public final int stop() { + return stop; + } + + @Override + public final int durationInSeconds() { + return durationInSeconds; + } + + @Override + public final int generalizedCost() { + return generalizedCost; + } +} diff --git a/src/main/java/org/opentripplanner/transit/raptor/util/ReversedRaptorTransfer.java b/src/main/java/org/opentripplanner/transit/raptor/util/ReversedRaptorTransfer.java index c970406daba..3dc1e906a7d 100644 --- a/src/main/java/org/opentripplanner/transit/raptor/util/ReversedRaptorTransfer.java +++ b/src/main/java/org/opentripplanner/transit/raptor/util/ReversedRaptorTransfer.java @@ -1,32 +1,17 @@ package org.opentripplanner.transit.raptor.util; +import org.opentripplanner.transit.raptor.api.transit.AbstractRaptorTransfer; import org.opentripplanner.transit.raptor.api.transit.RaptorTransfer; -public class ReversedRaptorTransfer implements RaptorTransfer { +public class ReversedRaptorTransfer extends AbstractRaptorTransfer { - private final int stopIndex; private final RaptorTransfer transfer; public ReversedRaptorTransfer(int fromStopIndex, RaptorTransfer transfer) { - this.stopIndex = fromStopIndex; + super(fromStopIndex, transfer.durationInSeconds(), transfer.generalizedCost()); this.transfer = transfer; } - @Override - public int stop() { - return stopIndex; - } - - @Override - public int generalizedCost() { - return transfer.generalizedCost(); - } - - @Override - public int durationInSeconds() { - return transfer.durationInSeconds(); - } - @Override public int earliestDepartureTime(int requestedDepartureTime) { return transfer.earliestDepartureTime(requestedDepartureTime); From 62d092ac61548c7d771661dd372d964e30f91c09 Mon Sep 17 00:00:00 2001 From: Hannes Junnila Date: Mon, 5 Sep 2022 15:43:08 +0300 Subject: [PATCH 2/7] refactor: Extract LegMode --- .../ext/flex/FlexIntegrationTest.java | 11 +- .../ext/fares/impl/SFBayFareServiceImpl.java | 6 +- .../ext/flex/FlexibleTransitLeg.java | 6 +- .../ext/flex/edgetype/FlexTripEdge.java | 4 +- .../ext/transmodelapi/model/EnumTypes.java | 40 ++-- .../ext/transmodelapi/model/plan/LegType.java | 4 +- .../api/mapping/LegMapper.java | 2 +- .../api/mapping/ModeMapper.java | 63 +++++ .../api/mapping/RouteMapper.java | 4 +- .../api/mapping/TraverseModeMapper.java | 111 --------- .../api/model/ApiRouterInfo.java | 4 +- .../module/PruneNoThruIslands.java | 3 +- .../org/opentripplanner/model/plan/Leg.java | 3 +- .../opentripplanner/model/plan/LegMode.java | 70 ++++++ .../model/plan/ScheduledTransitLeg.java | 5 +- .../opentripplanner/model/plan/StreetLeg.java | 7 +- .../model/plan/StreetLegBuilder.java | 7 +- ...oveParkAndRideWithMostlyWalkingFilter.java | 5 +- .../mapping/GraphPathToItineraryMapper.java | 14 +- .../mapping/RaptorPathToItineraryMapper.java | 11 +- .../routing/api/request/RouteRequest.java | 5 - .../routing/core/TraverseMode.java | 64 +---- .../routing/core/TraverseModeSet.java | 225 +----------------- .../routing/impl/GraphPathFinder.java | 4 - .../util/TravelOptionsMaker.java | 39 ++- .../visualizer/GraphVisualizer.java | 51 ++-- .../opentripplanner/visualizer/ShowGraph.java | 11 +- .../java/org/opentripplanner/GtfsTest.java | 23 +- .../module/osm/OpenStreetMapModuleTest.java | 2 +- .../module/osm/TestIntermediatePlaces.java | 39 +-- .../module/osm/TriangleInequalityTest.java | 64 +++-- .../opentripplanner/mmri/PreferencesTest.java | 3 +- .../model/plan/ItineraryTest.java | 8 +- .../model/plan/TestItineraryBuilder.java | 32 +-- .../routing/TestHalfEdges.java | 4 +- .../routing/algorithm/GraphRoutingTest.java | 38 --- .../routing/core/TraverseModeSetTest.java | 55 +---- .../StreetTraversalPermissionTest.java | 15 +- .../loader/GeometryProcessorTest.java | 1 - .../routing/street/BarrierRoutingTest.java | 10 +- .../routing/street/BicycleRoutingTest.java | 3 +- .../routing/street/CarRoutingTest.java | 3 +- .../street/SplitEdgeTurnRestrictionsTest.java | 3 +- .../speed_test/model/testcase/CsvFileIO.java | 4 +- .../model/testcase/ItineraryResultMapper.java | 4 +- .../speed_test/model/testcase/Result.java | 6 +- 46 files changed, 392 insertions(+), 704 deletions(-) create mode 100644 src/main/java/org/opentripplanner/api/mapping/ModeMapper.java delete mode 100644 src/main/java/org/opentripplanner/api/mapping/TraverseModeMapper.java create mode 100644 src/main/java/org/opentripplanner/model/plan/LegMode.java diff --git a/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTest.java b/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTest.java index eb4d594332c..6f909c1cd7c 100644 --- a/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTest.java +++ b/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTest.java @@ -5,9 +5,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.opentripplanner.graph_builder.DataImportIssueStore.noopIssueStore; import static org.opentripplanner.graph_builder.module.FakeGraph.getFileForResource; +import static org.opentripplanner.model.plan.LegMode.BUS; +import static org.opentripplanner.model.plan.LegMode.WALK; import static org.opentripplanner.routing.api.request.StreetMode.FLEXIBLE; -import static org.opentripplanner.routing.core.TraverseMode.BUS; -import static org.opentripplanner.routing.core.TraverseMode.WALK; import java.io.File; import java.net.URISyntaxException; @@ -31,7 +31,6 @@ import org.opentripplanner.model.plan.Itinerary; import org.opentripplanner.routing.RoutingService; import org.opentripplanner.routing.api.request.RouteRequest; -import org.opentripplanner.routing.core.TraverseMode; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.transit.service.TransitModel; import org.opentripplanner.util.OTPFeature; @@ -82,14 +81,14 @@ void shouldReturnARouteTransferringFromBusToFlex() { assertEquals(4, itin.getLegs().size()); var walkToBus = itin.getLegs().get(0); - assertEquals(TraverseMode.WALK, walkToBus.getMode()); + assertEquals(WALK, walkToBus.getMode()); var bus = itin.getLegs().get(1); assertEquals(BUS, bus.getMode()); assertEquals("30", bus.getRoute().getShortName()); var transfer = itin.getLegs().get(2); - assertEquals(TraverseMode.WALK, transfer.getMode()); + assertEquals(WALK, transfer.getMode()); var flex = itin.getLegs().get(3); assertEquals(BUS, flex.getMode()); @@ -146,7 +145,7 @@ void flexDirect() { assertEquals(3173, itin.getGeneralizedCost()); var walkToFlex = itin.getLegs().get(0); - assertEquals(TraverseMode.WALK, walkToFlex.getMode()); + assertEquals(WALK, walkToFlex.getMode()); var flex = itin.getLegs().get(1); assertEquals(BUS, flex.getMode()); diff --git a/src/ext/java/org/opentripplanner/ext/fares/impl/SFBayFareServiceImpl.java b/src/ext/java/org/opentripplanner/ext/fares/impl/SFBayFareServiceImpl.java index 803b9c75eb2..caf105d912c 100644 --- a/src/ext/java/org/opentripplanner/ext/fares/impl/SFBayFareServiceImpl.java +++ b/src/ext/java/org/opentripplanner/ext/fares/impl/SFBayFareServiceImpl.java @@ -9,16 +9,14 @@ import java.util.Set; import org.opentripplanner.ext.fares.model.FareRuleSet; import org.opentripplanner.model.plan.Leg; +import org.opentripplanner.model.plan.LegMode; import org.opentripplanner.routing.core.FareType; import org.opentripplanner.routing.core.ItineraryFares; -import org.opentripplanner.routing.core.TraverseMode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SFBayFareServiceImpl extends DefaultFareServiceImpl { - private static final long serialVersionUID = 20120229L; - @SuppressWarnings("unused") private static final Logger LOG = LoggerFactory.getLogger(SFBayFareServiceImpl.class); @@ -65,7 +63,7 @@ protected float getLowestCost( bartBlock = null; } if (agencyId.equals("SFMTA")) { - if (ride.getMode().equals(TraverseMode.CABLE_CAR)) { + if (ride.getMode().equals(LegMode.CABLE_CAR)) { // no transfers issued or accepted cost += CABLE_CAR_FARE; } else if ( diff --git a/src/ext/java/org/opentripplanner/ext/flex/FlexibleTransitLeg.java b/src/ext/java/org/opentripplanner/ext/flex/FlexibleTransitLeg.java index 50ac96b898e..cc91c68bbd3 100644 --- a/src/ext/java/org/opentripplanner/ext/flex/FlexibleTransitLeg.java +++ b/src/ext/java/org/opentripplanner/ext/flex/FlexibleTransitLeg.java @@ -11,10 +11,10 @@ import org.opentripplanner.model.BookingInfo; import org.opentripplanner.model.PickDrop; import org.opentripplanner.model.plan.Leg; +import org.opentripplanner.model.plan.LegMode; import org.opentripplanner.model.plan.Place; import org.opentripplanner.model.plan.StopArrival; import org.opentripplanner.routing.alertpatch.TransitAlert; -import org.opentripplanner.routing.core.TraverseMode; import org.opentripplanner.transit.model.basic.WheelchairAccessibility; import org.opentripplanner.transit.model.framework.AbstractTransitEntity; import org.opentripplanner.transit.model.network.Route; @@ -85,8 +85,8 @@ public WheelchairAccessibility getTripWheelchairAccessibility() { } @Override - public TraverseMode getMode() { - return TraverseMode.fromTransitMode(getTrip().getMode()); + public LegMode getMode() { + return LegMode.fromTransitMode(getTrip().getMode()); } @Override diff --git a/src/ext/java/org/opentripplanner/ext/flex/edgetype/FlexTripEdge.java b/src/ext/java/org/opentripplanner/ext/flex/edgetype/FlexTripEdge.java index 0a5e9e73345..62c005026a4 100644 --- a/src/ext/java/org/opentripplanner/ext/flex/edgetype/FlexTripEdge.java +++ b/src/ext/java/org/opentripplanner/ext/flex/edgetype/FlexTripEdge.java @@ -18,8 +18,6 @@ public class FlexTripEdge extends Edge { private static final Logger LOG = LoggerFactory.getLogger(FlexTripEdge.class); - - private static final long serialVersionUID = 1L; private final FlexTrip trip; public StopLocation s1; public StopLocation s2; @@ -64,7 +62,7 @@ public State traverse(State s0) { return null; } StateEditor editor = s0.edit(this); - editor.setBackMode(TraverseMode.BUS); + editor.setBackMode(TraverseMode.FLEX); // TODO: decide good value editor.incrementWeight(10 * 60); int timeInSeconds = getTimeInSeconds(); diff --git a/src/ext/java/org/opentripplanner/ext/transmodelapi/model/EnumTypes.java b/src/ext/java/org/opentripplanner/ext/transmodelapi/model/EnumTypes.java index 998b5bef3da..d2ee70a6d66 100644 --- a/src/ext/java/org/opentripplanner/ext/transmodelapi/model/EnumTypes.java +++ b/src/ext/java/org/opentripplanner/ext/transmodelapi/model/EnumTypes.java @@ -5,6 +5,7 @@ import java.util.function.Function; import org.opentripplanner.model.BookingMethod; import org.opentripplanner.model.plan.AbsoluteDirection; +import org.opentripplanner.model.plan.LegMode; import org.opentripplanner.model.plan.RelativeDirection; import org.opentripplanner.model.plan.VertexType; import org.opentripplanner.model.transfer.TransferPriority; @@ -14,7 +15,6 @@ import org.opentripplanner.routing.api.response.InputField; import org.opentripplanner.routing.api.response.RoutingErrorCode; import org.opentripplanner.routing.core.BicycleOptimizeType; -import org.opentripplanner.routing.core.TraverseMode; import org.opentripplanner.routing.stoptimes.ArrivalDeparture; import org.opentripplanner.transit.model.basic.TransitMode; import org.opentripplanner.transit.model.basic.WheelchairAccessibility; @@ -254,29 +254,25 @@ public class EnumTypes { ) .build(); - public static GraphQLEnumType MODE = GraphQLEnumType + public static GraphQLEnumType LEG_MODE = GraphQLEnumType .newEnum() .name("Mode") - .value("air", TraverseMode.AIRPLANE) - .value("bicycle", TraverseMode.BICYCLE) - .value("bus", TraverseMode.BUS) - .value("cableway", TraverseMode.CABLE_CAR) - .value("water", TraverseMode.FERRY) - .value("funicular", TraverseMode.FUNICULAR) - .value("lift", TraverseMode.GONDOLA) - .value("rail", TraverseMode.RAIL) - .value("metro", TraverseMode.SUBWAY) - .value("tram", TraverseMode.TRAM) - .value("coach", TraverseMode.BUS) - .description("NOT IMPLEMENTED") - .value("transit", TraverseMode.TRANSIT, "Any for of public transportation") - .value("foot", TraverseMode.WALK) - .value("car", TraverseMode.CAR) - .value("scooter", TraverseMode.SCOOTER) - // TODO OTP2 - Car park no added - // .value("car_park", TraverseMode.CAR_PARK, "Combine with foot and transit for park and ride.") - // .value("car_dropoff", TraverseMode.CAR_DROPOFF, "Combine with foot and transit for kiss and ride.") - // .value("car_pickup", TraverseMode.CAR_PICKUP, "Combine with foot and transit for ride and kiss.") + .value("air", LegMode.AIRPLANE) + .value("bicycle", LegMode.BICYCLE) + .value("bus", LegMode.BUS) + .value("cableway", LegMode.CABLE_CAR) + .value("water", LegMode.FERRY) + .value("funicular", LegMode.FUNICULAR) + .value("lift", LegMode.GONDOLA) + .value("rail", LegMode.RAIL) + .value("metro", LegMode.SUBWAY) + .value("tram", LegMode.TRAM) + .value("trolleybus", LegMode.TROLLEYBUS) + .value("monorail", LegMode.MONORAIL) + .value("coach", LegMode.COACH) + .value("foot", LegMode.WALK) + .value("car", LegMode.CAR) + .value("scooter", LegMode.SCOOTER) .build(); public static GraphQLEnumType TRANSPORT_MODE = GraphQLEnumType diff --git a/src/ext/java/org/opentripplanner/ext/transmodelapi/model/plan/LegType.java b/src/ext/java/org/opentripplanner/ext/transmodelapi/model/plan/LegType.java index 7a6280fd0d7..2b2795220cb 100644 --- a/src/ext/java/org/opentripplanner/ext/transmodelapi/model/plan/LegType.java +++ b/src/ext/java/org/opentripplanner/ext/transmodelapi/model/plan/LegType.java @@ -1,7 +1,7 @@ package org.opentripplanner.ext.transmodelapi.model.plan; import static org.opentripplanner.ext.transmodelapi.model.EnumTypes.ALTERNATIVE_LEGS_FILTER; -import static org.opentripplanner.ext.transmodelapi.model.EnumTypes.MODE; +import static org.opentripplanner.ext.transmodelapi.model.EnumTypes.LEG_MODE; import graphql.Scalars; import graphql.scalars.ExtendedScalars; @@ -119,7 +119,7 @@ public static GraphQLObjectType create( .description( "The mode of transport or access (e.g., foot) used when traversing this leg." ) - .type(new GraphQLNonNull(MODE)) + .type(new GraphQLNonNull(LEG_MODE)) .dataFetcher(env -> leg(env).getMode()) .build() ) diff --git a/src/main/java/org/opentripplanner/api/mapping/LegMapper.java b/src/main/java/org/opentripplanner/api/mapping/LegMapper.java index 5c04b5893d4..cab6ed727ae 100644 --- a/src/main/java/org/opentripplanner/api/mapping/LegMapper.java +++ b/src/main/java/org/opentripplanner/api/mapping/LegMapper.java @@ -89,7 +89,7 @@ public ApiLeg mapLeg( api.distance = round3Decimals(domain.getDistanceMeters()); api.generalizedCost = domain.getGeneralizedCost(); api.pathway = domain.getPathwayId() != null; - api.mode = TraverseModeMapper.mapToApi(domain.getMode()); + api.mode = ModeMapper.mapToApi(domain.getMode()); api.agencyTimeZoneOffset = domain.getAgencyTimeZoneOffset(); api.transitLeg = domain.isTransitLeg(); diff --git a/src/main/java/org/opentripplanner/api/mapping/ModeMapper.java b/src/main/java/org/opentripplanner/api/mapping/ModeMapper.java new file mode 100644 index 00000000000..41cf9daa66f --- /dev/null +++ b/src/main/java/org/opentripplanner/api/mapping/ModeMapper.java @@ -0,0 +1,63 @@ +package org.opentripplanner.api.mapping; + +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import org.opentripplanner.model.plan.LegMode; +import org.opentripplanner.transit.model.basic.TransitMode; + +public class ModeMapper { + + public static String mapToApi(LegMode domain) { + if (domain == null) { + return null; + } + + return switch (domain) { + case AIRPLANE -> "AIRPLANE"; + case BICYCLE -> "BICYCLE"; + case BUS -> "BUS"; + case CAR -> "CAR"; + case CABLE_CAR -> "CABLE_CAR"; + case COACH -> "COACH"; + case FERRY -> "FERRY"; + case FUNICULAR -> "FUNICULAR"; + case GONDOLA -> "GONDOLA"; + case RAIL -> "RAIL"; + case SUBWAY -> "SUBWAY"; + case TRAM -> "TRAM"; + case WALK -> "WALK"; + case SCOOTER -> "SCOOTER"; + case TROLLEYBUS -> "TROLLEYBUS"; + case MONORAIL -> "MONORAIL"; + }; + } + + public static List mapToApi(Set domain) { + if (domain == null) { + return null; + } + return domain.stream().map(ModeMapper::mapToApi).collect(Collectors.toList()); + } + + public static String mapToApi(TransitMode domain) { + if (domain == null) { + return null; + } + + return switch (domain) { + case AIRPLANE -> "AIRPLANE"; + case BUS -> "BUS"; + case CABLE_CAR -> "CABLE_CAR"; + case COACH -> "COACH"; + case FERRY -> "FERRY"; + case FUNICULAR -> "FUNICULAR"; + case GONDOLA -> "GONDOLA"; + case RAIL -> "RAIL"; + case SUBWAY -> "SUBWAY"; + case TRAM -> "TRAM"; + case TROLLEYBUS -> "TROLLEYBUS"; + case MONORAIL -> "MONORAIL"; + }; + } +} diff --git a/src/main/java/org/opentripplanner/api/mapping/RouteMapper.java b/src/main/java/org/opentripplanner/api/mapping/RouteMapper.java index d0f5133d0b1..f64a350092c 100644 --- a/src/main/java/org/opentripplanner/api/mapping/RouteMapper.java +++ b/src/main/java/org/opentripplanner/api/mapping/RouteMapper.java @@ -27,7 +27,7 @@ public static ApiRoute mapToApi(Route domain) { api.agency = AgencyMapper.mapToApi(domain.getAgency()); api.shortName = domain.getShortName(); api.longName = stringMapper.mapToApi(domain.getLongName()); - api.mode = TraverseModeMapper.mapToApi(domain.getMode()); + api.mode = ModeMapper.mapToApi(domain.getMode()); api.type = domain.getGtfsType() != null ? domain.getGtfsType() @@ -63,7 +63,7 @@ public static ApiRouteShort mapToApiShort(Route domain) { api.id = FeedScopedIdMapper.mapToApi(domain.getId()); api.shortName = domain.getShortName(); api.longName = stringMapper.mapToApi(domain.getLongName()); - api.mode = TraverseModeMapper.mapToApi(domain.getMode()); + api.mode = ModeMapper.mapToApi(domain.getMode()); api.color = domain.getColor(); api.agencyName = domain.getAgency().getName(); diff --git a/src/main/java/org/opentripplanner/api/mapping/TraverseModeMapper.java b/src/main/java/org/opentripplanner/api/mapping/TraverseModeMapper.java deleted file mode 100644 index 16eed9e53a1..00000000000 --- a/src/main/java/org/opentripplanner/api/mapping/TraverseModeMapper.java +++ /dev/null @@ -1,111 +0,0 @@ -package org.opentripplanner.api.mapping; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; -import org.opentripplanner.routing.core.TraverseMode; -import org.opentripplanner.transit.model.basic.TransitMode; - -public class TraverseModeMapper { - - private static final Map toDomain; - - static { - Map map = new HashMap<>(); - for (TraverseMode it : TraverseMode.values()) { - map.put(mapToApi(it), it); - } - toDomain = Map.copyOf(map); - } - - public static TraverseMode mapToDomain(String api) { - if (api == null) { - return null; - } - return toDomain.get(api); - } - - public static String mapToApi(TraverseMode domain) { - if (domain == null) { - return null; - } - - switch (domain) { - case AIRPLANE: - return "AIRPLANE"; - case BICYCLE: - return "BICYCLE"; - case BUS: - return "BUS"; - case CAR: - return "CAR"; - case CABLE_CAR: - return "CABLE_CAR"; - case FERRY: - return "FERRY"; - case FUNICULAR: - return "FUNICULAR"; - case GONDOLA: - return "GONDOLA"; - case RAIL: - return "RAIL"; - case SUBWAY: - return "SUBWAY"; - case TRAM: - return "TRAM"; - case TRANSIT: - return "TRANSIT"; - case WALK: - return "WALK"; - case SCOOTER: - return "SCOOTER"; - case TROLLEYBUS: - return "TROLLEYBUS"; - case MONORAIL: - return "MONORAIL"; - } - throw new IllegalArgumentException("Traverse mode not mapped: " + domain); - } - - public static List mapToApi(Set domain) { - if (domain == null) { - return null; - } - return domain.stream().map(TraverseModeMapper::mapToApi).collect(Collectors.toList()); - } - - public static String mapToApi(TransitMode domain) { - if (domain == null) { - return null; - } - - switch (domain) { - case AIRPLANE: - return "AIRPLANE"; - case COACH: - case BUS: - return "BUS"; - case CABLE_CAR: - return "CABLE_CAR"; - case FERRY: - return "FERRY"; - case FUNICULAR: - return "FUNICULAR"; - case GONDOLA: - return "GONDOLA"; - case RAIL: - return "RAIL"; - case SUBWAY: - return "SUBWAY"; - case TRAM: - return "TRAM"; - case TROLLEYBUS: - return "TROLLEYBUS"; - case MONORAIL: - return "MONORAIL"; - } - throw new IllegalArgumentException("Traverse mode not mapped: " + domain); - } -} diff --git a/src/main/java/org/opentripplanner/api/model/ApiRouterInfo.java b/src/main/java/org/opentripplanner/api/model/ApiRouterInfo.java index cacd1af4702..f77969e23bd 100644 --- a/src/main/java/org/opentripplanner/api/model/ApiRouterInfo.java +++ b/src/main/java/org/opentripplanner/api/model/ApiRouterInfo.java @@ -4,7 +4,7 @@ import java.util.List; import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.Geometry; -import org.opentripplanner.api.mapping.TraverseModeMapper; +import org.opentripplanner.api.mapping.ModeMapper; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.routing.vehicle_parking.VehicleParkingService; import org.opentripplanner.routing.vehicle_rental.VehicleRentalStationService; @@ -42,7 +42,7 @@ public ApiRouterInfo(String routerId, Graph graph, TransitService transitService this.buildTime = Date.from(graph.buildTime); this.transitServiceStarts = transitService.getTransitServiceStarts().toEpochSecond(); this.transitServiceEnds = transitService.getTransitServiceEnds().toEpochSecond(); - this.transitModes = TraverseModeMapper.mapToApi(transitService.getTransitModes()); + this.transitModes = ModeMapper.mapToApi(transitService.getTransitModes()); this.envelope = graph.getEnvelope(); this.hasParkRide = graph.hasParkRide; this.hasBikeSharing = mapHasBikeSharing(vehicleRentalService); diff --git a/src/main/java/org/opentripplanner/graph_builder/module/PruneNoThruIslands.java b/src/main/java/org/opentripplanner/graph_builder/module/PruneNoThruIslands.java index 4c7735d436b..5e82ffbf6b8 100644 --- a/src/main/java/org/opentripplanner/graph_builder/module/PruneNoThruIslands.java +++ b/src/main/java/org/opentripplanner/graph_builder/module/PruneNoThruIslands.java @@ -19,7 +19,6 @@ import org.opentripplanner.routing.api.request.RouteRequest; import org.opentripplanner.routing.core.State; import org.opentripplanner.routing.core.TraverseMode; -import org.opentripplanner.routing.core.TraverseModeSet; import org.opentripplanner.routing.edgetype.ElevatorEdge; import org.opentripplanner.routing.edgetype.FreeEdge; import org.opentripplanner.routing.edgetype.StreetEdge; @@ -317,7 +316,7 @@ private static void collectNeighbourVertices( TraverseMode traverseMode, boolean shouldMatchNoThruType ) { - RouteRequest options = new RouteRequest(new TraverseModeSet(traverseMode)); + RouteRequest options = new RouteRequest(traverseMode); for (Vertex gv : graph.getVertices()) { if (!(gv instanceof StreetVertex)) { diff --git a/src/main/java/org/opentripplanner/model/plan/Leg.java b/src/main/java/org/opentripplanner/model/plan/Leg.java index 56166aabb25..52b587d815c 100644 --- a/src/main/java/org/opentripplanner/model/plan/Leg.java +++ b/src/main/java/org/opentripplanner/model/plan/Leg.java @@ -16,7 +16,6 @@ import org.opentripplanner.model.plan.legreference.LegReference; import org.opentripplanner.model.transfer.ConstrainedTransfer; import org.opentripplanner.routing.alertpatch.TransitAlert; -import org.opentripplanner.routing.core.TraverseMode; import org.opentripplanner.transit.model.basic.WheelchairAccessibility; import org.opentripplanner.transit.model.framework.FeedScopedId; import org.opentripplanner.transit.model.network.Route; @@ -190,7 +189,7 @@ default WheelchairAccessibility getTripWheelchairAccessibility() { /** * The mode (e.g., Walk) used when traversing this leg. */ - TraverseMode getMode(); + LegMode getMode(); /** * The date and time this leg begins. diff --git a/src/main/java/org/opentripplanner/model/plan/LegMode.java b/src/main/java/org/opentripplanner/model/plan/LegMode.java new file mode 100644 index 00000000000..da4de97e5c3 --- /dev/null +++ b/src/main/java/org/opentripplanner/model/plan/LegMode.java @@ -0,0 +1,70 @@ +package org.opentripplanner.model.plan; + +import java.util.EnumSet; +import org.opentripplanner.routing.core.TraverseMode; +import org.opentripplanner.transit.model.basic.TransitMode; + +public enum LegMode { + WALK, + BICYCLE, + SCOOTER, + CAR, + TRAM, + SUBWAY, + RAIL, + BUS, + COACH, + FERRY, + CABLE_CAR, + GONDOLA, + FUNICULAR, + AIRPLANE, + TROLLEYBUS, + MONORAIL; + + private static final EnumSet TRANSIT_MODES = EnumSet.of( + AIRPLANE, + BUS, + CABLE_CAR, + COACH, + FERRY, + FUNICULAR, + GONDOLA, + RAIL, + SUBWAY, + TRAM, + TROLLEYBUS, + MONORAIL + ); + + public static LegMode fromTransitMode(TransitMode transitMode) { + return switch (transitMode) { + case RAIL -> RAIL; + case MONORAIL -> MONORAIL; + case COACH -> COACH; + case BUS -> BUS; + case SUBWAY -> SUBWAY; + case TRAM -> TRAM; + case FERRY -> FERRY; + case AIRPLANE -> AIRPLANE; + case CABLE_CAR -> CABLE_CAR; + case GONDOLA -> GONDOLA; + case FUNICULAR -> FUNICULAR; + case TROLLEYBUS -> TROLLEYBUS; + }; + } + + public static LegMode fromAStarTraverseMode(TraverseMode mode) { + return switch (mode) { + case WALK -> WALK; + case BICYCLE -> BICYCLE; + case SCOOTER -> SCOOTER; + case CAR -> CAR; + case FLEX -> throw new IllegalStateException(); + }; + } + + public boolean isTransit() { + return TRANSIT_MODES.contains(this); + } +} diff --git a/src/main/java/org/opentripplanner/model/plan/ScheduledTransitLeg.java b/src/main/java/org/opentripplanner/model/plan/ScheduledTransitLeg.java index 7cb03684c3e..93f542df251 100644 --- a/src/main/java/org/opentripplanner/model/plan/ScheduledTransitLeg.java +++ b/src/main/java/org/opentripplanner/model/plan/ScheduledTransitLeg.java @@ -19,7 +19,6 @@ import org.opentripplanner.model.plan.legreference.ScheduledTransitLegReference; import org.opentripplanner.model.transfer.ConstrainedTransfer; import org.opentripplanner.routing.alertpatch.TransitAlert; -import org.opentripplanner.routing.core.TraverseMode; import org.opentripplanner.transit.model.basic.WheelchairAccessibility; import org.opentripplanner.transit.model.framework.AbstractTransitEntity; import org.opentripplanner.transit.model.network.Route; @@ -162,8 +161,8 @@ public WheelchairAccessibility getTripWheelchairAccessibility() { } @Override - public TraverseMode getMode() { - return TraverseMode.fromTransitMode(getTrip().getMode()); + public LegMode getMode() { + return LegMode.fromTransitMode(getTrip().getMode()); } @Override diff --git a/src/main/java/org/opentripplanner/model/plan/StreetLeg.java b/src/main/java/org/opentripplanner/model/plan/StreetLeg.java index ab5c52e4ea4..ba3aabca54f 100644 --- a/src/main/java/org/opentripplanner/model/plan/StreetLeg.java +++ b/src/main/java/org/opentripplanner/model/plan/StreetLeg.java @@ -9,7 +9,6 @@ import org.locationtech.jts.geom.LineString; import org.opentripplanner.common.model.P2; import org.opentripplanner.model.StreetNote; -import org.opentripplanner.routing.core.TraverseMode; import org.opentripplanner.transit.model.framework.FeedScopedId; import org.opentripplanner.util.lang.DoubleUtils; import org.opentripplanner.util.lang.ToStringBuilder; @@ -20,7 +19,7 @@ */ public class StreetLeg implements Leg { - private final TraverseMode mode; + private final LegMode mode; private final ZonedDateTime startTime; private final ZonedDateTime endTime; private final double distanceMeters; @@ -79,7 +78,7 @@ public boolean isTransitLeg() { @Override public boolean isWalkingLeg() { - return mode.isWalking(); + return mode == LegMode.WALK; } @Override @@ -88,7 +87,7 @@ public boolean isStreetLeg() { } @Override - public TraverseMode getMode() { + public LegMode getMode() { return mode; } diff --git a/src/main/java/org/opentripplanner/model/plan/StreetLegBuilder.java b/src/main/java/org/opentripplanner/model/plan/StreetLegBuilder.java index 68c24e334f4..8fee059d939 100644 --- a/src/main/java/org/opentripplanner/model/plan/StreetLegBuilder.java +++ b/src/main/java/org/opentripplanner/model/plan/StreetLegBuilder.java @@ -7,12 +7,11 @@ import org.locationtech.jts.geom.LineString; import org.opentripplanner.common.model.P2; import org.opentripplanner.model.StreetNote; -import org.opentripplanner.routing.core.TraverseMode; import org.opentripplanner.transit.model.framework.FeedScopedId; public class StreetLegBuilder { - private TraverseMode mode; + private LegMode mode; private ZonedDateTime startTime; private ZonedDateTime endTime; private Place from; @@ -55,7 +54,7 @@ public StreetLeg build() { return new StreetLeg(this); } - public TraverseMode getMode() { + public LegMode getMode() { return mode; } @@ -119,7 +118,7 @@ public Set getStreetNotes() { return streetNotes; } - public StreetLegBuilder withMode(TraverseMode mode) { + public StreetLegBuilder withMode(LegMode mode) { this.mode = mode; return this; } diff --git a/src/main/java/org/opentripplanner/routing/algorithm/filterchain/deletionflagger/RemoveParkAndRideWithMostlyWalkingFilter.java b/src/main/java/org/opentripplanner/routing/algorithm/filterchain/deletionflagger/RemoveParkAndRideWithMostlyWalkingFilter.java index 98053c7b575..aff96447508 100644 --- a/src/main/java/org/opentripplanner/routing/algorithm/filterchain/deletionflagger/RemoveParkAndRideWithMostlyWalkingFilter.java +++ b/src/main/java/org/opentripplanner/routing/algorithm/filterchain/deletionflagger/RemoveParkAndRideWithMostlyWalkingFilter.java @@ -4,8 +4,7 @@ import java.util.function.Predicate; import java.util.stream.Collectors; import org.opentripplanner.model.plan.Itinerary; -import org.opentripplanner.model.plan.Leg; -import org.opentripplanner.routing.core.TraverseMode; +import org.opentripplanner.model.plan.LegMode; /** * This is used to filter out bike rental itineraries that contain mostly walking. The value @@ -38,7 +37,7 @@ public Predicate shouldBeFlaggedForRemoval() { double carDuration = itinerary .getLegs() .stream() - .filter(l -> l.getMode() == TraverseMode.CAR) + .filter(l -> l.getMode() == LegMode.CAR) .mapToDouble(l -> l.getDuration().toSeconds()) .sum(); double totalDuration = itinerary.getDuration().toSeconds(); diff --git a/src/main/java/org/opentripplanner/routing/algorithm/mapping/GraphPathToItineraryMapper.java b/src/main/java/org/opentripplanner/routing/algorithm/mapping/GraphPathToItineraryMapper.java index 41dd64831ec..5e313ca0413 100644 --- a/src/main/java/org/opentripplanner/routing/algorithm/mapping/GraphPathToItineraryMapper.java +++ b/src/main/java/org/opentripplanner/routing/algorithm/mapping/GraphPathToItineraryMapper.java @@ -17,12 +17,12 @@ import org.opentripplanner.model.StreetNote; import org.opentripplanner.model.plan.Itinerary; import org.opentripplanner.model.plan.Leg; +import org.opentripplanner.model.plan.LegMode; import org.opentripplanner.model.plan.Place; import org.opentripplanner.model.plan.StreetLeg; import org.opentripplanner.model.plan.StreetLegBuilder; import org.opentripplanner.model.plan.WalkStep; import org.opentripplanner.routing.core.State; -import org.opentripplanner.routing.core.TraverseMode; import org.opentripplanner.routing.edgetype.BoardingLocationToStopLink; import org.opentripplanner.routing.edgetype.PathwayEdge; import org.opentripplanner.routing.edgetype.StreetEdge; @@ -253,7 +253,7 @@ private static void calculateElevations(Itinerary itinerary, List edges) { * * @param states The states that go with the leg */ - private static TraverseMode resolveMode(List states) { + private static LegMode resolveMode(List states) { return states .stream() // The first state is part of the previous leg @@ -265,12 +265,12 @@ private static TraverseMode resolveMode(List states) { // Resolve correct mode if renting vehicle if (state.isRentingVehicle()) { return switch (state.stateData.rentalVehicleFormFactor) { - case BICYCLE, OTHER -> TraverseMode.BICYCLE; - case SCOOTER, MOPED -> TraverseMode.SCOOTER; - case CAR -> TraverseMode.CAR; + case BICYCLE, OTHER -> LegMode.BICYCLE; + case SCOOTER, MOPED -> LegMode.SCOOTER; + case CAR -> LegMode.CAR; }; } else { - return mode; + return LegMode.fromAStarTraverseMode(mode); } } @@ -279,7 +279,7 @@ private static TraverseMode resolveMode(List states) { .filter(Objects::nonNull) .findFirst() // Fallback to walking - .orElse(TraverseMode.WALK); + .orElse(LegMode.WALK); } private static List> encodeElevationProfileWithNaN( diff --git a/src/main/java/org/opentripplanner/routing/algorithm/mapping/RaptorPathToItineraryMapper.java b/src/main/java/org/opentripplanner/routing/algorithm/mapping/RaptorPathToItineraryMapper.java index 57bfee6c921..5697a66e3ec 100644 --- a/src/main/java/org/opentripplanner/routing/algorithm/mapping/RaptorPathToItineraryMapper.java +++ b/src/main/java/org/opentripplanner/routing/algorithm/mapping/RaptorPathToItineraryMapper.java @@ -8,6 +8,7 @@ import org.opentripplanner.model.plan.FrequencyTransitLeg; import org.opentripplanner.model.plan.Itinerary; import org.opentripplanner.model.plan.Leg; +import org.opentripplanner.model.plan.LegMode; import org.opentripplanner.model.plan.Place; import org.opentripplanner.model.plan.ScheduledTransitLeg; import org.opentripplanner.model.plan.StreetLeg; @@ -23,7 +24,6 @@ import org.opentripplanner.routing.core.RoutingContext; import org.opentripplanner.routing.core.State; import org.opentripplanner.routing.core.StateEditor; -import org.opentripplanner.routing.core.TraverseMode; import org.opentripplanner.routing.graph.Edge; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.routing.graph.Vertex; @@ -103,7 +103,7 @@ else if (pathLeg.isTransferLeg()) { legs.addAll( mapTransferLeg( pathLeg.asTransferLeg(), - request.modes.transferMode == StreetMode.BIKE ? TraverseMode.BICYCLE : TraverseMode.WALK + request.modes.transferMode == StreetMode.BIKE ? LegMode.BICYCLE : LegMode.WALK ) ); } @@ -203,10 +203,7 @@ private Leg mapTransitLeg(Leg prevTransitLeg, TransitPathLeg pathL ); } - private List mapTransferLeg( - TransferPathLeg pathLeg, - TraverseMode transferMode - ) { + private List mapTransferLeg(TransferPathLeg pathLeg, LegMode transferMode) { var transferFromStop = transitLayer.getStopByIndex(pathLeg.fromStop()); var transferToStop = transitLayer.getStopByIndex(pathLeg.toStop()); Transfer transfer = ((TransferWithDuration) pathLeg.transfer()).transfer(); @@ -237,7 +234,7 @@ private Itinerary mapEgressLeg(EgressPathLeg egressPathLeg) { private List mapNonTransitLeg( PathLeg pathLeg, Transfer transfer, - TraverseMode transferMode, + LegMode transferMode, Place from, Place to ) { diff --git a/src/main/java/org/opentripplanner/routing/api/request/RouteRequest.java b/src/main/java/org/opentripplanner/routing/api/request/RouteRequest.java index bcf24e15b64..ddd5f7b0cb5 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/RouteRequest.java +++ b/src/main/java/org/opentripplanner/routing/api/request/RouteRequest.java @@ -227,11 +227,6 @@ public RouteRequest() { to = new GenericLocation(null, null); } - public RouteRequest(TraverseModeSet streetSubRequestModes) { - this(); - this.setStreetSubRequestModes(streetSubRequestModes); - } - public RouteRequest(TraverseMode mode) { this(); this.setStreetSubRequestModes(new TraverseModeSet(mode)); diff --git a/src/main/java/org/opentripplanner/routing/core/TraverseMode.java b/src/main/java/org/opentripplanner/routing/core/TraverseMode.java index f304a137e91..468d90b8bb5 100644 --- a/src/main/java/org/opentripplanner/routing/core/TraverseMode.java +++ b/src/main/java/org/opentripplanner/routing/core/TraverseMode.java @@ -1,76 +1,16 @@ package org.opentripplanner.routing.core; import java.util.EnumSet; -import org.opentripplanner.transit.model.basic.TransitMode; public enum TraverseMode { WALK, BICYCLE, SCOOTER, CAR, - TRAM, - SUBWAY, - RAIL, - BUS, - FERRY, - CABLE_CAR, - GONDOLA, - FUNICULAR, - TRANSIT, - AIRPLANE, - TROLLEYBUS, - MONORAIL; - - private static final EnumSet TRANSIT_MODES = EnumSet.of( - AIRPLANE, - BUS, - CABLE_CAR, - FERRY, - FUNICULAR, - GONDOLA, - RAIL, - SUBWAY, - TRAM, - TRANSIT, - TROLLEYBUS, - MONORAIL - ); + FLEX; private static final EnumSet STREET_MODES = EnumSet.of(WALK, BICYCLE, SCOOTER, CAR); - public static TraverseMode fromTransitMode(TransitMode transitMode) { - switch (transitMode) { - case RAIL: - case MONORAIL: - return TraverseMode.RAIL; - case COACH: - case BUS: - return TraverseMode.BUS; - case SUBWAY: - return TraverseMode.SUBWAY; - case TRAM: - return TraverseMode.TRAM; - case FERRY: - return TraverseMode.FERRY; - case AIRPLANE: - return TraverseMode.AIRPLANE; - case CABLE_CAR: - return TraverseMode.CABLE_CAR; - case GONDOLA: - return TraverseMode.GONDOLA; - case FUNICULAR: - return TraverseMode.FUNICULAR; - case TROLLEYBUS: - return TraverseMode.TROLLEYBUS; - default: - throw new IllegalArgumentException(); - } - } - - public boolean isTransit() { - return TRANSIT_MODES.contains(this); - } - public boolean isOnStreetNonTransit() { return STREET_MODES.contains(this); } @@ -80,7 +20,7 @@ public boolean isDriving() { } public boolean isCycling() { - return this == BICYCLE; + return this == BICYCLE || this == SCOOTER; } public boolean isWalking() { diff --git a/src/main/java/org/opentripplanner/routing/core/TraverseModeSet.java b/src/main/java/org/opentripplanner/routing/core/TraverseModeSet.java index 5d75a8e193c..676c85b4e97 100644 --- a/src/main/java/org/opentripplanner/routing/core/TraverseModeSet.java +++ b/src/main/java/org/opentripplanner/routing/core/TraverseModeSet.java @@ -17,52 +17,15 @@ */ public class TraverseModeSet implements Cloneable, Serializable { - private static final long serialVersionUID = -1640048158419762255L; - private static final int MODE_BICYCLE = 1; private static final int MODE_WALK = 2; private static final int MODE_CAR = 4; - private static final int MODE_BUS = 16; - - private static final int MODE_TRAM = 32; - - private static final int MODE_SUBWAY = 64; - - private static final int MODE_RAIL = 128; - - private static final int MODE_FERRY = 256; - - private static final int MODE_CABLE_CAR = 512; - - private static final int MODE_GONDOLA = 1024; - - private static final int MODE_FUNICULAR = 2048; - - private static final int MODE_AIRPLANE = 4096; - - private static final int MODE_TROLLEYBUS = 8192; - - private static final int MODE_MONORAIL = 16384; - - private static final int MODE_TRANSIT = - MODE_TRAM | - MODE_RAIL | - MODE_SUBWAY | - MODE_FUNICULAR | - MODE_GONDOLA | - MODE_CABLE_CAR | - MODE_BUS | - MODE_FERRY | - MODE_AIRPLANE | - MODE_TROLLEYBUS | - MODE_MONORAIL; + private static final int MODE_ALL = MODE_CAR | MODE_WALK | MODE_BICYCLE; - private static final int MODE_ALL = MODE_TRANSIT | MODE_WALK | MODE_BICYCLE; - - private int modes = 0; + private byte modes = 0; public TraverseModeSet(TraverseMode... modes) { for (TraverseMode mode : modes) { @@ -83,15 +46,6 @@ public static TraverseModeSet allModes() { return modes; } - public void setMode(TraverseMode mode, boolean value) { - int mask = getMaskForMode(mode); - if (value) { - modes |= mask; - } else { - modes &= ~mask; - } - } - public boolean getBicycle() { return (modes & MODE_BICYCLE) != 0; } @@ -128,159 +82,6 @@ public void setCar(boolean car) { } } - public boolean getTram() { - return (modes & MODE_TRAM) != 0; - } - - public void setTram(boolean tram) { - if (tram) { - modes |= MODE_TRAM; - } else { - modes &= ~MODE_TRAM; - } - } - - public boolean getBus() { - return (modes & MODE_BUS) != 0; - } - - public void setBus(boolean bus) { - if (bus) { - modes |= MODE_BUS; - } else { - modes &= ~MODE_BUS; - } - } - - public boolean getGondola() { - return (modes & MODE_GONDOLA) != 0; - } - - public void setGondola(boolean gondola) { - if (gondola) { - modes |= MODE_GONDOLA; - } else { - modes &= ~MODE_GONDOLA; - } - } - - public boolean getFerry() { - return (modes & MODE_FERRY) != 0; - } - - public void setFerry(boolean ferry) { - if (ferry) { - modes |= MODE_FERRY; - } else { - modes &= ~MODE_FERRY; - } - } - - public boolean getCableCar() { - return (modes & MODE_CABLE_CAR) != 0; - } - - public void setCableCar(boolean cableCar) { - if (cableCar) { - modes |= MODE_CABLE_CAR; - } else { - modes &= ~MODE_CABLE_CAR; - } - } - - public boolean getFunicular() { - return (modes & MODE_FUNICULAR) != 0; - } - - public void setFunicular(boolean funicular) { - if (funicular) { - modes |= MODE_FUNICULAR; - } else { - modes &= ~MODE_FUNICULAR; - } - } - - public boolean getRail() { - return (modes & MODE_RAIL) != 0; - } - - public void setRail(boolean rail) { - if (rail) { - modes |= MODE_RAIL; - } else { - modes &= ~MODE_RAIL; - } - } - - public boolean getTrolleyBus() { - return (modes & MODE_TROLLEYBUS) != 0; - } - - public boolean geMonorail() { - return (modes & MODE_MONORAIL) != 0; - } - - public boolean getSubway() { - return (modes & MODE_SUBWAY) != 0; - } - - public void setSubway(boolean subway) { - if (subway) { - modes |= MODE_SUBWAY; - } else { - modes &= ~MODE_SUBWAY; - } - } - - public boolean getAirplane() { - return (modes & MODE_AIRPLANE) != 0; - } - - public void setAirplane(boolean airplane) { - if (airplane) { - modes |= MODE_AIRPLANE; - } else { - modes &= ~MODE_AIRPLANE; - } - } - - public void setTrolleybus(boolean trolleybus) { - if (trolleybus) { - modes |= MODE_TROLLEYBUS; - } else { - modes &= ~MODE_TROLLEYBUS; - } - } - - public void setMonorail(boolean monorail) { - if (monorail) { - modes |= MODE_MONORAIL; - } else { - modes &= ~MODE_MONORAIL; - } - } - - /** Returns true if the trip may use some transit mode */ - public boolean isTransit() { - return (modes & (MODE_TRANSIT)) != 0; - } - - public void setTransit(boolean transit) { - if (transit) { - modes |= MODE_TRANSIT; - } else { - modes &= ~MODE_TRANSIT; - } - } - - /** Returns a TraverseModeSet containing only the non-transit modes set. */ - public TraverseModeSet getNonTransitSet() { - TraverseModeSet retval = new TraverseModeSet(); - retval.modes = modes; - retval.setTransit(false); - return retval; - } - public List getModes() { ArrayList modeList = new ArrayList<>(); for (TraverseMode mode : TraverseMode.values()) { @@ -299,10 +100,6 @@ public boolean contains(TraverseMode mode) { return (modes & getMaskForMode(mode)) != 0; } - public boolean get(int modeMask) { - return (modes & modeMask) != 0; - } - /** get this traverse mode as a string that can be fed back into the constructor */ public String getAsStr() { String retVal = null; @@ -350,7 +147,7 @@ public String toString() { for (TraverseMode mode : TraverseMode.values()) { int mask = getMaskForMode(mode); if (mask != 0 && (modes & mask) == mask) { - if (out.length() != 0) { + if (!out.isEmpty()) { out.append(", "); } out.append(mode); @@ -361,22 +158,10 @@ public String toString() { private int getMaskForMode(TraverseMode mode) { return switch (mode) { - case BICYCLE -> MODE_BICYCLE; + case BICYCLE, SCOOTER -> MODE_BICYCLE; case WALK -> MODE_WALK; case CAR -> MODE_CAR; - case BUS -> MODE_BUS; - case TRAM -> MODE_TRAM; - case CABLE_CAR -> MODE_CABLE_CAR; - case GONDOLA -> MODE_GONDOLA; - case FERRY -> MODE_FERRY; - case FUNICULAR -> MODE_FUNICULAR; - case SUBWAY -> MODE_SUBWAY; - case RAIL -> MODE_RAIL; - case TROLLEYBUS -> MODE_TROLLEYBUS; - case MONORAIL -> MODE_MONORAIL; - case AIRPLANE -> MODE_AIRPLANE; - case TRANSIT -> MODE_TRANSIT; - default -> 0; + case FLEX -> 0; }; } } diff --git a/src/main/java/org/opentripplanner/routing/impl/GraphPathFinder.java b/src/main/java/org/opentripplanner/routing/impl/GraphPathFinder.java index 6d2a9d99ad4..7d6ff955bd7 100644 --- a/src/main/java/org/opentripplanner/routing/impl/GraphPathFinder.java +++ b/src/main/java/org/opentripplanner/routing/impl/GraphPathFinder.java @@ -66,10 +66,6 @@ public List getPaths(RoutingContext routingContext) { RouteRequest options = routingContext.opt; RoutingPreferences preferences = routingContext.opt.preferences(); - if (options.streetSubRequestModes.isTransit()) { - throw new UnsupportedOperationException("Transit search not supported"); - } - AStarBuilder aStar = AStarBuilder .oneToOneMaxDuration(preferences.street().maxDirectDuration(options.modes.directMode)) // FORCING the dominance function to weight only diff --git a/src/main/java/org/opentripplanner/util/TravelOptionsMaker.java b/src/main/java/org/opentripplanner/util/TravelOptionsMaker.java index a929a10251d..893beea1bcc 100644 --- a/src/main/java/org/opentripplanner/util/TravelOptionsMaker.java +++ b/src/main/java/org/opentripplanner/util/TravelOptionsMaker.java @@ -1,10 +1,9 @@ package org.opentripplanner.util; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Set; -import org.opentripplanner.routing.core.TraverseMode; +import org.opentripplanner.api.parameter.ApiRequestMode; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.transit.model.basic.TransitMode; import org.opentripplanner.transit.service.TransitService; @@ -21,9 +20,9 @@ public final class TravelOptionsMaker { static { staticTravelOptions = new ArrayList<>(3); - staticTravelOptions.add(new TravelOption(TraverseMode.WALK.toString())); - staticTravelOptions.add(new TravelOption(TraverseMode.BICYCLE.toString())); - staticTravelOptions.add(new TravelOption(TraverseMode.CAR.toString())); + staticTravelOptions.add(new TravelOption(ApiRequestMode.WALK.toString())); + staticTravelOptions.add(new TravelOption(ApiRequestMode.BICYCLE.toString())); + staticTravelOptions.add(new TravelOption(ApiRequestMode.CAR.toString())); } public static List makeOptions(Graph graph, TransitService transitService) { @@ -47,15 +46,15 @@ public static List makeOptions( if (!transitModes.isEmpty()) { travelOptions.add( new TravelOption( - String.join(",", TraverseMode.TRANSIT.toString(), TraverseMode.WALK.toString()), - TraverseMode.TRANSIT.toString() + String.join(",", ApiRequestMode.TRANSIT.toString(), ApiRequestMode.WALK.toString()), + ApiRequestMode.TRANSIT.toString() ) ); for (TransitMode transitMode : transitModes) { travelOptions.add( new TravelOption( - String.join(",", transitMode.toString(), TraverseMode.WALK.toString()), + String.join(",", transitMode.toString(), ApiRequestMode.WALK.toString()), transitMode.toString() ) ); @@ -67,7 +66,7 @@ public static List makeOptions( if (hasBikeSharing) { travelOptions.add( new TravelOption( - String.join(",", TraverseMode.WALK.toString(), "BICYCLE_RENT"), + String.join(",", ApiRequestMode.WALK.toString(), "BICYCLE_RENT"), "BICYCLERENT" ) ); @@ -78,8 +77,8 @@ public static List makeOptions( //Adds bicycle transit mode travelOptions.add( new TravelOption( - String.join(",", TraverseMode.TRANSIT.toString(), TraverseMode.BICYCLE.toString()), - String.join("_", TraverseMode.TRANSIT.toString(), TraverseMode.BICYCLE.toString()) + String.join(",", ApiRequestMode.TRANSIT.toString(), ApiRequestMode.BICYCLE.toString()), + String.join("_", ApiRequestMode.TRANSIT.toString(), ApiRequestMode.BICYCLE.toString()) ) ); if (hasBikeSharing) { @@ -87,8 +86,8 @@ public static List makeOptions( new TravelOption( String.join( ",", - TraverseMode.TRANSIT.toString(), - TraverseMode.WALK.toString(), + ApiRequestMode.TRANSIT.toString(), + ApiRequestMode.WALK.toString(), "BICYCLE_RENT" ), "TRANSIT_BICYCLERENT" @@ -101,8 +100,8 @@ public static List makeOptions( String.join( ",", "CAR_PARK", - TraverseMode.WALK.toString(), - TraverseMode.TRANSIT.toString() + ApiRequestMode.WALK.toString(), + ApiRequestMode.TRANSIT.toString() ), "PARKRIDE" ) @@ -114,8 +113,8 @@ public static List makeOptions( String.join( ",", "BICYCLE_PARK", - TraverseMode.WALK.toString(), - TraverseMode.TRANSIT.toString() + ApiRequestMode.WALK.toString(), + ApiRequestMode.TRANSIT.toString() ), "BIKERIDE" ) @@ -125,9 +124,9 @@ public static List makeOptions( new TravelOption( String.join( ",", - TraverseMode.CAR.toString(), - TraverseMode.WALK.toString(), - TraverseMode.TRANSIT.toString() + ApiRequestMode.CAR.toString(), + ApiRequestMode.WALK.toString(), + ApiRequestMode.TRANSIT.toString() ), "KISSRIDE" ) diff --git a/src/main/java/org/opentripplanner/visualizer/GraphVisualizer.java b/src/main/java/org/opentripplanner/visualizer/GraphVisualizer.java index c723f34beb7..23e89255981 100644 --- a/src/main/java/org/opentripplanner/visualizer/GraphVisualizer.java +++ b/src/main/java/org/opentripplanner/visualizer/GraphVisualizer.java @@ -57,6 +57,8 @@ import javax.swing.event.ListSelectionListener; import org.locationtech.jts.geom.Coordinate; import org.opentripplanner.api.common.LocationStringParser; +import org.opentripplanner.api.parameter.ApiRequestMode; +import org.opentripplanner.api.parameter.QualifiedModeSet; import org.opentripplanner.graph_builder.DataImportIssue; import org.opentripplanner.routing.algorithm.astar.TraverseVisitor; import org.opentripplanner.routing.api.request.RouteRequest; @@ -64,7 +66,6 @@ import org.opentripplanner.routing.core.RoutingContext; import org.opentripplanner.routing.core.State; import org.opentripplanner.routing.core.TemporaryVerticesContainer; -import org.opentripplanner.routing.core.TraverseModeSet; import org.opentripplanner.routing.edgetype.StreetEdge; import org.opentripplanner.routing.graph.Edge; import org.opentripplanner.routing.graph.Graph; @@ -439,22 +440,36 @@ protected void route(String from, String to) { searchDate.setText("Format: " + DATE_FORMAT.toString()); return; } - TraverseModeSet modeSet = new TraverseModeSet(); - modeSet.setWalk(walkCheckBox.isSelected()); - modeSet.setBicycle(bikeCheckBox.isSelected()); - modeSet.setFerry(ferryCheckBox.isSelected()); - modeSet.setRail(trainCheckBox.isSelected()); - modeSet.setTram(trainCheckBox.isSelected()); - modeSet.setSubway(trainCheckBox.isSelected()); - modeSet.setFunicular(trainCheckBox.isSelected()); - modeSet.setGondola(trainCheckBox.isSelected()); - modeSet.setBus(busCheckBox.isSelected()); - modeSet.setCableCar(busCheckBox.isSelected()); - modeSet.setCar(carCheckBox.isSelected()); - // must set generic transit mode last, and only when it is checked - // otherwise 'false' will clear trainish and busish - if (transitCheckBox.isSelected()) modeSet.setTransit(true); - RouteRequest options = new RouteRequest(modeSet); + List modes = new ArrayList<>(); + if (walkCheckBox.isSelected()) { + modes.add(ApiRequestMode.WALK.name()); + } + if (bikeCheckBox.isSelected()) { + modes.add(ApiRequestMode.BICYCLE.name()); + } + if (carCheckBox.isSelected()) { + modes.add(ApiRequestMode.CAR.name()); + } + if (ferryCheckBox.isSelected()) { + modes.add(ApiRequestMode.FERRY.name()); + } + if (trainCheckBox.isSelected()) { + modes.add(ApiRequestMode.RAIL.name()); + modes.add(ApiRequestMode.TRAM.name()); + modes.add(ApiRequestMode.SUBWAY.name()); + modes.add(ApiRequestMode.FUNICULAR.name()); + modes.add(ApiRequestMode.GONDOLA.name()); + } + if (busCheckBox.isSelected()) { + modes.add(ApiRequestMode.BUS.name()); + modes.add(ApiRequestMode.CABLE_CAR.name()); + } + if (transitCheckBox.isSelected()) { + modes.add(ApiRequestMode.TRANSIT.name()); + } + RouteRequest options = new RouteRequest(); + QualifiedModeSet qualifiedModeSet = new QualifiedModeSet(modes.toArray(String[]::new)); + options.modes = qualifiedModeSet.getRequestModes(); var preferences = options.preferences(); options.setArriveBy(arriveByCheckBox.isSelected()); @@ -471,7 +486,7 @@ protected void route(String from, String to) { options.setNumItineraries(Integer.parseInt(this.nPaths.getText())); System.out.println("--------"); System.out.println("Path from " + from + " to " + to + " at " + when); - System.out.println("\tModes: " + modeSet); + System.out.println("\tModes: " + qualifiedModeSet); System.out.println("\tOptions: " + options); // apply callback if the options call for it diff --git a/src/main/java/org/opentripplanner/visualizer/ShowGraph.java b/src/main/java/org/opentripplanner/visualizer/ShowGraph.java index 8cc5fd69c2f..a0629d9edb4 100644 --- a/src/main/java/org/opentripplanner/visualizer/ShowGraph.java +++ b/src/main/java/org/opentripplanner/visualizer/ShowGraph.java @@ -610,11 +610,12 @@ private void drawGraphPath(GraphPath gp) { Edge e = s.getBackEdge(); if (e == null) continue; - if (mode != null && mode.isTransit()) { - stroke(200, 050, 000); - strokeWeight(6); - drawEdge(e); - } + // TODO Add support for crating transit edges on the fly + // if (mode != null && mode.isTransit()) { + // stroke(200, 050, 000); + // strokeWeight(6); + // drawEdge(e); + // } if (e instanceof StreetEdge) { StreetTraversalPermission stp = ((StreetEdge) e).getPermission(); if (stp == StreetTraversalPermission.PEDESTRIAN) { diff --git a/src/test/java/org/opentripplanner/GtfsTest.java b/src/test/java/org/opentripplanner/GtfsTest.java index d1a8d986d68..0502e9f7954 100644 --- a/src/test/java/org/opentripplanner/GtfsTest.java +++ b/src/test/java/org/opentripplanner/GtfsTest.java @@ -3,6 +3,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.opentripplanner.routing.api.request.StreetMode.NOT_SET; +import static org.opentripplanner.routing.api.request.StreetMode.WALK; import static org.opentripplanner.updater.stoptime.BackwardsDelayPropagationType.REQUIRED_NO_DATA; import com.google.transit.realtime.GtfsRealtime.FeedEntity; @@ -23,15 +25,16 @@ import org.opentripplanner.model.calendar.ServiceDateInterval; import org.opentripplanner.model.plan.Itinerary; import org.opentripplanner.model.plan.Leg; +import org.opentripplanner.routing.api.request.RequestModesBuilder; import org.opentripplanner.routing.api.request.RouteRequest; import org.opentripplanner.routing.api.request.preference.RoutingPreferences; import org.opentripplanner.routing.api.response.RoutingResponse; import org.opentripplanner.routing.core.RouteMatcher; -import org.opentripplanner.routing.core.TraverseMode; -import org.opentripplanner.routing.core.TraverseModeSet; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.routing.impl.TransitAlertServiceImpl; import org.opentripplanner.standalone.api.OtpServerRequestContext; +import org.opentripplanner.transit.model.basic.MainAndSubMode; +import org.opentripplanner.transit.model.basic.TransitMode; import org.opentripplanner.transit.model.framework.Deduplicator; import org.opentripplanner.transit.model.framework.FeedScopedId; import org.opentripplanner.transit.service.StopModel; @@ -61,12 +64,11 @@ public Itinerary plan( String onTripId, boolean wheelchairAccessible, boolean preferLeastTransfers, - TraverseMode preferredMode, + TransitMode preferredMode, String excludedRoute, String excludedStop, int legCount ) { - final TraverseMode mode = preferredMode != null ? preferredMode : TraverseMode.TRANSIT; RouteRequest routingRequest = new RouteRequest(); RoutingPreferences preferences = routingRequest.preferences(); @@ -89,7 +91,18 @@ public Itinerary plan( } routingRequest.setWheelchair(wheelchairAccessible); preferences.transfer().setCost(preferLeastTransfers ? 300 : 0); - routingRequest.setStreetSubRequestModes(new TraverseModeSet(TraverseMode.WALK, mode)); + RequestModesBuilder requestModesBuilder = routingRequest.modes + .copy() + .withDirectMode(NOT_SET) + .withAccessMode(WALK) + .withTransferMode(WALK) + .withEgressMode(WALK); + if (preferredMode != null) { + requestModesBuilder.withTransitMode(preferredMode); + } else { + requestModesBuilder.withTransitModes(MainAndSubMode.all()); + } + routingRequest.modes = requestModesBuilder.build(); if (excludedRoute != null && !excludedRoute.isEmpty()) { routingRequest.setBannedRoutes(List.of(new FeedScopedId(feedId.getId(), excludedRoute))); } diff --git a/src/test/java/org/opentripplanner/graph_builder/module/osm/OpenStreetMapModuleTest.java b/src/test/java/org/opentripplanner/graph_builder/module/osm/OpenStreetMapModuleTest.java index f2fadff6b81..05427330abf 100644 --- a/src/test/java/org/opentripplanner/graph_builder/module/osm/OpenStreetMapModuleTest.java +++ b/src/test/java/org/opentripplanner/graph_builder/module/osm/OpenStreetMapModuleTest.java @@ -318,7 +318,7 @@ private void testBuildingAreas(boolean skipVisibility) { loader.buildGraph(); - RouteRequest request = new RouteRequest(new TraverseModeSet(TraverseMode.WALK)); + RouteRequest request = new RouteRequest(TraverseMode.WALK); //This are vertices that can be connected only over edges on area (with correct permissions) //It tests if it is possible to route over area without visibility calculations diff --git a/src/test/java/org/opentripplanner/graph_builder/module/osm/TestIntermediatePlaces.java b/src/test/java/org/opentripplanner/graph_builder/module/osm/TestIntermediatePlaces.java index 614d354acef..beaa908f2b3 100644 --- a/src/test/java/org/opentripplanner/graph_builder/module/osm/TestIntermediatePlaces.java +++ b/src/test/java/org/opentripplanner/graph_builder/module/osm/TestIntermediatePlaces.java @@ -4,6 +4,8 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.opentripplanner.routing.api.request.StreetMode.CAR; +import static org.opentripplanner.routing.api.request.StreetMode.NOT_SET; import java.time.Duration; import java.time.Instant; @@ -21,11 +23,10 @@ import org.opentripplanner.model.plan.TripPlan; import org.opentripplanner.routing.algorithm.mapping.GraphPathToItineraryMapper; import org.opentripplanner.routing.algorithm.mapping.TripPlanMapper; +import org.opentripplanner.routing.api.request.RequestModes; import org.opentripplanner.routing.api.request.RouteRequest; import org.opentripplanner.routing.core.RoutingContext; import org.opentripplanner.routing.core.TemporaryVerticesContainer; -import org.opentripplanner.routing.core.TraverseMode; -import org.opentripplanner.routing.core.TraverseModeSet; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.routing.impl.GraphPathFinder; import org.opentripplanner.routing.spt.GraphPath; @@ -85,14 +86,14 @@ public void testWithoutIntermediatePlaces() { fromLocation, toLocation, intermediateLocations, - new TraverseModeSet(TraverseMode.WALK), + RequestModes.defaultRequestModes().copy().clearTransitModes().build(), false ); handleRequest( fromLocation, toLocation, intermediateLocations, - new TraverseModeSet(TraverseMode.WALK), + RequestModes.defaultRequestModes().copy().clearTransitModes().build(), true ); } @@ -108,14 +109,14 @@ public void testOneIntermediatePlace() { fromLocation, toLocation, intermediateLocations, - new TraverseModeSet(TraverseMode.WALK), + RequestModes.defaultRequestModes().copy().clearTransitModes().build(), false ); handleRequest( fromLocation, toLocation, intermediateLocations, - new TraverseModeSet(TraverseMode.WALK), + RequestModes.defaultRequestModes().copy().clearTransitModes().build(), true ); } @@ -133,14 +134,14 @@ public void testTwoIntermediatePlaces() { fromLocation, toLocation, intermediateLocations, - new TraverseModeSet(TraverseMode.CAR), + RequestModes.defaultRequestModes().copy().withDirectMode(CAR).clearTransitModes().build(), false ); handleRequest( fromLocation, toLocation, intermediateLocations, - new TraverseModeSet(TraverseMode.CAR), + RequestModes.defaultRequestModes().copy().withDirectMode(CAR).clearTransitModes().build(), true ); } @@ -155,14 +156,14 @@ public void testTransitWithoutIntermediatePlaces() { fromLocation, toLocation, intermediateLocations, - new TraverseModeSet(TraverseMode.TRANSIT, TraverseMode.WALK), + RequestModes.defaultRequestModes(), false ); handleRequest( fromLocation, toLocation, intermediateLocations, - new TraverseModeSet(TraverseMode.TRANSIT, TraverseMode.WALK), + RequestModes.defaultRequestModes(), true ); } @@ -177,14 +178,14 @@ public void testThreeBusStopPlaces() { fromLocation, toLocation, intermediateLocations, - new TraverseModeSet(TraverseMode.TRANSIT), + RequestModes.defaultRequestModes().copy().withDirectMode(NOT_SET).build(), false ); handleRequest( fromLocation, toLocation, intermediateLocations, - new TraverseModeSet(TraverseMode.TRANSIT), + RequestModes.defaultRequestModes().copy().withDirectMode(NOT_SET).build(), true ); } @@ -199,14 +200,14 @@ public void testTransitOneIntermediatePlace() { fromLocation, toLocation, intermediateLocations, - new TraverseModeSet(TraverseMode.TRANSIT, TraverseMode.WALK), + RequestModes.defaultRequestModes(), false ); handleRequest( fromLocation, toLocation, intermediateLocations, - new TraverseModeSet(TraverseMode.TRANSIT, TraverseMode.WALK), + RequestModes.defaultRequestModes(), true ); } @@ -223,14 +224,14 @@ public void testTransitTwoIntermediatePlaces() { fromLocation, toLocation, intermediateLocations, - new TraverseModeSet(TraverseMode.TRANSIT, TraverseMode.WALK), + RequestModes.defaultRequestModes(), false ); handleRequest( fromLocation, toLocation, intermediateLocations, - new TraverseModeSet(TraverseMode.TRANSIT, TraverseMode.WALK), + RequestModes.defaultRequestModes(), true ); } @@ -239,11 +240,11 @@ private void handleRequest( GenericLocation from, GenericLocation to, GenericLocation[] via, - TraverseModeSet modes, + RequestModes modes, boolean arriveBy ) { - // TODO VIA - Why is input modes no longer set in the request RouteRequest request = new RouteRequest(); + request.modes = modes; request.setDateTime("2016-04-20", "13:00", timeZone); request.setArriveBy(arriveBy); request.setFrom(from); @@ -268,7 +269,7 @@ private void handleRequest( assertTrue(via.length < itinerary.getLegs().size()); validateLegsTemporally(request, itinerary); validateLegsSpatially(plan, itinerary); - if (modes.contains(TraverseMode.TRANSIT)) { + if (!modes.transitModes.isEmpty()) { assertTrue(itinerary.getTransitDuration().toSeconds() > 0); } } diff --git a/src/test/java/org/opentripplanner/graph_builder/module/osm/TriangleInequalityTest.java b/src/test/java/org/opentripplanner/graph_builder/module/osm/TriangleInequalityTest.java index adc7882d872..dc23fdde3ce 100644 --- a/src/test/java/org/opentripplanner/graph_builder/module/osm/TriangleInequalityTest.java +++ b/src/test/java/org/opentripplanner/graph_builder/module/osm/TriangleInequalityTest.java @@ -5,6 +5,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.opentripplanner.graph_builder.DataImportIssueStore.noopIssueStore; +import static org.opentripplanner.routing.api.request.StreetMode.BIKE; +import static org.opentripplanner.routing.api.request.StreetMode.CAR; import java.io.File; import java.net.URLDecoder; @@ -19,7 +21,9 @@ import org.opentripplanner.graph_builder.ConfiguredDataSource; import org.opentripplanner.openstreetmap.OpenStreetMapProvider; import org.opentripplanner.routing.algorithm.astar.AStarBuilder; +import org.opentripplanner.routing.api.request.RequestModes; import org.opentripplanner.routing.api.request.RouteRequest; +import org.opentripplanner.routing.api.request.StreetMode; import org.opentripplanner.routing.core.RoutingContext; import org.opentripplanner.routing.core.TraverseMode; import org.opentripplanner.routing.core.TraverseModeSet; @@ -93,25 +97,35 @@ public void testTriangleInequalityDefaultModes() { @Test public void testTriangleInequalityWalkingOnly() { - TraverseModeSet modes = new TraverseModeSet(TraverseMode.WALK); + RequestModes modes = RequestModes.defaultRequestModes().copy().clearTransitModes().build(); checkTriangleInequality(modes); } @Test public void testTriangleInequalityDrivingOnly() { - TraverseModeSet modes = new TraverseModeSet(TraverseMode.CAR); + RequestModes modes = RequestModes + .defaultRequestModes() + .copy() + .withDirectMode(CAR) + .clearTransitModes() + .build(); checkTriangleInequality(modes); } @Test public void testTriangleInequalityWalkTransit() { - TraverseModeSet modes = new TraverseModeSet(TraverseMode.WALK, TraverseMode.TRANSIT); + RequestModes modes = RequestModes.defaultRequestModes(); checkTriangleInequality(modes); } @Test public void testTriangleInequalityWalkBike() { - TraverseModeSet modes = new TraverseModeSet(TraverseMode.WALK, TraverseMode.BICYCLE); + RequestModes modes = RequestModes + .defaultRequestModes() + .copy() + .withDirectMode(BIKE) + .clearTransitModes() + .build(); checkTriangleInequality(modes); } @@ -122,25 +136,35 @@ public void testTriangleInequalityDefaultModesBasicSPT() { @Test public void testTriangleInequalityWalkingOnlyBasicSPT() { - TraverseModeSet modes = new TraverseModeSet(TraverseMode.WALK); + RequestModes modes = RequestModes.defaultRequestModes().copy().clearTransitModes().build(); checkTriangleInequality(modes); } @Test public void testTriangleInequalityDrivingOnlyBasicSPT() { - TraverseModeSet modes = new TraverseModeSet(TraverseMode.CAR); + RequestModes modes = RequestModes + .defaultRequestModes() + .copy() + .withDirectMode(CAR) + .clearTransitModes() + .build(); checkTriangleInequality(modes); } @Test public void testTriangleInequalityWalkTransitBasicSPT() { - TraverseModeSet modes = new TraverseModeSet(TraverseMode.WALK, TraverseMode.TRANSIT); + RequestModes modes = RequestModes.defaultRequestModes(); checkTriangleInequality(modes); } @Test public void testTriangleInequalityWalkBikeBasicSPT() { - TraverseModeSet modes = new TraverseModeSet(TraverseMode.WALK, TraverseMode.BICYCLE); + RequestModes modes = RequestModes + .defaultRequestModes() + .copy() + .withDirectMode(BIKE) + .clearTransitModes() + .build(); checkTriangleInequality(modes); } @@ -151,25 +175,35 @@ public void testTriangleInequalityDefaultModesMultiSPT() { @Test public void testTriangleInequalityWalkingOnlyMultiSPT() { - TraverseModeSet modes = new TraverseModeSet(TraverseMode.WALK); + RequestModes modes = RequestModes.defaultRequestModes().copy().clearTransitModes().build(); checkTriangleInequality(modes); } @Test public void testTriangleInequalityDrivingOnlyMultiSPT() { - TraverseModeSet modes = new TraverseModeSet(TraverseMode.CAR); + RequestModes modes = RequestModes + .defaultRequestModes() + .copy() + .withDirectMode(CAR) + .clearTransitModes() + .build(); checkTriangleInequality(modes); } @Test public void testTriangleInequalityWalkTransitMultiSPT() { - TraverseModeSet modes = new TraverseModeSet(TraverseMode.WALK, TraverseMode.TRANSIT); + RequestModes modes = RequestModes.defaultRequestModes(); checkTriangleInequality(modes); } @Test public void testTriangleInequalityWalkBikeMultiSPT() { - TraverseModeSet modes = new TraverseModeSet(TraverseMode.WALK, TraverseMode.BICYCLE); + RequestModes modes = RequestModes + .defaultRequestModes() + .copy() + .withDirectMode(BIKE) + .clearTransitModes() + .build(); checkTriangleInequality(modes); } @@ -186,7 +220,7 @@ private void checkTriangleInequality() { checkTriangleInequality(null); } - private void checkTriangleInequality(TraverseModeSet traverseModes) { + private void checkTriangleInequality(RequestModes modes) { assertNotNull(start); assertNotNull(end); @@ -202,8 +236,8 @@ private void checkTriangleInequality(TraverseModeSet traverseModes) { graph.setIntersectionTraversalCostModel(new ConstantIntersectionTraversalCostModel(10.0)); - if (traverseModes != null) { - prototypeOptions.setStreetSubRequestModes(traverseModes); + if (modes != null) { + prototypeOptions.modes = modes; } ShortestPathTree tree = AStarBuilder diff --git a/src/test/java/org/opentripplanner/mmri/PreferencesTest.java b/src/test/java/org/opentripplanner/mmri/PreferencesTest.java index 7500fed0413..4f78150906f 100644 --- a/src/test/java/org/opentripplanner/mmri/PreferencesTest.java +++ b/src/test/java/org/opentripplanner/mmri/PreferencesTest.java @@ -1,13 +1,14 @@ package org.opentripplanner.mmri; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.opentripplanner.routing.core.TraverseMode.BUS; +import static org.opentripplanner.transit.model.basic.TransitMode.BUS; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.opentripplanner.GtfsTest; import org.opentripplanner.model.plan.Itinerary; import org.opentripplanner.model.plan.Leg; +import org.opentripplanner.transit.model.basic.TransitMode; public class PreferencesTest extends GtfsTest { diff --git a/src/test/java/org/opentripplanner/model/plan/ItineraryTest.java b/src/test/java/org/opentripplanner/model/plan/ItineraryTest.java index 8306d34a8f7..62c2558147c 100644 --- a/src/test/java/org/opentripplanner/model/plan/ItineraryTest.java +++ b/src/test/java/org/opentripplanner/model/plan/ItineraryTest.java @@ -2,7 +2,6 @@ import static java.time.Duration.ZERO; import static java.time.Duration.ofMinutes; -import static java.time.Duration.ofSeconds; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotSame; @@ -12,7 +11,6 @@ import java.time.Duration; import org.junit.jupiter.api.Test; -import org.opentripplanner.routing.core.TraverseMode; import org.opentripplanner.transit.model._data.TransitModelForTest; public class ItineraryTest implements PlanTestConstants { @@ -34,7 +32,7 @@ public void testDerivedFieldsWithWalkingOnly() { assertSameLocation(A, result.firstLeg().getFrom()); assertEquals(newTime(T11_00), result.firstLeg().getStartTime()); assertEquals(newTime(T11_05), result.firstLeg().getEndTime()); - assertEquals(TraverseMode.WALK, result.firstLeg().getMode()); + assertEquals(LegMode.WALK, result.firstLeg().getMode()); assertEquals(420.0d, result.firstLeg().getDistanceMeters(), 1E-3); assertSameLocation(B, result.lastLeg().getTo()); @@ -58,7 +56,7 @@ public void testDerivedFieldsWithBusAllTheWay() { assertSameLocation(B, result.firstLeg().getTo()); assertEquals(newTime(T11_00), result.firstLeg().getStartTime()); assertEquals(newTime(T11_10), result.firstLeg().getEndTime()); - assertEquals(TraverseMode.BUS, result.firstLeg().getMode()); + assertEquals(LegMode.BUS, result.firstLeg().getMode()); assertEquals(TransitModelForTest.id("55"), result.firstLeg().getTrip().getId()); assertEquals(7500, result.firstLeg().getDistanceMeters(), 1E-3); @@ -82,7 +80,7 @@ public void testDerivedFieldsWithTrainAllTheWay() { assertSameLocation(B, result.firstLeg().getTo()); assertEquals(newTime(T11_05), result.firstLeg().getStartTime()); assertEquals(newTime(T11_15), result.firstLeg().getEndTime()); - assertEquals(TraverseMode.RAIL, result.firstLeg().getMode()); + assertEquals(LegMode.RAIL, result.firstLeg().getMode()); assertEquals(TransitModelForTest.id("20"), result.firstLeg().getTrip().getId()); assertEquals(15_000, result.firstLeg().getDistanceMeters(), 1E-3); diff --git a/src/test/java/org/opentripplanner/model/plan/TestItineraryBuilder.java b/src/test/java/org/opentripplanner/model/plan/TestItineraryBuilder.java index f14b59f2e12..e49ddc808fa 100644 --- a/src/test/java/org/opentripplanner/model/plan/TestItineraryBuilder.java +++ b/src/test/java/org/opentripplanner/model/plan/TestItineraryBuilder.java @@ -1,9 +1,9 @@ package org.opentripplanner.model.plan; import static java.time.ZoneOffset.UTC; -import static org.opentripplanner.routing.core.TraverseMode.BICYCLE; -import static org.opentripplanner.routing.core.TraverseMode.CAR; -import static org.opentripplanner.routing.core.TraverseMode.WALK; +import static org.opentripplanner.model.plan.LegMode.BICYCLE; +import static org.opentripplanner.model.plan.LegMode.CAR; +import static org.opentripplanner.model.plan.LegMode.WALK; import static org.opentripplanner.transit.model._data.TransitModelForTest.FEED_ID; import static org.opentripplanner.transit.model._data.TransitModelForTest.route; @@ -392,7 +392,7 @@ private TestItineraryBuilder transit( return this; } - private Leg streetLeg(TraverseMode mode, int startTime, int endTime, Place to, int legCost) { + private Leg streetLeg(LegMode mode, int startTime, int endTime, Place to, int legCost) { StreetLeg leg = StreetLeg .create() .withMode(mode) @@ -415,21 +415,15 @@ private Leg streetLeg(TraverseMode mode, int startTime, int endTime, Place to, i return leg; } - private double speed(TraverseMode mode) { - switch (mode) { - case WALK: - return WALK_SPEED; - case BICYCLE: - return BICYCLE_SPEED; - case BUS: - return BUS_SPEED; - case RAIL: - return RAIL_SPEED; - case CAR: - return CAR_SPEED; - default: - throw new IllegalStateException("Unsupported mode: " + mode); - } + private double speed(LegMode mode) { + return switch (mode) { + case WALK -> WALK_SPEED; + case BICYCLE -> BICYCLE_SPEED; + case BUS -> BUS_SPEED; + case RAIL -> RAIL_SPEED; + case CAR -> CAR_SPEED; + default -> throw new IllegalStateException("Unsupported mode: " + mode); + }; } private int cost(float reluctance, int durationSeconds) { diff --git a/src/test/java/org/opentripplanner/routing/TestHalfEdges.java b/src/test/java/org/opentripplanner/routing/TestHalfEdges.java index 2a0d1da7977..2a77a5d51f0 100644 --- a/src/test/java/org/opentripplanner/routing/TestHalfEdges.java +++ b/src/test/java/org/opentripplanner/routing/TestHalfEdges.java @@ -286,7 +286,7 @@ public void testHalfEdges() { * that (b) it is not preferred to riding a tiny bit longer. */ - options = new RouteRequest(new TraverseModeSet(TraverseMode.BICYCLE)); + options = new RouteRequest(TraverseMode.BICYCLE); start = StreetVertexIndex.createTemporaryStreetLocationForTest( "start1", @@ -589,7 +589,7 @@ public void testStreetLocationFinder() { Collection edges = start.getOutgoing(); assertEquals(2, edges.size()); - RouteRequest biking = new RouteRequest(new TraverseModeSet(TraverseMode.BICYCLE)); + RouteRequest biking = new RouteRequest(TraverseMode.BICYCLE); TemporaryStreetLocation end = (TemporaryStreetLocation) finder.getVertexForLocationForTest( new GenericLocation(40.008, -74.0), biking, diff --git a/src/test/java/org/opentripplanner/routing/algorithm/GraphRoutingTest.java b/src/test/java/org/opentripplanner/routing/algorithm/GraphRoutingTest.java index f0ae63eb78a..9ef7088cea8 100644 --- a/src/test/java/org/opentripplanner/routing/algorithm/GraphRoutingTest.java +++ b/src/test/java/org/opentripplanner/routing/algorithm/GraphRoutingTest.java @@ -3,17 +3,10 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; -import java.util.stream.Stream; import org.locationtech.jts.geom.Coordinate; import org.opentripplanner.TestOtpModel; import org.opentripplanner.model.PickDrop; import org.opentripplanner.model.StopTime; -import org.opentripplanner.routing.algorithm.astar.AStarBuilder; -import org.opentripplanner.routing.api.request.RouteRequest; -import org.opentripplanner.routing.core.RoutingContext; -import org.opentripplanner.routing.core.TraverseModeSet; import org.opentripplanner.routing.edgetype.ElevatorAlightEdge; import org.opentripplanner.routing.edgetype.ElevatorBoardEdge; import org.opentripplanner.routing.edgetype.ElevatorEdge; @@ -31,7 +24,6 @@ import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.routing.graph.Vertex; import org.opentripplanner.routing.location.TemporaryStreetLocation; -import org.opentripplanner.routing.spt.GraphPath; import org.opentripplanner.routing.vehicle_parking.VehicleParking; import org.opentripplanner.routing.vehicle_parking.VehicleParking.VehicleParkingEntranceCreator; import org.opentripplanner.routing.vehicle_parking.VehicleParkingHelper; @@ -68,19 +60,6 @@ public abstract class GraphRoutingTest { public static final String TEST_VEHICLE_RENTAL_NETWORK = "test network"; - public static String graphPathToString(GraphPath graphPath) { - return graphPath.states - .stream() - .flatMap(s -> - Stream.of( - s.getBackEdge() != null ? s.getBackEdge().getDefaultName() : null, - s.getVertex().getDefaultName() - ) - ) - .filter(Objects::nonNull) - .collect(Collectors.joining(" - ")); - } - protected TestOtpModel modelOf(Builder builder) { builder.build(); Graph graph = builder.graph(); @@ -88,19 +67,6 @@ protected TestOtpModel modelOf(Builder builder) { return new TestOtpModel(graph, transitModel).index(); } - protected GraphPath routeParkAndRide( - Graph graph, - StreetVertex from, - StreetVertex to, - TraverseModeSet traverseModeSet - ) { - RouteRequest request = new RouteRequest(traverseModeSet); - RoutingContext rctx = new RoutingContext(request, graph, from, to); - request.parkAndRide = true; - - return AStarBuilder.oneToOne().setContext(rctx).getShortestPathTree().getPath(to); - } - public abstract static class Builder { private final Graph graph; @@ -317,10 +283,6 @@ public TemporaryFreeEdge link(StreetVertex from, TemporaryVertex to) { return new TemporaryFreeEdge(from, to); } - public List biLink(StreetVertex from, TemporaryVertex to) { - return List.of(link(from, to), link(to, from)); - } - // -- Vehicle rental public VehicleRentalPlace vehicleRentalStationEntity( String id, diff --git a/src/test/java/org/opentripplanner/routing/core/TraverseModeSetTest.java b/src/test/java/org/opentripplanner/routing/core/TraverseModeSetTest.java index bcc389de038..62a99d960fe 100644 --- a/src/test/java/org/opentripplanner/routing/core/TraverseModeSetTest.java +++ b/src/test/java/org/opentripplanner/routing/core/TraverseModeSetTest.java @@ -1,6 +1,7 @@ package org.opentripplanner.routing.core; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; @@ -12,15 +13,8 @@ public void testCarMode() { TraverseModeSet modeSet = new TraverseModeSet(TraverseMode.CAR); assertTrue(modeSet.getCar()); - assertFalse(modeSet.isTransit()); - assertFalse(modeSet.getRail()); - assertFalse(modeSet.getTram()); - assertFalse(modeSet.getSubway()); - assertFalse(modeSet.getFunicular()); - assertFalse(modeSet.getGondola()); assertFalse(modeSet.getWalk()); assertFalse(modeSet.getBicycle()); - assertFalse(modeSet.getTrolleyBus()); } @Test @@ -29,14 +23,7 @@ public void testWalkMode() { assertTrue(modeSet.getWalk()); assertFalse(modeSet.getCar()); - assertFalse(modeSet.isTransit()); - assertFalse(modeSet.getRail()); - assertFalse(modeSet.getTram()); - assertFalse(modeSet.getSubway()); - assertFalse(modeSet.getFunicular()); - assertFalse(modeSet.getGondola()); assertFalse(modeSet.getBicycle()); - assertFalse(modeSet.getTrolleyBus()); } @Test @@ -46,46 +33,6 @@ public void testBikeMode() { assertTrue(modeSet.getBicycle()); assertFalse(modeSet.getWalk()); assertFalse(modeSet.getCar()); - assertFalse(modeSet.isTransit()); - assertFalse(modeSet.getRail()); - assertFalse(modeSet.getTram()); - assertFalse(modeSet.getSubway()); - assertFalse(modeSet.getFunicular()); - assertFalse(modeSet.getGondola()); assertFalse(modeSet.getWalk()); - assertFalse(modeSet.getTrolleyBus()); - } - - @Test - public void testTrolleyMode() { - TraverseModeSet modeSet = new TraverseModeSet(TraverseMode.TROLLEYBUS); - - assertFalse(modeSet.getBicycle()); - assertFalse(modeSet.getWalk()); - assertFalse(modeSet.getCar()); - assertTrue(modeSet.isTransit()); - assertFalse(modeSet.getRail()); - assertFalse(modeSet.getTram()); - assertFalse(modeSet.getSubway()); - assertFalse(modeSet.getFunicular()); - assertFalse(modeSet.getGondola()); - assertFalse(modeSet.getWalk()); - assertTrue(modeSet.getTrolleyBus()); - } - - @Test - public void testTransitMode() { - TraverseModeSet modeSet = new TraverseModeSet(TraverseMode.TRANSIT); - - assertFalse(modeSet.getBicycle()); - assertFalse(modeSet.getWalk()); - assertFalse(modeSet.getCar()); - assertTrue(modeSet.isTransit()); - assertTrue(modeSet.getRail()); - assertTrue(modeSet.getTram()); - assertTrue(modeSet.getSubway()); - assertTrue(modeSet.getFunicular()); - assertTrue(modeSet.getGondola()); - assertTrue(modeSet.getTrolleyBus()); } } diff --git a/src/test/java/org/opentripplanner/routing/edgetype/StreetTraversalPermissionTest.java b/src/test/java/org/opentripplanner/routing/edgetype/StreetTraversalPermissionTest.java index 2cf81dc3061..5d08e6c5ea1 100644 --- a/src/test/java/org/opentripplanner/routing/edgetype/StreetTraversalPermissionTest.java +++ b/src/test/java/org/opentripplanner/routing/edgetype/StreetTraversalPermissionTest.java @@ -42,20 +42,15 @@ public void testAllowsTraverseMode() { StreetTraversalPermission perm1 = StreetTraversalPermission.ALL; assertTrue(perm1.allows(TraverseMode.CAR)); assertTrue(perm1.allows(TraverseMode.WALK)); - - // StreetTraversalPermission is not used for public transit. - assertFalse(perm1.allows(TraverseMode.TRANSIT)); } @Test public void testAllowsTraverseModeSet() { - StreetTraversalPermission perm1 = StreetTraversalPermission.BICYCLE_AND_CAR; - assertTrue(perm1.allows(TraverseModeSet.allModes())); - assertTrue(perm1.allows(new TraverseModeSet(TraverseMode.CAR, TraverseMode.BICYCLE))); - assertTrue( - perm1.allows(new TraverseModeSet(TraverseMode.BICYCLE, TraverseMode.RAIL, TraverseMode.FERRY)) - ); - assertFalse(perm1.allows(new TraverseModeSet(TraverseMode.WALK))); + StreetTraversalPermission perm = StreetTraversalPermission.BICYCLE_AND_CAR; + assertTrue(perm.allows(TraverseModeSet.allModes())); + assertTrue(perm.allows(new TraverseModeSet(TraverseMode.CAR, TraverseMode.BICYCLE))); + assertTrue(perm.allows(new TraverseModeSet(TraverseMode.BICYCLE))); + assertFalse(perm.allows(new TraverseModeSet(TraverseMode.WALK))); } @Test diff --git a/src/test/java/org/opentripplanner/routing/edgetype/loader/GeometryProcessorTest.java b/src/test/java/org/opentripplanner/routing/edgetype/loader/GeometryProcessorTest.java index 3feb23fa652..9a4d5a1fafe 100644 --- a/src/test/java/org/opentripplanner/routing/edgetype/loader/GeometryProcessorTest.java +++ b/src/test/java/org/opentripplanner/routing/edgetype/loader/GeometryProcessorTest.java @@ -333,7 +333,6 @@ public void testFrequencies() { GraphPath path; RouteRequest options = new RouteRequest(); - options.setStreetSubRequestModes(new TraverseModeSet(TraverseMode.TRANSIT)); options.setDateTime(TestUtils.dateInstant("America/New_York", 2009, 8, 7, 0, 0, 0)); // U to V - original stop times - shouldn't be used diff --git a/src/test/java/org/opentripplanner/routing/street/BarrierRoutingTest.java b/src/test/java/org/opentripplanner/routing/street/BarrierRoutingTest.java index 72b53a91d9b..751b495570d 100644 --- a/src/test/java/org/opentripplanner/routing/street/BarrierRoutingTest.java +++ b/src/test/java/org/opentripplanner/routing/street/BarrierRoutingTest.java @@ -22,6 +22,7 @@ import org.opentripplanner.TestOtpModel; import org.opentripplanner.model.GenericLocation; import org.opentripplanner.model.plan.Itinerary; +import org.opentripplanner.model.plan.LegMode; import org.opentripplanner.model.plan.WalkStep; import org.opentripplanner.routing.algorithm.mapping.GraphPathToItineraryMapper; import org.opentripplanner.routing.api.request.RouteRequest; @@ -73,7 +74,7 @@ public void shouldWalkForBarriers() { .flatMap(i -> Stream.of( () -> assertEquals(1, i.getLegs().size()), - () -> assertEquals(BICYCLE, i.getLegs().get(0).getMode()), + () -> assertEquals(LegMode.BICYCLE, i.getLegs().get(0).getMode()), () -> assertEquals( List.of(false, true, false, true, false), @@ -141,7 +142,12 @@ private static String computePolyline( .stream() .flatMap(i -> i.getLegs().stream()) .map(l -> - () -> assertEquals(traverseMode, l.getMode(), "Allow only " + traverseMode + " legs") + () -> + assertEquals( + LegMode.fromAStarTraverseMode(traverseMode), + l.getMode(), + "Allow only " + traverseMode + " legs" + ) ) ); } diff --git a/src/test/java/org/opentripplanner/routing/street/BicycleRoutingTest.java b/src/test/java/org/opentripplanner/routing/street/BicycleRoutingTest.java index 6a6c393e275..a602b66528e 100644 --- a/src/test/java/org/opentripplanner/routing/street/BicycleRoutingTest.java +++ b/src/test/java/org/opentripplanner/routing/street/BicycleRoutingTest.java @@ -11,6 +11,7 @@ import org.opentripplanner.ConstantsForTests; import org.opentripplanner.TestOtpModel; import org.opentripplanner.model.GenericLocation; +import org.opentripplanner.model.plan.LegMode; import org.opentripplanner.routing.algorithm.mapping.GraphPathToItineraryMapper; import org.opentripplanner.routing.api.request.RouteRequest; import org.opentripplanner.routing.core.BicycleOptimizeType; @@ -92,7 +93,7 @@ private static String computePolyline(Graph graph, GenericLocation from, Generic // make sure that we only get BICYLE legs itineraries.forEach(i -> - i.getLegs().forEach(l -> Assertions.assertEquals(l.getMode(), TraverseMode.BICYCLE)) + i.getLegs().forEach(l -> Assertions.assertEquals(LegMode.BICYCLE, l.getMode())) ); Geometry legGeometry = itineraries.get(0).getLegs().get(0).getLegGeometry(); return PolylineEncoder.encodeGeometry(legGeometry).points(); diff --git a/src/test/java/org/opentripplanner/routing/street/CarRoutingTest.java b/src/test/java/org/opentripplanner/routing/street/CarRoutingTest.java index b060a6ae6cc..6e5a2fa6e1e 100644 --- a/src/test/java/org/opentripplanner/routing/street/CarRoutingTest.java +++ b/src/test/java/org/opentripplanner/routing/street/CarRoutingTest.java @@ -13,6 +13,7 @@ import org.opentripplanner.ConstantsForTests; import org.opentripplanner.TestOtpModel; import org.opentripplanner.model.GenericLocation; +import org.opentripplanner.model.plan.LegMode; import org.opentripplanner.routing.algorithm.mapping.GraphPathToItineraryMapper; import org.opentripplanner.routing.api.request.RouteRequest; import org.opentripplanner.routing.core.RoutingContext; @@ -145,7 +146,7 @@ private static String computePolyline(Graph graph, GenericLocation from, Generic // make sure that we only get CAR legs itineraries.forEach(i -> - i.getLegs().forEach(l -> Assertions.assertEquals(l.getMode(), TraverseMode.CAR)) + i.getLegs().forEach(l -> Assertions.assertEquals(LegMode.CAR, l.getMode())) ); Geometry legGeometry = itineraries.get(0).getLegs().get(0).getLegGeometry(); return PolylineEncoder.encodeGeometry(legGeometry).points(); diff --git a/src/test/java/org/opentripplanner/routing/street/SplitEdgeTurnRestrictionsTest.java b/src/test/java/org/opentripplanner/routing/street/SplitEdgeTurnRestrictionsTest.java index 11a4779f89f..349eec06492 100644 --- a/src/test/java/org/opentripplanner/routing/street/SplitEdgeTurnRestrictionsTest.java +++ b/src/test/java/org/opentripplanner/routing/street/SplitEdgeTurnRestrictionsTest.java @@ -11,6 +11,7 @@ import org.opentripplanner.ConstantsForTests; import org.opentripplanner.TestOtpModel; import org.opentripplanner.model.GenericLocation; +import org.opentripplanner.model.plan.LegMode; import org.opentripplanner.routing.algorithm.mapping.GraphPathToItineraryMapper; import org.opentripplanner.routing.api.request.RouteRequest; import org.opentripplanner.routing.core.RoutingContext; @@ -165,7 +166,7 @@ private static String computeCarPolyline(Graph graph, GenericLocation from, Gene // make sure that we only get CAR legs itineraries.forEach(i -> - i.getLegs().forEach(l -> Assertions.assertEquals(l.getMode(), TraverseMode.CAR)) + i.getLegs().forEach(l -> Assertions.assertEquals(LegMode.CAR, l.getMode())) ); Geometry geometry = itineraries.get(0).getLegs().get(0).getLegGeometry(); return PolylineEncoder.encodeGeometry(geometry).points(); diff --git a/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/CsvFileIO.java b/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/CsvFileIO.java index 5b3a6519681..412e91f573e 100644 --- a/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/CsvFileIO.java +++ b/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/CsvFileIO.java @@ -18,7 +18,7 @@ import java.util.stream.Collectors; import org.opentripplanner.api.parameter.QualifiedModeSet; import org.opentripplanner.model.GenericLocation; -import org.opentripplanner.routing.core.TraverseMode; +import org.opentripplanner.model.plan.LegMode; import org.opentripplanner.transit.model.framework.FeedScopedId; import org.opentripplanner.util.time.DurationUtils; import org.opentripplanner.util.time.TimeUtils; @@ -258,7 +258,7 @@ private Result readExpectedResult(CsvReader csvReader) throws IOException { parseTime(csvReader.get("startTime")), parseTime(csvReader.get("endTime")), str2Col(csvReader.get("agencies")), - str2Col(csvReader.get("modes"), TraverseMode::valueOf), + str2Col(csvReader.get("modes"), LegMode::valueOf), str2Col(csvReader.get("routes")), str2Col(csvReader.get("stops")), csvReader.get("details") diff --git a/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/ItineraryResultMapper.java b/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/ItineraryResultMapper.java index 0fc9802cdf6..82461bfa31a 100644 --- a/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/ItineraryResultMapper.java +++ b/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/ItineraryResultMapper.java @@ -12,7 +12,7 @@ import java.util.stream.Collectors; import org.opentripplanner.model.plan.Itinerary; import org.opentripplanner.model.plan.Leg; -import org.opentripplanner.routing.core.TraverseMode; +import org.opentripplanner.model.plan.LegMode; import org.opentripplanner.transit.model.organization.Agency; import org.opentripplanner.transit.model.site.StopLocation; import org.opentripplanner.transit.raptor.api.path.PathStringBuilder; @@ -113,7 +113,7 @@ private static String agencyShortName(Agency agency) { private Result map(Itinerary itinerary) { List agencies = new ArrayList<>(); List routes = new ArrayList<>(); - Set modes = EnumSet.noneOf(TraverseMode.class); + Set modes = EnumSet.noneOf(LegMode.class); List stops = new ArrayList<>(); for (Leg it : itinerary.getLegs()) { diff --git a/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/Result.java b/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/Result.java index 48bd7d0e64a..c743a651160 100644 --- a/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/Result.java +++ b/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/Result.java @@ -4,7 +4,7 @@ import java.util.Collection; import java.util.Comparator; import java.util.List; -import org.opentripplanner.routing.core.TraverseMode; +import org.opentripplanner.model.plan.LegMode; import org.opentripplanner.util.CompositeComparator; import org.opentripplanner.util.time.DurationUtils; import org.opentripplanner.util.time.TimeUtils; @@ -33,7 +33,7 @@ class Result { /** Alphabetical distinct list of agencies. A {@code List} is used because the order is important. */ final List agencies; /** Alphabetical distinct list of modes. A {@code List} is used because the order is important. */ - final List modes; + final List modes; /** A list of routes in tha same order as they appear in the journey. */ final List routes; /** A list of stops in tha same order as they appear in the journey. */ @@ -53,7 +53,7 @@ class Result { Integer startTime, Integer endTime, Collection agencies, - Collection modes, + Collection modes, Collection routes, Collection stops, String details From 9bd8ea5e02d559a3ea2ea93c69074add3dc319c4 Mon Sep 17 00:00:00 2001 From: Thomas Gran Date: Tue, 13 Sep 2022 20:11:01 +0200 Subject: [PATCH 3/7] refactor: Drop LegMode, and used domain TransitMode and TraverseMode --- .../ext/flex/FlexIntegrationTest.java | 26 +++---- .../ext/fares/impl/NycFareServiceImpl.java | 25 +++---- .../ext/fares/impl/SFBayFareServiceImpl.java | 6 +- .../ext/flex/FlexibleTransitLeg.java | 16 ++--- .../datafetchers/LegacyGraphQLLegImpl.java | 13 +++- .../ext/transmodelapi/model/EnumTypes.java | 34 ++++----- .../ext/transmodelapi/model/plan/LegType.java | 20 +++++- .../api/mapping/LegMapper.java | 23 +++--- .../api/mapping/ModeMapper.java | 47 +++++++------ .../opentripplanner/model/plan/Itinerary.java | 36 +++++++--- .../org/opentripplanner/model/plan/Leg.java | 13 ++-- .../opentripplanner/model/plan/LegMode.java | 70 ------------------- .../model/plan/ScheduledTransitLeg.java | 14 ++-- .../opentripplanner/model/plan/StreetLeg.java | 21 +++--- .../model/plan/StreetLegBuilder.java | 7 +- .../model/plan/TransitLeg.java | 22 ++++++ ...moveBikerentalWithMostlyWalkingFilter.java | 2 +- ...oveParkAndRideWithMostlyWalkingFilter.java | 9 ++- .../filterchain/groupids/GroupByDistance.java | 11 ++- .../mapping/GraphPathToItineraryMapper.java | 14 ++-- .../mapping/RaptorPathToItineraryMapper.java | 11 +-- .../transit/model/framework/FeedScopedId.java | 6 +- .../raptor/api/path/PathStringBuilder.java | 2 +- .../model/plan/ItineraryTest.java | 8 ++- .../model/plan/TestItineraryBuilder.java | 20 ++++-- .../groupids/GroupByDistanceTest.java | 4 +- .../algorithm/mapping/SnapshotTestBase.java | 5 +- .../routing/street/BarrierRoutingTest.java | 8 +-- .../routing/street/BicycleRoutingTest.java | 17 +++-- .../routing/street/CarRoutingTest.java | 15 +++- .../street/SplitEdgeTurnRestrictionsTest.java | 15 +++- .../speed_test/model/testcase/CsvFileIO.java | 16 ++++- .../model/testcase/ItineraryResultMapper.java | 18 +++-- .../speed_test/model/testcase/Result.java | 11 +-- 34 files changed, 331 insertions(+), 254 deletions(-) delete mode 100644 src/main/java/org/opentripplanner/model/plan/LegMode.java create mode 100644 src/main/java/org/opentripplanner/model/plan/TransitLeg.java diff --git a/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTest.java b/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTest.java index 6f909c1cd7c..baf3056bdd6 100644 --- a/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTest.java +++ b/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTest.java @@ -5,9 +5,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.opentripplanner.graph_builder.DataImportIssueStore.noopIssueStore; import static org.opentripplanner.graph_builder.module.FakeGraph.getFileForResource; -import static org.opentripplanner.model.plan.LegMode.BUS; -import static org.opentripplanner.model.plan.LegMode.WALK; import static org.opentripplanner.routing.api.request.StreetMode.FLEXIBLE; +import static org.opentripplanner.routing.core.TraverseMode.WALK; +import static org.opentripplanner.transit.model.basic.TransitMode.BUS; import java.io.File; import java.net.URISyntaxException; @@ -80,17 +80,17 @@ void shouldReturnARouteTransferringFromBusToFlex() { assertEquals(4, itin.getLegs().size()); - var walkToBus = itin.getLegs().get(0); + var walkToBus = itin.getStreetLeg(0); assertEquals(WALK, walkToBus.getMode()); - var bus = itin.getLegs().get(1); + var bus = itin.getTransitLeg(1); assertEquals(BUS, bus.getMode()); assertEquals("30", bus.getRoute().getShortName()); - var transfer = itin.getLegs().get(2); + var transfer = itin.getStreetLeg(2); assertEquals(WALK, transfer.getMode()); - var flex = itin.getLegs().get(3); + var flex = itin.getTransitLeg(3); assertEquals(BUS, flex.getMode()); assertEquals("Zone 2", flex.getRoute().getShortName()); assertTrue(flex.isFlexibleTrip()); @@ -110,21 +110,21 @@ void shouldReturnARouteWithTwoTransfers() { assertEquals(5, itin.getLegs().size()); - var firstBus = itin.getLegs().get(0); + var firstBus = itin.getTransitLeg(0); assertEquals(BUS, firstBus.getMode()); assertEquals("856", firstBus.getRoute().getShortName()); - var transferToSecondBus = itin.getLegs().get(1); + var transferToSecondBus = itin.getStreetLeg(1); assertEquals(WALK, transferToSecondBus.getMode()); - var secondBus = itin.getLegs().get(2); + var secondBus = itin.getTransitLeg(2); assertEquals(BUS, secondBus.getMode()); assertEquals("30", secondBus.getRoute().getShortName()); - var transferToFlex = itin.getLegs().get(3); + var transferToFlex = itin.getStreetLeg(3); assertEquals(WALK, transferToFlex.getMode()); - var finalFlex = itin.getLegs().get(4); + var finalFlex = itin.getTransitLeg(4); assertEquals(BUS, finalFlex.getMode()); assertEquals("Zone 2", finalFlex.getRoute().getShortName()); assertTrue(finalFlex.isFlexibleTrip()); @@ -144,10 +144,10 @@ void flexDirect() { assertEquals("2021-12-02T12:53:12-05:00[America/New_York]", itin.startTime().toString()); assertEquals(3173, itin.getGeneralizedCost()); - var walkToFlex = itin.getLegs().get(0); + var walkToFlex = itin.getStreetLeg(0); assertEquals(WALK, walkToFlex.getMode()); - var flex = itin.getLegs().get(1); + var flex = itin.getTransitLeg(1); assertEquals(BUS, flex.getMode()); assertEquals("Zone 2", flex.getRoute().getShortName()); assertTrue(flex.isFlexibleTrip()); diff --git a/src/ext/java/org/opentripplanner/ext/fares/impl/NycFareServiceImpl.java b/src/ext/java/org/opentripplanner/ext/fares/impl/NycFareServiceImpl.java index aad23142263..80996420952 100644 --- a/src/ext/java/org/opentripplanner/ext/fares/impl/NycFareServiceImpl.java +++ b/src/ext/java/org/opentripplanner/ext/fares/impl/NycFareServiceImpl.java @@ -12,6 +12,7 @@ import java.util.stream.Stream; import org.opentripplanner.model.plan.Itinerary; import org.opentripplanner.model.plan.Leg; +import org.opentripplanner.model.plan.TransitLeg; import org.opentripplanner.routing.core.FareType; import org.opentripplanner.routing.core.ItineraryFares; import org.opentripplanner.routing.core.Money; @@ -339,8 +340,8 @@ private static Ride mapToRide(Itinerary itinerary, Leg leg) { Ride ride = new Ride(); ride.classifier = NycRideClassifier.WALK; return ride; - } else if (leg.isTransitLeg()) { - Ride ride = rideForTransitPathLeg(leg); + } else if (leg instanceof TransitLeg transitLeg) { + Ride ride = rideForTransitPathLeg(transitLeg); Route route = leg.getRoute(); int routeType = route.getGtfsType(); @@ -387,15 +388,15 @@ private static List makeMtaStopList(String... stops) { return out; } - private static Ride rideForTransitPathLeg(Leg leg) { + private static Ride rideForTransitPathLeg(TransitLeg transitLeg) { Ride ride = new Ride(); - ride.firstStop = leg.getFrom().stop; - ride.lastStop = leg.getTo().stop; + ride.firstStop = transitLeg.getFrom().stop; + ride.lastStop = transitLeg.getTo().stop; ride.startZone = ride.firstStop.getFirstZoneAsString(); ride.endZone = ride.lastStop.getFirstZoneAsString(); - var zones = leg + var zones = transitLeg .getIntermediateStops() .stream() .map(stopArrival -> stopArrival.place.stop.getFirstZoneAsString()) @@ -406,15 +407,15 @@ private static Ride rideForTransitPathLeg(Leg leg) { ); ride.zones = zones; - ride.agency = leg.getRoute().getAgency().getId(); - ride.route = leg.getRoute().getId(); - ride.trip = leg.getTrip().getId(); + ride.agency = transitLeg.getRoute().getAgency().getId(); + ride.route = transitLeg.getRoute().getId(); + ride.trip = transitLeg.getTrip().getId(); - ride.startTime = leg.getStartTime(); - ride.endTime = leg.getEndTime(); + ride.startTime = transitLeg.getStartTime(); + ride.endTime = transitLeg.getEndTime(); // In the default fare service, we classify rides by mode. - ride.classifier = leg.getMode(); + ride.classifier = transitLeg.getMode(); return ride; } diff --git a/src/ext/java/org/opentripplanner/ext/fares/impl/SFBayFareServiceImpl.java b/src/ext/java/org/opentripplanner/ext/fares/impl/SFBayFareServiceImpl.java index caf105d912c..2dde24615a8 100644 --- a/src/ext/java/org/opentripplanner/ext/fares/impl/SFBayFareServiceImpl.java +++ b/src/ext/java/org/opentripplanner/ext/fares/impl/SFBayFareServiceImpl.java @@ -9,9 +9,10 @@ import java.util.Set; import org.opentripplanner.ext.fares.model.FareRuleSet; import org.opentripplanner.model.plan.Leg; -import org.opentripplanner.model.plan.LegMode; +import org.opentripplanner.model.plan.TransitLeg; import org.opentripplanner.routing.core.FareType; import org.opentripplanner.routing.core.ItineraryFares; +import org.opentripplanner.transit.model.basic.TransitMode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,7 +64,8 @@ protected float getLowestCost( bartBlock = null; } if (agencyId.equals("SFMTA")) { - if (ride.getMode().equals(LegMode.CABLE_CAR)) { + TransitMode mode = (ride instanceof TransitLeg transitLeg) ? transitLeg.getMode() : null; + if (mode == TransitMode.CABLE_CAR) { // no transfers issued or accepted cost += CABLE_CAR_FARE; } else if ( diff --git a/src/ext/java/org/opentripplanner/ext/flex/FlexibleTransitLeg.java b/src/ext/java/org/opentripplanner/ext/flex/FlexibleTransitLeg.java index cc91c68bbd3..94180290f73 100644 --- a/src/ext/java/org/opentripplanner/ext/flex/FlexibleTransitLeg.java +++ b/src/ext/java/org/opentripplanner/ext/flex/FlexibleTransitLeg.java @@ -6,15 +6,17 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import javax.annotation.Nonnull; import org.locationtech.jts.geom.LineString; import org.opentripplanner.ext.flex.edgetype.FlexTripEdge; import org.opentripplanner.model.BookingInfo; import org.opentripplanner.model.PickDrop; import org.opentripplanner.model.plan.Leg; -import org.opentripplanner.model.plan.LegMode; import org.opentripplanner.model.plan.Place; import org.opentripplanner.model.plan.StopArrival; +import org.opentripplanner.model.plan.TransitLeg; import org.opentripplanner.routing.alertpatch.TransitAlert; +import org.opentripplanner.transit.model.basic.TransitMode; import org.opentripplanner.transit.model.basic.WheelchairAccessibility; import org.opentripplanner.transit.model.framework.AbstractTransitEntity; import org.opentripplanner.transit.model.network.Route; @@ -28,7 +30,7 @@ * One leg of a trip -- that is, a temporally continuous piece of the journey that takes place on a * particular vehicle, which is running on flexible trip, i.e. not using fixed schedule and stops. */ -public class FlexibleTransitLeg implements Leg { +public class FlexibleTransitLeg implements TransitLeg { private final FlexTripEdge edge; @@ -54,11 +56,6 @@ public FlexibleTransitLeg( this.generalizedCost = generalizedCost; } - @Override - public boolean isTransitLeg() { - return true; - } - @Override public Agency getAgency() { return getTrip().getRoute().getAgency(); @@ -85,8 +82,9 @@ public WheelchairAccessibility getTripWheelchairAccessibility() { } @Override - public LegMode getMode() { - return LegMode.fromTransitMode(getTrip().getMode()); + @Nonnull + public TransitMode getMode() { + return getTrip().getMode(); } @Override diff --git a/src/ext/java/org/opentripplanner/ext/legacygraphqlapi/datafetchers/LegacyGraphQLLegImpl.java b/src/ext/java/org/opentripplanner/ext/legacygraphqlapi/datafetchers/LegacyGraphQLLegImpl.java index 56b16a1ed30..cef3ab2efb6 100644 --- a/src/ext/java/org/opentripplanner/ext/legacygraphqlapi/datafetchers/LegacyGraphQLLegImpl.java +++ b/src/ext/java/org/opentripplanner/ext/legacygraphqlapi/datafetchers/LegacyGraphQLLegImpl.java @@ -13,6 +13,8 @@ import org.opentripplanner.model.PickDrop; import org.opentripplanner.model.plan.Leg; import org.opentripplanner.model.plan.StopArrival; +import org.opentripplanner.model.plan.StreetLeg; +import org.opentripplanner.model.plan.TransitLeg; import org.opentripplanner.model.plan.WalkStep; import org.opentripplanner.routing.RoutingService; import org.opentripplanner.transit.model.network.Route; @@ -123,7 +125,16 @@ public DataFetcher legGeometry() { @Override public DataFetcher mode() { - return environment -> getSource(environment).getMode().name(); + return environment -> { + Leg leg = getSource(environment); + if (leg instanceof StreetLeg s) { + return s.getMode().name(); + } + if (leg instanceof TransitLeg s) { + return s.getMode().name(); + } + throw new IllegalStateException("Unhandled leg type: " + leg); + }; } @Override diff --git a/src/ext/java/org/opentripplanner/ext/transmodelapi/model/EnumTypes.java b/src/ext/java/org/opentripplanner/ext/transmodelapi/model/EnumTypes.java index d2ee70a6d66..913bb9b3899 100644 --- a/src/ext/java/org/opentripplanner/ext/transmodelapi/model/EnumTypes.java +++ b/src/ext/java/org/opentripplanner/ext/transmodelapi/model/EnumTypes.java @@ -5,7 +5,6 @@ import java.util.function.Function; import org.opentripplanner.model.BookingMethod; import org.opentripplanner.model.plan.AbsoluteDirection; -import org.opentripplanner.model.plan.LegMode; import org.opentripplanner.model.plan.RelativeDirection; import org.opentripplanner.model.plan.VertexType; import org.opentripplanner.model.transfer.TransferPriority; @@ -15,6 +14,7 @@ import org.opentripplanner.routing.api.response.InputField; import org.opentripplanner.routing.api.response.RoutingErrorCode; import org.opentripplanner.routing.core.BicycleOptimizeType; +import org.opentripplanner.routing.core.TraverseMode; import org.opentripplanner.routing.stoptimes.ArrivalDeparture; import org.opentripplanner.transit.model.basic.TransitMode; import org.opentripplanner.transit.model.basic.WheelchairAccessibility; @@ -257,22 +257,22 @@ public class EnumTypes { public static GraphQLEnumType LEG_MODE = GraphQLEnumType .newEnum() .name("Mode") - .value("air", LegMode.AIRPLANE) - .value("bicycle", LegMode.BICYCLE) - .value("bus", LegMode.BUS) - .value("cableway", LegMode.CABLE_CAR) - .value("water", LegMode.FERRY) - .value("funicular", LegMode.FUNICULAR) - .value("lift", LegMode.GONDOLA) - .value("rail", LegMode.RAIL) - .value("metro", LegMode.SUBWAY) - .value("tram", LegMode.TRAM) - .value("trolleybus", LegMode.TROLLEYBUS) - .value("monorail", LegMode.MONORAIL) - .value("coach", LegMode.COACH) - .value("foot", LegMode.WALK) - .value("car", LegMode.CAR) - .value("scooter", LegMode.SCOOTER) + .value("air", TransitMode.AIRPLANE) + .value("bicycle", TraverseMode.BICYCLE) + .value("bus", TransitMode.BUS) + .value("cableway", TransitMode.CABLE_CAR) + .value("water", TransitMode.FERRY) + .value("funicular", TransitMode.FUNICULAR) + .value("lift", TransitMode.GONDOLA) + .value("rail", TransitMode.RAIL) + .value("metro", TransitMode.SUBWAY) + .value("tram", TransitMode.TRAM) + .value("trolleybus", TransitMode.TROLLEYBUS) + .value("monorail", TransitMode.MONORAIL) + .value("coach", TransitMode.COACH) + .value("foot", TraverseMode.WALK) + .value("car", TraverseMode.CAR) + .value("scooter", TraverseMode.SCOOTER) .build(); public static GraphQLEnumType TRANSPORT_MODE = GraphQLEnumType diff --git a/src/ext/java/org/opentripplanner/ext/transmodelapi/model/plan/LegType.java b/src/ext/java/org/opentripplanner/ext/transmodelapi/model/plan/LegType.java index 2b2795220cb..f5176187a27 100644 --- a/src/ext/java/org/opentripplanner/ext/transmodelapi/model/plan/LegType.java +++ b/src/ext/java/org/opentripplanner/ext/transmodelapi/model/plan/LegType.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.function.Function; import java.util.stream.Collectors; import org.opentripplanner.ext.transmodelapi.model.EnumTypes; import org.opentripplanner.ext.transmodelapi.model.TransmodelTransportSubmode; @@ -23,6 +24,8 @@ import org.opentripplanner.ext.transmodelapi.support.GqlUtil; import org.opentripplanner.model.plan.Leg; import org.opentripplanner.model.plan.StopArrival; +import org.opentripplanner.model.plan.StreetLeg; +import org.opentripplanner.model.plan.TransitLeg; import org.opentripplanner.model.plan.legreference.LegReferenceSerializer; import org.opentripplanner.routing.alternativelegs.AlternativeLegs; import org.opentripplanner.transit.model.timetable.TripIdAndServiceDate; @@ -120,7 +123,7 @@ public static GraphQLObjectType create( "The mode of transport or access (e.g., foot) used when traversing this leg." ) .type(new GraphQLNonNull(LEG_MODE)) - .dataFetcher(env -> leg(env).getMode()) + .dataFetcher(env -> onLeg(env, StreetLeg::getMode, TransitLeg::getMode)) .build() ) .field( @@ -525,4 +528,19 @@ public static GraphQLObjectType create( private static Leg leg(DataFetchingEnvironment environment) { return environment.getSource(); } + + private static Object onLeg( + DataFetchingEnvironment environment, + Function streetLegAccessor, + Function transitLegAccessor + ) { + Leg leg = leg(environment); + if (leg instanceof StreetLeg sl) { + return streetLegAccessor.apply(sl); + } + if (leg instanceof TransitLeg tl) { + return transitLegAccessor.apply(tl); + } + throw new IllegalStateException("Unhandled leg type: " + leg); + } } diff --git a/src/main/java/org/opentripplanner/api/mapping/LegMapper.java b/src/main/java/org/opentripplanner/api/mapping/LegMapper.java index cab6ed727ae..6a31e7ebf58 100644 --- a/src/main/java/org/opentripplanner/api/mapping/LegMapper.java +++ b/src/main/java/org/opentripplanner/api/mapping/LegMapper.java @@ -11,6 +11,8 @@ import org.opentripplanner.api.model.ApiLeg; import org.opentripplanner.model.PickDrop; import org.opentripplanner.model.plan.Leg; +import org.opentripplanner.model.plan.StreetLeg; +import org.opentripplanner.model.plan.TransitLeg; import org.opentripplanner.util.PolylineEncoder; public class LegMapper { @@ -89,16 +91,16 @@ public ApiLeg mapLeg( api.distance = round3Decimals(domain.getDistanceMeters()); api.generalizedCost = domain.getGeneralizedCost(); api.pathway = domain.getPathwayId() != null; - api.mode = ModeMapper.mapToApi(domain.getMode()); api.agencyTimeZoneOffset = domain.getAgencyTimeZoneOffset(); - api.transitLeg = domain.isTransitLeg(); - if (domain.isTransitLeg()) { + if (domain instanceof TransitLeg trLeg) { + api.transitLeg = true; var agency = domain.getAgency(); api.agencyId = FeedScopedIdMapper.mapToApi(agency.getId()); api.agencyName = agency.getName(); api.agencyUrl = agency.getUrl(); api.agencyBrandingUrl = agency.getBrandingUrl(); + api.mode = ModeMapper.mapToApi(trLeg.getMode()); var route = domain.getRoute(); api.route = i18NStringMapper.mapToApi(route.getLongName()); @@ -113,11 +115,16 @@ public ApiLeg mapLeg( api.tripId = FeedScopedIdMapper.mapToApi(trip.getId()); api.tripShortName = trip.getShortName(); api.tripBlockId = trip.getGtfsBlockId(); - } else if (domain.getPathwayId() != null) { - api.route = FeedScopedIdMapper.mapToApi(domain.getPathwayId()); - } else { - // TODO OTP2 - This should be set to the street name according to the JavaDoc - api.route = ""; + } else if (domain instanceof StreetLeg streetLeg) { + api.transitLeg = false; + api.mode = ModeMapper.mapToApi(streetLeg.getMode()); + + if (domain.getPathwayId() != null) { + api.route = FeedScopedIdMapper.mapToApi(domain.getPathwayId()); + } else { + // TODO OTP2 - This should be set to the street name according to the JavaDoc + api.route = ""; + } } api.interlineWithPreviousLeg = domain.isInterlinedWithPreviousLeg(); diff --git a/src/main/java/org/opentripplanner/api/mapping/ModeMapper.java b/src/main/java/org/opentripplanner/api/mapping/ModeMapper.java index 41cf9daa66f..5f54a836d5f 100644 --- a/src/main/java/org/opentripplanner/api/mapping/ModeMapper.java +++ b/src/main/java/org/opentripplanner/api/mapping/ModeMapper.java @@ -3,34 +3,25 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import org.opentripplanner.model.plan.LegMode; +import org.opentripplanner.model.plan.Leg; +import org.opentripplanner.model.plan.StreetLeg; +import org.opentripplanner.model.plan.TransitLeg; +import org.opentripplanner.routing.core.TraverseMode; import org.opentripplanner.transit.model.basic.TransitMode; public class ModeMapper { - public static String mapToApi(LegMode domain) { + public static String mapToApi(Leg domain) { if (domain == null) { return null; } - - return switch (domain) { - case AIRPLANE -> "AIRPLANE"; - case BICYCLE -> "BICYCLE"; - case BUS -> "BUS"; - case CAR -> "CAR"; - case CABLE_CAR -> "CABLE_CAR"; - case COACH -> "COACH"; - case FERRY -> "FERRY"; - case FUNICULAR -> "FUNICULAR"; - case GONDOLA -> "GONDOLA"; - case RAIL -> "RAIL"; - case SUBWAY -> "SUBWAY"; - case TRAM -> "TRAM"; - case WALK -> "WALK"; - case SCOOTER -> "SCOOTER"; - case TROLLEYBUS -> "TROLLEYBUS"; - case MONORAIL -> "MONORAIL"; - }; + if (domain instanceof StreetLeg sl) { + return mapToApi(sl.getMode()); + } + if (domain instanceof TransitLeg tl) { + return mapToApi(tl.getMode()); + } + throw new IllegalStateException("Unhandled leg type: " + domain); } public static List mapToApi(Set domain) { @@ -40,6 +31,20 @@ public static List mapToApi(Set domain) { return domain.stream().map(ModeMapper::mapToApi).collect(Collectors.toList()); } + public static String mapToApi(TraverseMode domain) { + if (domain == null) { + return null; + } + + return switch (domain) { + case BICYCLE -> "BICYCLE"; + case CAR -> "CAR"; + case WALK -> "WALK"; + case SCOOTER -> "SCOOTER"; + case FLEX -> throw new IllegalStateException(); + }; + } + public static String mapToApi(TransitMode domain) { if (domain == null) { return null; diff --git a/src/main/java/org/opentripplanner/model/plan/Itinerary.java b/src/main/java/org/opentripplanner/model/plan/Itinerary.java index 080405f0b5c..34a898aee50 100644 --- a/src/main/java/org/opentripplanner/model/plan/Itinerary.java +++ b/src/main/java/org/opentripplanner/model/plan/Itinerary.java @@ -153,7 +153,7 @@ public Leg lastLeg() { /** Get the first transit leg if one exist */ public Optional firstTransitLeg() { - return getLegs().stream().filter(Leg::isTransitLeg).findFirst(); + return getLegs().stream().filter(TransitLeg.class::isInstance).findFirst(); } /** @@ -252,15 +252,15 @@ public String toStr() { buf.sep(); if (leg.isWalkingLeg()) { buf.walk((int) leg.getDuration().toSeconds()); - } else if (leg.isTransitLeg()) { + } else if (leg instanceof TransitLeg transitLeg) { buf.transit( - leg.getMode().name(), - leg.getTrip().logName(), - leg.getStartTime(), - leg.getEndTime() + transitLeg.getMode().name(), + transitLeg.getTrip().logName(), + transitLeg.getStartTime(), + transitLeg.getEndTime() ); - } else { - buf.other(leg.getMode().name(), leg.getStartTime(), leg.getEndTime()); + } else if (leg instanceof StreetLeg streetLeg) { + buf.street(streetLeg.getMode().name(), leg.getStartTime(), leg.getEndTime()); } buf.sep(); @@ -335,6 +335,26 @@ public List getLegs() { return legs; } + /** + * Retrieve a transit leg by its index in the itinerary, starting from 0. This is useful in test + * where you may assume leg N is a transit leg. + * + * @throws ClassCastException if the leg is not a TransitLeg + */ + public TransitLeg getTransitLeg(int index) { + return (TransitLeg) legs.get(index); + } + + /** + * Retrieve a street leg by its index in the itinerary, starting from 0. This is useful in test + * where you may assume leg N is a transit leg. + * + * @throws ClassCastException if the leg is not a StreetLeg + */ + public StreetLeg getStreetLeg(int index) { + return (StreetLeg) legs.get(index); + } + public void setLegs(List legs) { this.legs = List.copyOf(legs); } diff --git a/src/main/java/org/opentripplanner/model/plan/Leg.java b/src/main/java/org/opentripplanner/model/plan/Leg.java index 52b587d815c..d302c7f4f0b 100644 --- a/src/main/java/org/opentripplanner/model/plan/Leg.java +++ b/src/main/java/org/opentripplanner/model/plan/Leg.java @@ -99,14 +99,18 @@ default boolean isPartiallySameTransitLeg(Leg other) { ); } + /** + * Check is this instance has the same type and mode as the given other. + */ + boolean hasSameMode(Leg other); + /** * Return {@code true} if to legs are the same. The mode must match and the time must overlap. * For transit the trip ID must match and board/alight position must overlap. (Two trips with * different service-date can overlap in time, so we use boarding-/alight-position to verify). */ default boolean isPartiallySameLeg(Leg other) { - // Assert both legs have the same mode - if (getMode() != other.getMode()) { + if (!hasSameMode(other)) { return false; } @@ -186,11 +190,6 @@ default WheelchairAccessibility getTripWheelchairAccessibility() { return null; } - /** - * The mode (e.g., Walk) used when traversing this leg. - */ - LegMode getMode(); - /** * The date and time this leg begins. */ diff --git a/src/main/java/org/opentripplanner/model/plan/LegMode.java b/src/main/java/org/opentripplanner/model/plan/LegMode.java deleted file mode 100644 index da4de97e5c3..00000000000 --- a/src/main/java/org/opentripplanner/model/plan/LegMode.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.opentripplanner.model.plan; - -import java.util.EnumSet; -import org.opentripplanner.routing.core.TraverseMode; -import org.opentripplanner.transit.model.basic.TransitMode; - -public enum LegMode { - WALK, - BICYCLE, - SCOOTER, - CAR, - TRAM, - SUBWAY, - RAIL, - BUS, - COACH, - FERRY, - CABLE_CAR, - GONDOLA, - FUNICULAR, - AIRPLANE, - TROLLEYBUS, - MONORAIL; - - private static final EnumSet TRANSIT_MODES = EnumSet.of( - AIRPLANE, - BUS, - CABLE_CAR, - COACH, - FERRY, - FUNICULAR, - GONDOLA, - RAIL, - SUBWAY, - TRAM, - TROLLEYBUS, - MONORAIL - ); - - public static LegMode fromTransitMode(TransitMode transitMode) { - return switch (transitMode) { - case RAIL -> RAIL; - case MONORAIL -> MONORAIL; - case COACH -> COACH; - case BUS -> BUS; - case SUBWAY -> SUBWAY; - case TRAM -> TRAM; - case FERRY -> FERRY; - case AIRPLANE -> AIRPLANE; - case CABLE_CAR -> CABLE_CAR; - case GONDOLA -> GONDOLA; - case FUNICULAR -> FUNICULAR; - case TROLLEYBUS -> TROLLEYBUS; - }; - } - - public static LegMode fromAStarTraverseMode(TraverseMode mode) { - return switch (mode) { - case WALK -> WALK; - case BICYCLE -> BICYCLE; - case SCOOTER -> SCOOTER; - case CAR -> CAR; - case FLEX -> throw new IllegalStateException(); - }; - } - - public boolean isTransit() { - return TRANSIT_MODES.contains(this); - } -} diff --git a/src/main/java/org/opentripplanner/model/plan/ScheduledTransitLeg.java b/src/main/java/org/opentripplanner/model/plan/ScheduledTransitLeg.java index 93f542df251..b3f93929f83 100644 --- a/src/main/java/org/opentripplanner/model/plan/ScheduledTransitLeg.java +++ b/src/main/java/org/opentripplanner/model/plan/ScheduledTransitLeg.java @@ -9,6 +9,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.LineString; @@ -19,6 +20,7 @@ import org.opentripplanner.model.plan.legreference.ScheduledTransitLegReference; import org.opentripplanner.model.transfer.ConstrainedTransfer; import org.opentripplanner.routing.alertpatch.TransitAlert; +import org.opentripplanner.transit.model.basic.TransitMode; import org.opentripplanner.transit.model.basic.WheelchairAccessibility; import org.opentripplanner.transit.model.framework.AbstractTransitEntity; import org.opentripplanner.transit.model.network.Route; @@ -37,7 +39,7 @@ * One leg of a trip -- that is, a temporally continuous piece of the journey that takes place on a * particular vehicle. */ -public class ScheduledTransitLeg implements Leg { +public class ScheduledTransitLeg implements TransitLeg { protected final TripTimes tripTimes; protected final TripPattern tripPattern; @@ -114,11 +116,6 @@ public Instant getServiceDateMidnight() { return ServiceDateUtils.asStartOfService(serviceDate, zoneId).toInstant(); } - @Override - public boolean isTransitLeg() { - return true; - } - public boolean isScheduledTransitLeg() { return true; } @@ -161,8 +158,9 @@ public WheelchairAccessibility getTripWheelchairAccessibility() { } @Override - public LegMode getMode() { - return LegMode.fromTransitMode(getTrip().getMode()); + @Nonnull + public TransitMode getMode() { + return getTrip().getMode(); } @Override diff --git a/src/main/java/org/opentripplanner/model/plan/StreetLeg.java b/src/main/java/org/opentripplanner/model/plan/StreetLeg.java index ba3aabca54f..6d7881eab9e 100644 --- a/src/main/java/org/opentripplanner/model/plan/StreetLeg.java +++ b/src/main/java/org/opentripplanner/model/plan/StreetLeg.java @@ -3,12 +3,14 @@ import java.time.Duration; import java.time.ZonedDateTime; import java.util.List; +import java.util.Objects; import java.util.Set; import java.util.function.Predicate; import javax.annotation.Nullable; import org.locationtech.jts.geom.LineString; import org.opentripplanner.common.model.P2; import org.opentripplanner.model.StreetNote; +import org.opentripplanner.routing.core.TraverseMode; import org.opentripplanner.transit.model.framework.FeedScopedId; import org.opentripplanner.util.lang.DoubleUtils; import org.opentripplanner.util.lang.ToStringBuilder; @@ -19,7 +21,7 @@ */ public class StreetLeg implements Leg { - private final LegMode mode; + private final TraverseMode mode; private final ZonedDateTime startTime; private final ZonedDateTime endTime; private final double distanceMeters; @@ -42,12 +44,7 @@ public class StreetLeg implements Leg { private final Float accessibilityScore; public StreetLeg(StreetLegBuilder builder) { - if (builder.getMode().isTransit()) { - throw new IllegalArgumentException( - "To create a transit leg use the other classes implementing Leg." - ); - } - this.mode = builder.getMode(); + this.mode = Objects.requireNonNull(builder.getMode()); this.startTime = builder.getStartTime(); this.endTime = builder.getEndTime(); this.distanceMeters = DoubleUtils.roundTo2Decimals(builder.getDistanceMeters()); @@ -78,7 +75,7 @@ public boolean isTransitLeg() { @Override public boolean isWalkingLeg() { - return mode == LegMode.WALK; + return mode == TraverseMode.WALK; } @Override @@ -86,8 +83,7 @@ public boolean isStreetLeg() { return true; } - @Override - public LegMode getMode() { + public TraverseMode getMode() { return mode; } @@ -184,6 +180,11 @@ public int getGeneralizedCost() { return generalizedCost; } + @Override + public boolean hasSameMode(Leg other) { + return other instanceof StreetLeg oSL && mode.equals(oSL.mode); + } + @Override public Leg withTimeShift(Duration duration) { return StreetLegBuilder diff --git a/src/main/java/org/opentripplanner/model/plan/StreetLegBuilder.java b/src/main/java/org/opentripplanner/model/plan/StreetLegBuilder.java index 8fee059d939..68c24e334f4 100644 --- a/src/main/java/org/opentripplanner/model/plan/StreetLegBuilder.java +++ b/src/main/java/org/opentripplanner/model/plan/StreetLegBuilder.java @@ -7,11 +7,12 @@ import org.locationtech.jts.geom.LineString; import org.opentripplanner.common.model.P2; import org.opentripplanner.model.StreetNote; +import org.opentripplanner.routing.core.TraverseMode; import org.opentripplanner.transit.model.framework.FeedScopedId; public class StreetLegBuilder { - private LegMode mode; + private TraverseMode mode; private ZonedDateTime startTime; private ZonedDateTime endTime; private Place from; @@ -54,7 +55,7 @@ public StreetLeg build() { return new StreetLeg(this); } - public LegMode getMode() { + public TraverseMode getMode() { return mode; } @@ -118,7 +119,7 @@ public Set getStreetNotes() { return streetNotes; } - public StreetLegBuilder withMode(LegMode mode) { + public StreetLegBuilder withMode(TraverseMode mode) { this.mode = mode; return this; } diff --git a/src/main/java/org/opentripplanner/model/plan/TransitLeg.java b/src/main/java/org/opentripplanner/model/plan/TransitLeg.java new file mode 100644 index 00000000000..736739ca970 --- /dev/null +++ b/src/main/java/org/opentripplanner/model/plan/TransitLeg.java @@ -0,0 +1,22 @@ +package org.opentripplanner.model.plan; + +import javax.annotation.Nonnull; +import org.opentripplanner.transit.model.basic.TransitMode; + +public interface TransitLeg extends Leg { + /** + * The mode (e.g., BUS) used when traversing this leg. + */ + @Nonnull + TransitMode getMode(); + + @Override + default boolean isTransitLeg() { + return true; + } + + @Override + default boolean hasSameMode(Leg other) { + return other instanceof TransitLeg trLeg && getMode().equals(trLeg.getMode()); + } +} diff --git a/src/main/java/org/opentripplanner/routing/algorithm/filterchain/deletionflagger/RemoveBikerentalWithMostlyWalkingFilter.java b/src/main/java/org/opentripplanner/routing/algorithm/filterchain/deletionflagger/RemoveBikerentalWithMostlyWalkingFilter.java index de9a69b97a9..74ce88bc379 100644 --- a/src/main/java/org/opentripplanner/routing/algorithm/filterchain/deletionflagger/RemoveBikerentalWithMostlyWalkingFilter.java +++ b/src/main/java/org/opentripplanner/routing/algorithm/filterchain/deletionflagger/RemoveBikerentalWithMostlyWalkingFilter.java @@ -30,7 +30,7 @@ public Predicate shouldBeFlaggedForRemoval() { var containsTransit = itinerary .getLegs() .stream() - .anyMatch(l -> l != null && l.getMode().isTransit()); + .anyMatch(l -> l != null && l.isTransitLeg()); double bikeRentalDistance = itinerary .getLegs() diff --git a/src/main/java/org/opentripplanner/routing/algorithm/filterchain/deletionflagger/RemoveParkAndRideWithMostlyWalkingFilter.java b/src/main/java/org/opentripplanner/routing/algorithm/filterchain/deletionflagger/RemoveParkAndRideWithMostlyWalkingFilter.java index aff96447508..c47f35d712d 100644 --- a/src/main/java/org/opentripplanner/routing/algorithm/filterchain/deletionflagger/RemoveParkAndRideWithMostlyWalkingFilter.java +++ b/src/main/java/org/opentripplanner/routing/algorithm/filterchain/deletionflagger/RemoveParkAndRideWithMostlyWalkingFilter.java @@ -4,7 +4,8 @@ import java.util.function.Predicate; import java.util.stream.Collectors; import org.opentripplanner.model.plan.Itinerary; -import org.opentripplanner.model.plan.LegMode; +import org.opentripplanner.model.plan.StreetLeg; +import org.opentripplanner.routing.core.TraverseMode; /** * This is used to filter out bike rental itineraries that contain mostly walking. The value @@ -32,12 +33,14 @@ public Predicate shouldBeFlaggedForRemoval() { var containsTransit = itinerary .getLegs() .stream() - .anyMatch(l -> l != null && l.getMode().isTransit()); + .anyMatch(l -> l != null && l.isTransitLeg()); double carDuration = itinerary .getLegs() .stream() - .filter(l -> l.getMode() == LegMode.CAR) + .filter(StreetLeg.class::isInstance) + .map(it -> (StreetLeg) it) + .filter(l -> l.getMode() == TraverseMode.CAR) .mapToDouble(l -> l.getDuration().toSeconds()) .sum(); double totalDuration = itinerary.getDuration().toSeconds(); diff --git a/src/main/java/org/opentripplanner/routing/algorithm/filterchain/groupids/GroupByDistance.java b/src/main/java/org/opentripplanner/routing/algorithm/filterchain/groupids/GroupByDistance.java index 53144b20d26..9a96598ff13 100644 --- a/src/main/java/org/opentripplanner/routing/algorithm/filterchain/groupids/GroupByDistance.java +++ b/src/main/java/org/opentripplanner/routing/algorithm/filterchain/groupids/GroupByDistance.java @@ -4,6 +4,8 @@ import java.util.List; import org.opentripplanner.model.plan.Itinerary; import org.opentripplanner.model.plan.Leg; +import org.opentripplanner.model.plan.StreetLeg; +import org.opentripplanner.model.plan.TransitLeg; import org.opentripplanner.util.lang.ToStringBuilder; /** @@ -139,12 +141,15 @@ private void assertPIsValid(double p) { private static String keySetToString(Leg leg) { var builder = ToStringBuilder .of(leg.getClass()) - .addEnum("mode", leg.getMode()) .addTime("start", leg.getStartTime()) .addTime("end", leg.getStartTime()); - if (leg.isTransitLeg()) { - builder.addObj("tripId", leg.getTrip().getId()); + if (leg instanceof TransitLeg trLeg) { + builder.addEnum("mode", trLeg.getMode()).addObj("tripId", leg.getTrip().getId()); + } else if (leg instanceof StreetLeg stLeg) { + builder.addEnum("mode", stLeg.getMode()); + } else { + throw new IllegalStateException("Unhandled type: " + leg.getClass()); } return builder.toString(); } diff --git a/src/main/java/org/opentripplanner/routing/algorithm/mapping/GraphPathToItineraryMapper.java b/src/main/java/org/opentripplanner/routing/algorithm/mapping/GraphPathToItineraryMapper.java index 5e313ca0413..41dd64831ec 100644 --- a/src/main/java/org/opentripplanner/routing/algorithm/mapping/GraphPathToItineraryMapper.java +++ b/src/main/java/org/opentripplanner/routing/algorithm/mapping/GraphPathToItineraryMapper.java @@ -17,12 +17,12 @@ import org.opentripplanner.model.StreetNote; import org.opentripplanner.model.plan.Itinerary; import org.opentripplanner.model.plan.Leg; -import org.opentripplanner.model.plan.LegMode; import org.opentripplanner.model.plan.Place; import org.opentripplanner.model.plan.StreetLeg; import org.opentripplanner.model.plan.StreetLegBuilder; import org.opentripplanner.model.plan.WalkStep; import org.opentripplanner.routing.core.State; +import org.opentripplanner.routing.core.TraverseMode; import org.opentripplanner.routing.edgetype.BoardingLocationToStopLink; import org.opentripplanner.routing.edgetype.PathwayEdge; import org.opentripplanner.routing.edgetype.StreetEdge; @@ -253,7 +253,7 @@ private static void calculateElevations(Itinerary itinerary, List edges) { * * @param states The states that go with the leg */ - private static LegMode resolveMode(List states) { + private static TraverseMode resolveMode(List states) { return states .stream() // The first state is part of the previous leg @@ -265,12 +265,12 @@ private static LegMode resolveMode(List states) { // Resolve correct mode if renting vehicle if (state.isRentingVehicle()) { return switch (state.stateData.rentalVehicleFormFactor) { - case BICYCLE, OTHER -> LegMode.BICYCLE; - case SCOOTER, MOPED -> LegMode.SCOOTER; - case CAR -> LegMode.CAR; + case BICYCLE, OTHER -> TraverseMode.BICYCLE; + case SCOOTER, MOPED -> TraverseMode.SCOOTER; + case CAR -> TraverseMode.CAR; }; } else { - return LegMode.fromAStarTraverseMode(mode); + return mode; } } @@ -279,7 +279,7 @@ private static LegMode resolveMode(List states) { .filter(Objects::nonNull) .findFirst() // Fallback to walking - .orElse(LegMode.WALK); + .orElse(TraverseMode.WALK); } private static List> encodeElevationProfileWithNaN( diff --git a/src/main/java/org/opentripplanner/routing/algorithm/mapping/RaptorPathToItineraryMapper.java b/src/main/java/org/opentripplanner/routing/algorithm/mapping/RaptorPathToItineraryMapper.java index 5697a66e3ec..57bfee6c921 100644 --- a/src/main/java/org/opentripplanner/routing/algorithm/mapping/RaptorPathToItineraryMapper.java +++ b/src/main/java/org/opentripplanner/routing/algorithm/mapping/RaptorPathToItineraryMapper.java @@ -8,7 +8,6 @@ import org.opentripplanner.model.plan.FrequencyTransitLeg; import org.opentripplanner.model.plan.Itinerary; import org.opentripplanner.model.plan.Leg; -import org.opentripplanner.model.plan.LegMode; import org.opentripplanner.model.plan.Place; import org.opentripplanner.model.plan.ScheduledTransitLeg; import org.opentripplanner.model.plan.StreetLeg; @@ -24,6 +23,7 @@ import org.opentripplanner.routing.core.RoutingContext; import org.opentripplanner.routing.core.State; import org.opentripplanner.routing.core.StateEditor; +import org.opentripplanner.routing.core.TraverseMode; import org.opentripplanner.routing.graph.Edge; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.routing.graph.Vertex; @@ -103,7 +103,7 @@ else if (pathLeg.isTransferLeg()) { legs.addAll( mapTransferLeg( pathLeg.asTransferLeg(), - request.modes.transferMode == StreetMode.BIKE ? LegMode.BICYCLE : LegMode.WALK + request.modes.transferMode == StreetMode.BIKE ? TraverseMode.BICYCLE : TraverseMode.WALK ) ); } @@ -203,7 +203,10 @@ private Leg mapTransitLeg(Leg prevTransitLeg, TransitPathLeg pathL ); } - private List mapTransferLeg(TransferPathLeg pathLeg, LegMode transferMode) { + private List mapTransferLeg( + TransferPathLeg pathLeg, + TraverseMode transferMode + ) { var transferFromStop = transitLayer.getStopByIndex(pathLeg.fromStop()); var transferToStop = transitLayer.getStopByIndex(pathLeg.toStop()); Transfer transfer = ((TransferWithDuration) pathLeg.transfer()).transfer(); @@ -234,7 +237,7 @@ private Itinerary mapEgressLeg(EgressPathLeg egressPathLeg) { private List mapNonTransitLeg( PathLeg pathLeg, Transfer transfer, - LegMode transferMode, + TraverseMode transferMode, Place from, Place to ) { diff --git a/src/main/java/org/opentripplanner/transit/model/framework/FeedScopedId.java b/src/main/java/org/opentripplanner/transit/model/framework/FeedScopedId.java index f5984735dbc..d76bbdfe168 100644 --- a/src/main/java/org/opentripplanner/transit/model/framework/FeedScopedId.java +++ b/src/main/java/org/opentripplanner/transit/model/framework/FeedScopedId.java @@ -29,10 +29,8 @@ public final class FeedScopedId implements Serializable, Comparable WALK_SPEED; - case BICYCLE -> BICYCLE_SPEED; case BUS -> BUS_SPEED; case RAIL -> RAIL_SPEED; + default -> throw new IllegalStateException("Unsupported mode: " + mode); + }; + } + + private double speed(TraverseMode mode) { + return switch (mode) { + case WALK -> WALK_SPEED; + case BICYCLE -> BICYCLE_SPEED; case CAR -> CAR_SPEED; default -> throw new IllegalStateException("Unsupported mode: " + mode); }; diff --git a/src/test/java/org/opentripplanner/routing/algorithm/filterchain/groupids/GroupByDistanceTest.java b/src/test/java/org/opentripplanner/routing/algorithm/filterchain/groupids/GroupByDistanceTest.java index 5b9ffedd84b..a1938f0c213 100644 --- a/src/test/java/org/opentripplanner/routing/algorithm/filterchain/groupids/GroupByDistanceTest.java +++ b/src/test/java/org/opentripplanner/routing/algorithm/filterchain/groupids/GroupByDistanceTest.java @@ -224,7 +224,7 @@ public void testToString() { var subject = new GroupByDistance(itinerary, 0.5); assertEquals( - "GroupByDistance{streetOnly, keySet: [StreetLeg{mode: BICYCLE, start: 11:00:00, end: 11:00:00}]}", + "GroupByDistance{streetOnly, keySet: [StreetLeg{start: 11:00:00, end: 11:00:00, mode: BICYCLE}]}", subject.toString() ); @@ -232,7 +232,7 @@ public void testToString() { subject = new GroupByDistance(itinerary, 0.5); assertEquals( - "GroupByDistance{keySet: [ScheduledTransitLeg{mode: BUS, start: 11:10:00, end: 11:10:00, tripId: F:11}]}", + "GroupByDistance{keySet: [ScheduledTransitLeg{start: 11:10:00, end: 11:10:00, mode: BUS, tripId: F:11}]}", subject.toString() ); } diff --git a/src/test/java/org/opentripplanner/routing/algorithm/mapping/SnapshotTestBase.java b/src/test/java/org/opentripplanner/routing/algorithm/mapping/SnapshotTestBase.java index 6445730de63..3d1cf11786d 100644 --- a/src/test/java/org/opentripplanner/routing/algorithm/mapping/SnapshotTestBase.java +++ b/src/test/java/org/opentripplanner/routing/algorithm/mapping/SnapshotTestBase.java @@ -42,6 +42,7 @@ import org.opentripplanner.model.GenericLocation; import org.opentripplanner.model.plan.Itinerary; import org.opentripplanner.model.plan.Leg; +import org.opentripplanner.model.plan.StreetLeg; import org.opentripplanner.routing.api.request.RouteRequest; import org.opentripplanner.routing.api.request.StreetMode; import org.opentripplanner.routing.api.response.RoutingResponse; @@ -144,7 +145,9 @@ protected void printItineraries( for (int j = 0; j < itinerary.getLegs().size(); j++) { Leg leg = itinerary.getLegs().get(j); - String mode = leg.getMode().isTransit() ? "T" : leg.getMode().name().substring(0, 1); + String mode = (leg instanceof StreetLeg stLeg) + ? stLeg.getMode().name().substring(0, 1) + : "T"; System.out.printf( " - leg %2d - %52.52s %9s --%s-> %-9s %-52.52s\n", j, diff --git a/src/test/java/org/opentripplanner/routing/street/BarrierRoutingTest.java b/src/test/java/org/opentripplanner/routing/street/BarrierRoutingTest.java index 751b495570d..74fdff9b4a0 100644 --- a/src/test/java/org/opentripplanner/routing/street/BarrierRoutingTest.java +++ b/src/test/java/org/opentripplanner/routing/street/BarrierRoutingTest.java @@ -22,7 +22,7 @@ import org.opentripplanner.TestOtpModel; import org.opentripplanner.model.GenericLocation; import org.opentripplanner.model.plan.Itinerary; -import org.opentripplanner.model.plan.LegMode; +import org.opentripplanner.model.plan.StreetLeg; import org.opentripplanner.model.plan.WalkStep; import org.opentripplanner.routing.algorithm.mapping.GraphPathToItineraryMapper; import org.opentripplanner.routing.api.request.RouteRequest; @@ -74,7 +74,7 @@ public void shouldWalkForBarriers() { .flatMap(i -> Stream.of( () -> assertEquals(1, i.getLegs().size()), - () -> assertEquals(LegMode.BICYCLE, i.getLegs().get(0).getMode()), + () -> assertEquals(TraverseMode.BICYCLE, i.getStreetLeg(0).getMode()), () -> assertEquals( List.of(false, true, false, true, false), @@ -144,8 +144,8 @@ private static String computePolyline( .map(l -> () -> assertEquals( - LegMode.fromAStarTraverseMode(traverseMode), - l.getMode(), + traverseMode, + (l instanceof StreetLeg s) ? s.getMode() : null, "Allow only " + traverseMode + " legs" ) ) diff --git a/src/test/java/org/opentripplanner/routing/street/BicycleRoutingTest.java b/src/test/java/org/opentripplanner/routing/street/BicycleRoutingTest.java index a602b66528e..4ce51758f60 100644 --- a/src/test/java/org/opentripplanner/routing/street/BicycleRoutingTest.java +++ b/src/test/java/org/opentripplanner/routing/street/BicycleRoutingTest.java @@ -1,17 +1,18 @@ package org.opentripplanner.routing.street; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.opentripplanner.test.support.PolylineAssert.assertThatPolylinesAreEqual; import java.time.Duration; import java.time.Instant; import java.time.ZoneId; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.locationtech.jts.geom.Geometry; import org.opentripplanner.ConstantsForTests; import org.opentripplanner.TestOtpModel; import org.opentripplanner.model.GenericLocation; -import org.opentripplanner.model.plan.LegMode; +import org.opentripplanner.model.plan.StreetLeg; import org.opentripplanner.routing.algorithm.mapping.GraphPathToItineraryMapper; import org.opentripplanner.routing.api.request.RouteRequest; import org.opentripplanner.routing.core.BicycleOptimizeType; @@ -91,9 +92,17 @@ private static String computePolyline(Graph graph, GenericLocation from, Generic var itineraries = graphPathToItineraryMapper.mapItineraries(paths); temporaryVertices.close(); - // make sure that we only get BICYLE legs + // make sure that we only get BICYCLE legs itineraries.forEach(i -> - i.getLegs().forEach(l -> Assertions.assertEquals(LegMode.BICYCLE, l.getMode())) + i + .getLegs() + .forEach(l -> { + if (l instanceof StreetLeg stLeg) { + assertEquals(TraverseMode.BICYCLE, stLeg.getMode()); + } else { + fail("Expected StreetLeg (BICYCLE): " + l); + } + }) ); Geometry legGeometry = itineraries.get(0).getLegs().get(0).getLegGeometry(); return PolylineEncoder.encodeGeometry(legGeometry).points(); diff --git a/src/test/java/org/opentripplanner/routing/street/CarRoutingTest.java b/src/test/java/org/opentripplanner/routing/street/CarRoutingTest.java index 6e5a2fa6e1e..a8392af9c11 100644 --- a/src/test/java/org/opentripplanner/routing/street/CarRoutingTest.java +++ b/src/test/java/org/opentripplanner/routing/street/CarRoutingTest.java @@ -1,11 +1,12 @@ package org.opentripplanner.routing.street; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.opentripplanner.test.support.PolylineAssert.assertThatPolylinesAreEqual; import java.time.Duration; import java.time.Instant; import java.time.ZoneId; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -13,7 +14,7 @@ import org.opentripplanner.ConstantsForTests; import org.opentripplanner.TestOtpModel; import org.opentripplanner.model.GenericLocation; -import org.opentripplanner.model.plan.LegMode; +import org.opentripplanner.model.plan.StreetLeg; import org.opentripplanner.routing.algorithm.mapping.GraphPathToItineraryMapper; import org.opentripplanner.routing.api.request.RouteRequest; import org.opentripplanner.routing.core.RoutingContext; @@ -146,7 +147,15 @@ private static String computePolyline(Graph graph, GenericLocation from, Generic // make sure that we only get CAR legs itineraries.forEach(i -> - i.getLegs().forEach(l -> Assertions.assertEquals(LegMode.CAR, l.getMode())) + i + .getLegs() + .forEach(l -> { + if (l instanceof StreetLeg stLeg) { + assertEquals(TraverseMode.CAR, stLeg.getMode()); + } else { + fail("Expected StreetLeg (CAR): " + l); + } + }) ); Geometry legGeometry = itineraries.get(0).getLegs().get(0).getLegGeometry(); return PolylineEncoder.encodeGeometry(legGeometry).points(); diff --git a/src/test/java/org/opentripplanner/routing/street/SplitEdgeTurnRestrictionsTest.java b/src/test/java/org/opentripplanner/routing/street/SplitEdgeTurnRestrictionsTest.java index 349eec06492..f66e9b309df 100644 --- a/src/test/java/org/opentripplanner/routing/street/SplitEdgeTurnRestrictionsTest.java +++ b/src/test/java/org/opentripplanner/routing/street/SplitEdgeTurnRestrictionsTest.java @@ -1,17 +1,18 @@ package org.opentripplanner.routing.street; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.opentripplanner.test.support.PolylineAssert.assertThatPolylinesAreEqual; import java.time.Duration; import java.time.Instant; import java.time.ZoneId; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.locationtech.jts.geom.Geometry; import org.opentripplanner.ConstantsForTests; import org.opentripplanner.TestOtpModel; import org.opentripplanner.model.GenericLocation; -import org.opentripplanner.model.plan.LegMode; +import org.opentripplanner.model.plan.StreetLeg; import org.opentripplanner.routing.algorithm.mapping.GraphPathToItineraryMapper; import org.opentripplanner.routing.api.request.RouteRequest; import org.opentripplanner.routing.core.RoutingContext; @@ -166,7 +167,15 @@ private static String computeCarPolyline(Graph graph, GenericLocation from, Gene // make sure that we only get CAR legs itineraries.forEach(i -> - i.getLegs().forEach(l -> Assertions.assertEquals(LegMode.CAR, l.getMode())) + i + .getLegs() + .forEach(l -> { + if (l instanceof StreetLeg stLeg) { + assertEquals(TraverseMode.CAR, stLeg.getMode()); + } else { + fail("Expected StreetLeg (CAR): " + l); + } + }) ); Geometry geometry = itineraries.get(0).getLegs().get(0).getLegGeometry(); return PolylineEncoder.encodeGeometry(geometry).points(); diff --git a/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/CsvFileIO.java b/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/CsvFileIO.java index 412e91f573e..8ae936c8b7a 100644 --- a/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/CsvFileIO.java +++ b/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/CsvFileIO.java @@ -13,12 +13,14 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.Objects; import java.util.function.Function; import java.util.regex.Pattern; import java.util.stream.Collectors; import org.opentripplanner.api.parameter.QualifiedModeSet; import org.opentripplanner.model.GenericLocation; -import org.opentripplanner.model.plan.LegMode; +import org.opentripplanner.routing.core.TraverseMode; +import org.opentripplanner.transit.model.basic.TransitMode; import org.opentripplanner.transit.model.framework.FeedScopedId; import org.opentripplanner.util.time.DurationUtils; import org.opentripplanner.util.time.TimeUtils; @@ -43,7 +45,7 @@ public class CsvFileIO { private final String feedId; public CsvFileIO(File dir, String testSetName, String feedId) { - this.feedId = feedId; + this.feedId = Objects.requireNonNull(feedId); testCasesFile = new File(dir, testSetName + ".csv"); expectedResultsFile = new File(dir, testSetName + "-expected-results.csv"); expectedResultsOutputFile = new File(dir, testSetName + "-results.csv"); @@ -258,7 +260,7 @@ private Result readExpectedResult(CsvReader csvReader) throws IOException { parseTime(csvReader.get("startTime")), parseTime(csvReader.get("endTime")), str2Col(csvReader.get("agencies")), - str2Col(csvReader.get("modes"), LegMode::valueOf), + str2Col(csvReader.get("modes"), CsvFileIO::parseMode), str2Col(csvReader.get("routes")), str2Col(csvReader.get("stops")), csvReader.get("details") @@ -274,4 +276,12 @@ private Result readExpectedResult(CsvReader csvReader) throws IOException { private boolean isCommentOrEmpty(String line) { return line.startsWith("#") || line.matches("[\\s,;|]*"); } + + private static Enum parseMode(String mode) { + try { + return TransitMode.valueOf(mode); + } catch (IllegalArgumentException ignore) { + return TraverseMode.valueOf(mode); + } + } } diff --git a/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/ItineraryResultMapper.java b/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/ItineraryResultMapper.java index 82461bfa31a..1e1a82a9e86 100644 --- a/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/ItineraryResultMapper.java +++ b/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/ItineraryResultMapper.java @@ -3,8 +3,8 @@ import java.time.temporal.ChronoField; import java.util.ArrayList; import java.util.Collection; -import java.util.EnumSet; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Optional; @@ -12,7 +12,9 @@ import java.util.stream.Collectors; import org.opentripplanner.model.plan.Itinerary; import org.opentripplanner.model.plan.Leg; -import org.opentripplanner.model.plan.LegMode; +import org.opentripplanner.model.plan.StreetLeg; +import org.opentripplanner.model.plan.TransitLeg; +import org.opentripplanner.transit.model.basic.TransitMode; import org.opentripplanner.transit.model.organization.Agency; import org.opentripplanner.transit.model.site.StopLocation; import org.opentripplanner.transit.raptor.api.path.PathStringBuilder; @@ -82,9 +84,9 @@ public static String details(Itinerary itin) { if (leg.isWalkingLeg()) { buf.walk((int) leg.getDuration().toSeconds()); - } else if (leg.isTransitLeg()) { + } else if (leg instanceof TransitLeg transitLeg) { buf.transit( - leg.getMode().name() + " " + leg.getRoute().getShortName(), + transitLeg.getMode().name() + " " + leg.getRoute().getShortName(), leg.getStartTime().get(ChronoField.SECOND_OF_DAY), leg.getEndTime().get(ChronoField.SECOND_OF_DAY) ); @@ -113,14 +115,16 @@ private static String agencyShortName(Agency agency) { private Result map(Itinerary itinerary) { List agencies = new ArrayList<>(); List routes = new ArrayList<>(); - Set modes = EnumSet.noneOf(LegMode.class); + Set> modes = new HashSet<>(); List stops = new ArrayList<>(); for (Leg it : itinerary.getLegs()) { - if (it.isTransitLeg()) { + if (it instanceof TransitLeg trLeg) { agencies.add(agencyShortName(it.getAgency())); routes.add(it.getRoute().getName()); - modes.add(it.getMode()); + modes.add(trLeg.getMode()); + } else if (it instanceof StreetLeg streetLeg) { + modes.add(streetLeg.getMode()); } if (it.getTo().stop != null) { stops.add(it.getTo().stop.getId().toString()); diff --git a/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/Result.java b/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/Result.java index c743a651160..addc7d7d6a4 100644 --- a/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/Result.java +++ b/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/Result.java @@ -4,7 +4,6 @@ import java.util.Collection; import java.util.Comparator; import java.util.List; -import org.opentripplanner.model.plan.LegMode; import org.opentripplanner.util.CompositeComparator; import org.opentripplanner.util.time.DurationUtils; import org.opentripplanner.util.time.TimeUtils; @@ -33,7 +32,7 @@ class Result { /** Alphabetical distinct list of agencies. A {@code List} is used because the order is important. */ final List agencies; /** Alphabetical distinct list of modes. A {@code List} is used because the order is important. */ - final List modes; + final List> modes; /** A list of routes in tha same order as they appear in the journey. */ final List routes; /** A list of stops in tha same order as they appear in the journey. */ @@ -53,7 +52,7 @@ class Result { Integer startTime, Integer endTime, Collection agencies, - Collection modes, + Collection> modes, Collection routes, Collection stops, String details @@ -66,7 +65,7 @@ class Result { this.startTime = startTime; this.endTime = endTime; this.agencies = sortedList(agencies); - this.modes = sortedList(modes); + this.modes = sortedModes(modes); this.routes = List.copyOf(routes); this.stops = List.copyOf(stops); this.details = details; @@ -130,4 +129,8 @@ private static Comparator compareCost(boolean skipCost) { private static List sortedList(Collection values) { return values.stream().sorted().distinct().toList(); } + + private static > List sortedModes(Collection modes) { + return modes.stream().sorted(Comparator.comparing(l -> l.name())).distinct().toList(); + } } From 5d11ce67ac4288aecbce51887218278fbbfaa9ce Mon Sep 17 00:00:00 2001 From: Thomas Gran Date: Tue, 13 Sep 2022 21:21:55 +0200 Subject: [PATCH 4/7] test: Make FeedId required in SpeedTest config, prevent NPE later --- .../transit/raptor/speed_test/options/SpeedTestConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/opentripplanner/transit/raptor/speed_test/options/SpeedTestConfig.java b/src/test/java/org/opentripplanner/transit/raptor/speed_test/options/SpeedTestConfig.java index 0021c8708e9..d358eccb4f0 100644 --- a/src/test/java/org/opentripplanner/transit/raptor/speed_test/options/SpeedTestConfig.java +++ b/src/test/java/org/opentripplanner/transit/raptor/speed_test/options/SpeedTestConfig.java @@ -38,7 +38,7 @@ public SpeedTestConfig(JsonNode node) { this.rawNode = node; testDate = adapter.asDateOrRelativePeriod("testDate", "PT0D"); graph = adapter.asUri("graph", null); - feedId = adapter.asText("feedId", null); + feedId = adapter.asText("feedId"); transitRoutingParams = new TransitRoutingConfig(adapter.path("tuningParameters")); request = mapRoutingRequest(adapter.path("routingDefaults")); } From 119f34a020853be7afbf36e8a0ee015e6c6ebccd Mon Sep 17 00:00:00 2001 From: Thomas Gran Date: Tue, 13 Sep 2022 21:23:06 +0200 Subject: [PATCH 5/7] refactor: Remove unused field skipCost in ItineraryResultMapper --- .../RemoveParkAndRideWithMostlyWalkingFilter.java | 2 +- .../model/testcase/ItineraryResultMapper.java | 10 +++------- .../speed_test/model/testcase/TestCaseResults.java | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/opentripplanner/routing/algorithm/filterchain/deletionflagger/RemoveParkAndRideWithMostlyWalkingFilter.java b/src/main/java/org/opentripplanner/routing/algorithm/filterchain/deletionflagger/RemoveParkAndRideWithMostlyWalkingFilter.java index c47f35d712d..a81dca12f32 100644 --- a/src/main/java/org/opentripplanner/routing/algorithm/filterchain/deletionflagger/RemoveParkAndRideWithMostlyWalkingFilter.java +++ b/src/main/java/org/opentripplanner/routing/algorithm/filterchain/deletionflagger/RemoveParkAndRideWithMostlyWalkingFilter.java @@ -39,7 +39,7 @@ public Predicate shouldBeFlaggedForRemoval() { .getLegs() .stream() .filter(StreetLeg.class::isInstance) - .map(it -> (StreetLeg) it) + .map(StreetLeg.class::cast) .filter(l -> l.getMode() == TraverseMode.CAR) .mapToDouble(l -> l.getDuration().toSeconds()) .sum(); diff --git a/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/ItineraryResultMapper.java b/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/ItineraryResultMapper.java index 1e1a82a9e86..2654cd5dde1 100644 --- a/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/ItineraryResultMapper.java +++ b/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/ItineraryResultMapper.java @@ -14,7 +14,6 @@ import org.opentripplanner.model.plan.Leg; import org.opentripplanner.model.plan.StreetLeg; import org.opentripplanner.model.plan.TransitLeg; -import org.opentripplanner.transit.model.basic.TransitMode; import org.opentripplanner.transit.model.organization.Agency; import org.opentripplanner.transit.model.site.StopLocation; import org.opentripplanner.transit.raptor.api.path.PathStringBuilder; @@ -30,7 +29,6 @@ class ItineraryResultMapper { private static final Map AGENCY_NAMES_SHORT = new HashMap<>(); - private final boolean skipCost; private final String testCaseId; static { @@ -68,8 +66,7 @@ class ItineraryResultMapper { AGENCY_NAMES_SHORT.put("Østfold kollektivtrafikk", "ØstKol"); } - private ItineraryResultMapper(boolean skipCost, String testCaseId) { - this.skipCost = skipCost; + private ItineraryResultMapper(String testCaseId) { this.testCaseId = testCaseId; } @@ -97,10 +94,9 @@ public static String details(Itinerary itin) { static Collection map( final String testCaseId, - Collection itineraries, - boolean skipCost + Collection itineraries ) { - var mapper = new ItineraryResultMapper(skipCost, testCaseId); + var mapper = new ItineraryResultMapper(testCaseId); return itineraries.stream().map(mapper::map).collect(Collectors.toList()); } diff --git a/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/TestCaseResults.java b/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/TestCaseResults.java index 13cbf9f9bd3..18fea62be45 100644 --- a/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/TestCaseResults.java +++ b/src/test/java/org/opentripplanner/transit/raptor/speed_test/model/testcase/TestCaseResults.java @@ -74,7 +74,7 @@ void addTimes(int transitTimeMs, int totalTimeMs) { } void matchItineraries(Collection itineraries) { - actual.addAll(ItineraryResultMapper.map(testCaseId, itineraries, skipCost)); + actual.addAll(ItineraryResultMapper.map(testCaseId, itineraries)); matchedResults.clear(); matchedResults.addAll(DiffTool.diff(expected, actual, Result.comparator(skipCost))); status = resolveStatus(); From c6c93424f89064eda53b1d3ba53adf4ab89ea288 Mon Sep 17 00:00:00 2001 From: Thomas Gran Date: Wed, 14 Sep 2022 11:08:16 +0200 Subject: [PATCH 6/7] refactor: Rename RequestModes copy() to copyOf() --- .../ext/flex/FlexIntegrationTest.java | 2 +- .../routing/algorithm/RoutingWorker.java | 4 ++-- .../routing/api/request/RequestModes.java | 4 ++-- .../routing/api/request/RouteRequest.java | 4 +--- .../java/org/opentripplanner/GtfsTest.java | 3 +-- .../module/osm/TestIntermediatePlaces.java | 16 +++++++------- .../module/osm/TriangleInequalityTest.java | 21 ++++++++----------- 7 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTest.java b/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTest.java index baf3056bdd6..58bfff9286f 100644 --- a/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTest.java +++ b/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTest.java @@ -226,7 +226,7 @@ private Itinerary getItinerary( request.setNumItineraries(10); request.setSearchWindow(Duration.ofHours(2)); - var modes = request.modes.copy(); + var modes = request.modes.copyOf(); modes.withEgressMode(FLEXIBLE); if (onlyDirect) { diff --git a/src/main/java/org/opentripplanner/routing/algorithm/RoutingWorker.java b/src/main/java/org/opentripplanner/routing/algorithm/RoutingWorker.java index 5bb3a45932b..c4b9b123f28 100644 --- a/src/main/java/org/opentripplanner/routing/algorithm/RoutingWorker.java +++ b/src/main/java/org/opentripplanner/routing/algorithm/RoutingWorker.java @@ -90,7 +90,7 @@ public RoutingResponse route() { var emptyDirectModeHandler = new FilterTransitWhenDirectModeIsEmpty(request.modes); request.modes = - request.modes.copy().withDirectMode(emptyDirectModeHandler.resolveDirectMode()).build(); + request.modes.copyOf().withDirectMode(emptyDirectModeHandler.resolveDirectMode()).build(); this.debugTimingAggregator.finishedPrecalculating(); @@ -154,7 +154,7 @@ public RoutingResponse route() { // Restore original directMode. request.modes = - request.modes.copy().withDirectMode(emptyDirectModeHandler.originalDirectMode()).build(); + request.modes.copyOf().withDirectMode(emptyDirectModeHandler.originalDirectMode()).build(); // Adjust the search-window for the next search if the current search-window // is off (too few or too many results found). diff --git a/src/main/java/org/opentripplanner/routing/api/request/RequestModes.java b/src/main/java/org/opentripplanner/routing/api/request/RequestModes.java index a671bf5190a..ee8fdac8d84 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/RequestModes.java +++ b/src/main/java/org/opentripplanner/routing/api/request/RequestModes.java @@ -62,10 +62,10 @@ public RequestModes(RequestModesBuilder builder) { } public static RequestModesBuilder of() { - return DEFAULTS.copy(); + return DEFAULTS.copyOf(); } - public RequestModesBuilder copy() { + public RequestModesBuilder copyOf() { return new RequestModesBuilder(this); } diff --git a/src/main/java/org/opentripplanner/routing/api/request/RouteRequest.java b/src/main/java/org/opentripplanner/routing/api/request/RouteRequest.java index ddd5f7b0cb5..463c048d785 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/RouteRequest.java +++ b/src/main/java/org/opentripplanner/routing/api/request/RouteRequest.java @@ -12,7 +12,6 @@ import java.util.List; import java.util.Locale; import java.util.Set; -import javax.annotation.Nonnull; import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.Envelope; import org.opentripplanner.api.common.LocationStringParser; @@ -22,7 +21,6 @@ import org.opentripplanner.model.plan.pagecursor.PageCursor; import org.opentripplanner.model.plan.pagecursor.PageType; import org.opentripplanner.routing.api.request.preference.RoutingPreferences; -import org.opentripplanner.routing.api.request.preference.WheelchairAccessibilityPreferences; import org.opentripplanner.routing.core.RouteMatcher; import org.opentripplanner.routing.core.State; import org.opentripplanner.routing.core.TraverseMode; @@ -429,7 +427,7 @@ public void applyPageCursor() { arriveBy = false; } setDateTime(arriveBy ? pageCursor.latestArrivalTime : pageCursor.earliestDepartureTime); - modes = modes.copy().withDirectMode(StreetMode.NOT_SET).build(); + modes = modes.copyOf().withDirectMode(StreetMode.NOT_SET).build(); LOG.debug("Request dateTime={} set from pageCursor.", dateTime); } } diff --git a/src/test/java/org/opentripplanner/GtfsTest.java b/src/test/java/org/opentripplanner/GtfsTest.java index 0502e9f7954..54d360f303a 100644 --- a/src/test/java/org/opentripplanner/GtfsTest.java +++ b/src/test/java/org/opentripplanner/GtfsTest.java @@ -29,7 +29,6 @@ import org.opentripplanner.routing.api.request.RouteRequest; import org.opentripplanner.routing.api.request.preference.RoutingPreferences; import org.opentripplanner.routing.api.response.RoutingResponse; -import org.opentripplanner.routing.core.RouteMatcher; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.routing.impl.TransitAlertServiceImpl; import org.opentripplanner.standalone.api.OtpServerRequestContext; @@ -92,7 +91,7 @@ public Itinerary plan( routingRequest.setWheelchair(wheelchairAccessible); preferences.transfer().setCost(preferLeastTransfers ? 300 : 0); RequestModesBuilder requestModesBuilder = routingRequest.modes - .copy() + .copyOf() .withDirectMode(NOT_SET) .withAccessMode(WALK) .withTransferMode(WALK) diff --git a/src/test/java/org/opentripplanner/graph_builder/module/osm/TestIntermediatePlaces.java b/src/test/java/org/opentripplanner/graph_builder/module/osm/TestIntermediatePlaces.java index beaa908f2b3..3c47df390e7 100644 --- a/src/test/java/org/opentripplanner/graph_builder/module/osm/TestIntermediatePlaces.java +++ b/src/test/java/org/opentripplanner/graph_builder/module/osm/TestIntermediatePlaces.java @@ -86,14 +86,14 @@ public void testWithoutIntermediatePlaces() { fromLocation, toLocation, intermediateLocations, - RequestModes.defaultRequestModes().copy().clearTransitModes().build(), + RequestModes.defaultRequestModes().copyOf().clearTransitModes().build(), false ); handleRequest( fromLocation, toLocation, intermediateLocations, - RequestModes.defaultRequestModes().copy().clearTransitModes().build(), + RequestModes.defaultRequestModes().copyOf().clearTransitModes().build(), true ); } @@ -109,14 +109,14 @@ public void testOneIntermediatePlace() { fromLocation, toLocation, intermediateLocations, - RequestModes.defaultRequestModes().copy().clearTransitModes().build(), + RequestModes.defaultRequestModes().copyOf().clearTransitModes().build(), false ); handleRequest( fromLocation, toLocation, intermediateLocations, - RequestModes.defaultRequestModes().copy().clearTransitModes().build(), + RequestModes.defaultRequestModes().copyOf().clearTransitModes().build(), true ); } @@ -134,14 +134,14 @@ public void testTwoIntermediatePlaces() { fromLocation, toLocation, intermediateLocations, - RequestModes.defaultRequestModes().copy().withDirectMode(CAR).clearTransitModes().build(), + RequestModes.defaultRequestModes().copyOf().withDirectMode(CAR).clearTransitModes().build(), false ); handleRequest( fromLocation, toLocation, intermediateLocations, - RequestModes.defaultRequestModes().copy().withDirectMode(CAR).clearTransitModes().build(), + RequestModes.defaultRequestModes().copyOf().withDirectMode(CAR).clearTransitModes().build(), true ); } @@ -178,14 +178,14 @@ public void testThreeBusStopPlaces() { fromLocation, toLocation, intermediateLocations, - RequestModes.defaultRequestModes().copy().withDirectMode(NOT_SET).build(), + RequestModes.defaultRequestModes().copyOf().withDirectMode(NOT_SET).build(), false ); handleRequest( fromLocation, toLocation, intermediateLocations, - RequestModes.defaultRequestModes().copy().withDirectMode(NOT_SET).build(), + RequestModes.defaultRequestModes().copyOf().withDirectMode(NOT_SET).build(), true ); } diff --git a/src/test/java/org/opentripplanner/graph_builder/module/osm/TriangleInequalityTest.java b/src/test/java/org/opentripplanner/graph_builder/module/osm/TriangleInequalityTest.java index dc23fdde3ce..08cef18a3f0 100644 --- a/src/test/java/org/opentripplanner/graph_builder/module/osm/TriangleInequalityTest.java +++ b/src/test/java/org/opentripplanner/graph_builder/module/osm/TriangleInequalityTest.java @@ -23,10 +23,7 @@ import org.opentripplanner.routing.algorithm.astar.AStarBuilder; import org.opentripplanner.routing.api.request.RequestModes; import org.opentripplanner.routing.api.request.RouteRequest; -import org.opentripplanner.routing.api.request.StreetMode; import org.opentripplanner.routing.core.RoutingContext; -import org.opentripplanner.routing.core.TraverseMode; -import org.opentripplanner.routing.core.TraverseModeSet; import org.opentripplanner.routing.core.intersection_model.ConstantIntersectionTraversalCostModel; import org.opentripplanner.routing.graph.Edge; import org.opentripplanner.routing.graph.Graph; @@ -97,7 +94,7 @@ public void testTriangleInequalityDefaultModes() { @Test public void testTriangleInequalityWalkingOnly() { - RequestModes modes = RequestModes.defaultRequestModes().copy().clearTransitModes().build(); + RequestModes modes = RequestModes.defaultRequestModes().copyOf().clearTransitModes().build(); checkTriangleInequality(modes); } @@ -105,7 +102,7 @@ public void testTriangleInequalityWalkingOnly() { public void testTriangleInequalityDrivingOnly() { RequestModes modes = RequestModes .defaultRequestModes() - .copy() + .copyOf() .withDirectMode(CAR) .clearTransitModes() .build(); @@ -122,7 +119,7 @@ public void testTriangleInequalityWalkTransit() { public void testTriangleInequalityWalkBike() { RequestModes modes = RequestModes .defaultRequestModes() - .copy() + .copyOf() .withDirectMode(BIKE) .clearTransitModes() .build(); @@ -136,7 +133,7 @@ public void testTriangleInequalityDefaultModesBasicSPT() { @Test public void testTriangleInequalityWalkingOnlyBasicSPT() { - RequestModes modes = RequestModes.defaultRequestModes().copy().clearTransitModes().build(); + RequestModes modes = RequestModes.defaultRequestModes().copyOf().clearTransitModes().build(); checkTriangleInequality(modes); } @@ -144,7 +141,7 @@ public void testTriangleInequalityWalkingOnlyBasicSPT() { public void testTriangleInequalityDrivingOnlyBasicSPT() { RequestModes modes = RequestModes .defaultRequestModes() - .copy() + .copyOf() .withDirectMode(CAR) .clearTransitModes() .build(); @@ -161,7 +158,7 @@ public void testTriangleInequalityWalkTransitBasicSPT() { public void testTriangleInequalityWalkBikeBasicSPT() { RequestModes modes = RequestModes .defaultRequestModes() - .copy() + .copyOf() .withDirectMode(BIKE) .clearTransitModes() .build(); @@ -175,7 +172,7 @@ public void testTriangleInequalityDefaultModesMultiSPT() { @Test public void testTriangleInequalityWalkingOnlyMultiSPT() { - RequestModes modes = RequestModes.defaultRequestModes().copy().clearTransitModes().build(); + RequestModes modes = RequestModes.defaultRequestModes().copyOf().clearTransitModes().build(); checkTriangleInequality(modes); } @@ -183,7 +180,7 @@ public void testTriangleInequalityWalkingOnlyMultiSPT() { public void testTriangleInequalityDrivingOnlyMultiSPT() { RequestModes modes = RequestModes .defaultRequestModes() - .copy() + .copyOf() .withDirectMode(CAR) .clearTransitModes() .build(); @@ -200,7 +197,7 @@ public void testTriangleInequalityWalkTransitMultiSPT() { public void testTriangleInequalityWalkBikeMultiSPT() { RequestModes modes = RequestModes .defaultRequestModes() - .copy() + .copyOf() .withDirectMode(BIKE) .clearTransitModes() .build(); From bb36319b382dcf5f22156c27de9b67285176e147 Mon Sep 17 00:00:00 2001 From: Thomas Gran Date: Wed, 14 Sep 2022 11:11:14 +0200 Subject: [PATCH 7/7] refactor: Use RequestModes.of() not RequestModes.defaultRequestModes().copyOf() --- .../routing/api/request/RequestModes.java | 7 +++ .../module/osm/TestIntermediatePlaces.java | 16 +++---- .../module/osm/TriangleInequalityTest.java | 48 ++++--------------- 3 files changed, 24 insertions(+), 47 deletions(-) diff --git a/src/main/java/org/opentripplanner/routing/api/request/RequestModes.java b/src/main/java/org/opentripplanner/routing/api/request/RequestModes.java index ee8fdac8d84..9ca7cab5081 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/RequestModes.java +++ b/src/main/java/org/opentripplanner/routing/api/request/RequestModes.java @@ -61,6 +61,9 @@ public RequestModes(RequestModesBuilder builder) { ); } + /** + * Return a mode builder with the defaults set. + */ public static RequestModesBuilder of() { return DEFAULTS.copyOf(); } @@ -69,6 +72,10 @@ public RequestModesBuilder copyOf() { return new RequestModesBuilder(this); } + /** + * Return the default set of modes with WALK for all street modes and all transit modes set. + * Tip: Use the {@link #of()} to change the defaults. + */ public static RequestModes defaultRequestModes() { return DEFAULTS; } diff --git a/src/test/java/org/opentripplanner/graph_builder/module/osm/TestIntermediatePlaces.java b/src/test/java/org/opentripplanner/graph_builder/module/osm/TestIntermediatePlaces.java index 3c47df390e7..ac6838f53ba 100644 --- a/src/test/java/org/opentripplanner/graph_builder/module/osm/TestIntermediatePlaces.java +++ b/src/test/java/org/opentripplanner/graph_builder/module/osm/TestIntermediatePlaces.java @@ -86,14 +86,14 @@ public void testWithoutIntermediatePlaces() { fromLocation, toLocation, intermediateLocations, - RequestModes.defaultRequestModes().copyOf().clearTransitModes().build(), + RequestModes.of().clearTransitModes().build(), false ); handleRequest( fromLocation, toLocation, intermediateLocations, - RequestModes.defaultRequestModes().copyOf().clearTransitModes().build(), + RequestModes.of().clearTransitModes().build(), true ); } @@ -109,14 +109,14 @@ public void testOneIntermediatePlace() { fromLocation, toLocation, intermediateLocations, - RequestModes.defaultRequestModes().copyOf().clearTransitModes().build(), + RequestModes.of().clearTransitModes().build(), false ); handleRequest( fromLocation, toLocation, intermediateLocations, - RequestModes.defaultRequestModes().copyOf().clearTransitModes().build(), + RequestModes.of().clearTransitModes().build(), true ); } @@ -134,14 +134,14 @@ public void testTwoIntermediatePlaces() { fromLocation, toLocation, intermediateLocations, - RequestModes.defaultRequestModes().copyOf().withDirectMode(CAR).clearTransitModes().build(), + RequestModes.of().withDirectMode(CAR).clearTransitModes().build(), false ); handleRequest( fromLocation, toLocation, intermediateLocations, - RequestModes.defaultRequestModes().copyOf().withDirectMode(CAR).clearTransitModes().build(), + RequestModes.of().withDirectMode(CAR).clearTransitModes().build(), true ); } @@ -178,14 +178,14 @@ public void testThreeBusStopPlaces() { fromLocation, toLocation, intermediateLocations, - RequestModes.defaultRequestModes().copyOf().withDirectMode(NOT_SET).build(), + RequestModes.of().withDirectMode(NOT_SET).build(), false ); handleRequest( fromLocation, toLocation, intermediateLocations, - RequestModes.defaultRequestModes().copyOf().withDirectMode(NOT_SET).build(), + RequestModes.of().withDirectMode(NOT_SET).build(), true ); } diff --git a/src/test/java/org/opentripplanner/graph_builder/module/osm/TriangleInequalityTest.java b/src/test/java/org/opentripplanner/graph_builder/module/osm/TriangleInequalityTest.java index 08cef18a3f0..672a61729f9 100644 --- a/src/test/java/org/opentripplanner/graph_builder/module/osm/TriangleInequalityTest.java +++ b/src/test/java/org/opentripplanner/graph_builder/module/osm/TriangleInequalityTest.java @@ -94,18 +94,13 @@ public void testTriangleInequalityDefaultModes() { @Test public void testTriangleInequalityWalkingOnly() { - RequestModes modes = RequestModes.defaultRequestModes().copyOf().clearTransitModes().build(); + RequestModes modes = RequestModes.of().clearTransitModes().build(); checkTriangleInequality(modes); } @Test public void testTriangleInequalityDrivingOnly() { - RequestModes modes = RequestModes - .defaultRequestModes() - .copyOf() - .withDirectMode(CAR) - .clearTransitModes() - .build(); + RequestModes modes = RequestModes.of().withDirectMode(CAR).clearTransitModes().build(); checkTriangleInequality(modes); } @@ -117,12 +112,7 @@ public void testTriangleInequalityWalkTransit() { @Test public void testTriangleInequalityWalkBike() { - RequestModes modes = RequestModes - .defaultRequestModes() - .copyOf() - .withDirectMode(BIKE) - .clearTransitModes() - .build(); + RequestModes modes = RequestModes.of().withDirectMode(BIKE).clearTransitModes().build(); checkTriangleInequality(modes); } @@ -133,18 +123,13 @@ public void testTriangleInequalityDefaultModesBasicSPT() { @Test public void testTriangleInequalityWalkingOnlyBasicSPT() { - RequestModes modes = RequestModes.defaultRequestModes().copyOf().clearTransitModes().build(); + RequestModes modes = RequestModes.of().clearTransitModes().build(); checkTriangleInequality(modes); } @Test public void testTriangleInequalityDrivingOnlyBasicSPT() { - RequestModes modes = RequestModes - .defaultRequestModes() - .copyOf() - .withDirectMode(CAR) - .clearTransitModes() - .build(); + RequestModes modes = RequestModes.of().withDirectMode(CAR).clearTransitModes().build(); checkTriangleInequality(modes); } @@ -156,12 +141,7 @@ public void testTriangleInequalityWalkTransitBasicSPT() { @Test public void testTriangleInequalityWalkBikeBasicSPT() { - RequestModes modes = RequestModes - .defaultRequestModes() - .copyOf() - .withDirectMode(BIKE) - .clearTransitModes() - .build(); + RequestModes modes = RequestModes.of().withDirectMode(BIKE).clearTransitModes().build(); checkTriangleInequality(modes); } @@ -172,18 +152,13 @@ public void testTriangleInequalityDefaultModesMultiSPT() { @Test public void testTriangleInequalityWalkingOnlyMultiSPT() { - RequestModes modes = RequestModes.defaultRequestModes().copyOf().clearTransitModes().build(); + RequestModes modes = RequestModes.of().clearTransitModes().build(); checkTriangleInequality(modes); } @Test public void testTriangleInequalityDrivingOnlyMultiSPT() { - RequestModes modes = RequestModes - .defaultRequestModes() - .copyOf() - .withDirectMode(CAR) - .clearTransitModes() - .build(); + RequestModes modes = RequestModes.of().withDirectMode(CAR).clearTransitModes().build(); checkTriangleInequality(modes); } @@ -195,12 +170,7 @@ public void testTriangleInequalityWalkTransitMultiSPT() { @Test public void testTriangleInequalityWalkBikeMultiSPT() { - RequestModes modes = RequestModes - .defaultRequestModes() - .copyOf() - .withDirectMode(BIKE) - .clearTransitModes() - .build(); + RequestModes modes = RequestModes.of().withDirectMode(BIKE).clearTransitModes().build(); checkTriangleInequality(modes); }