From 2a6522e2e3f7119f2d234ddb1dca1b9cea86eb60 Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Mon, 20 Nov 2023 13:46:23 +0200 Subject: [PATCH 01/21] Support default boolean value ignore in toStringBuilder --- .../opentripplanner/framework/tostring/ToStringBuilder.java | 4 ++++ .../framework/tostring/ToStringBuilderTest.java | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/main/java/org/opentripplanner/framework/tostring/ToStringBuilder.java b/src/main/java/org/opentripplanner/framework/tostring/ToStringBuilder.java index f6c17b19af1..477d9e9938e 100644 --- a/src/main/java/org/opentripplanner/framework/tostring/ToStringBuilder.java +++ b/src/main/java/org/opentripplanner/framework/tostring/ToStringBuilder.java @@ -95,6 +95,10 @@ public ToStringBuilder addBool(String name, Boolean value) { return addIfNotNull(name, value); } + public ToStringBuilder addBool(String name, Boolean value, Boolean ignoreValue) { + return addIfNotIgnored(name, value, ignoreValue, Object::toString); + } + public ToStringBuilder addBoolIfTrue(String name, Boolean value) { if (TRUE.equals(value)) { addLabel(name); diff --git a/src/test/java/org/opentripplanner/framework/tostring/ToStringBuilderTest.java b/src/test/java/org/opentripplanner/framework/tostring/ToStringBuilderTest.java index ca35c8272db..1387c9af905 100644 --- a/src/test/java/org/opentripplanner/framework/tostring/ToStringBuilderTest.java +++ b/src/test/java/org/opentripplanner/framework/tostring/ToStringBuilderTest.java @@ -77,6 +77,11 @@ public void addBool() { "ToStringBuilderTest{a: true, b: false}", subject().addBool("a", true).addBool("b", false).toString() ); + + assertEquals( + "ToStringBuilderTest{a: true}", + subject().addBool("a", true, false).addBool("b", false, false).toString() + ); } @Test From 8ddc392b910a555772f1970cc7e27c18419f4602 Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Mon, 20 Nov 2023 17:34:50 +0200 Subject: [PATCH 02/21] Refactor so that there are own parking preferences for bike and car --- .../common/RequestToPreferencesMapper.java | 14 ++ .../api/common/RoutingResource.java | 16 -- .../apis/gtfs/mapping/RouteRequestMapper.java | 70 ++++--- .../org/opentripplanner/model/plan/Place.java | 6 +- .../request/preference/BikePreferences.java | 20 ++ .../request/preference/CarPreferences.java | 20 ++ .../preference/ParkingPreferences.java | 186 ++++++++++++++++++ .../api/request/request/JourneyRequest.java | 6 - .../request/VehicleParkingRequest.java | 68 ------- .../filter/VehicleParkingFilterRequest.java | 24 ++- .../routerequest/RouteRequestConfig.java | 119 +++++++---- .../model/edge/StreetVehicleParkingLink.java | 12 +- .../street/model/edge/VehicleParkingEdge.java | 24 ++- .../search/request/StreetSearchRequest.java | 8 - .../request/StreetSearchRequestBuilder.java | 8 - .../request/StreetSearchRequestMapper.java | 2 - .../gtfs/mapping/RouteRequestMapperTest.java | 40 ---- .../preference/ParkingPreferencesTest.java | 89 +++++++++ .../street/integration/ParkAndRideTest.java | 31 +-- .../edge/StreetVehicleParkingLinkTest.java | 20 +- .../model/edge/VehicleParkingEdgeTest.java | 17 +- .../edge/VehicleParkingPreferredTagsTest.java | 23 +-- 22 files changed, 546 insertions(+), 277 deletions(-) create mode 100644 src/main/java/org/opentripplanner/routing/api/request/preference/ParkingPreferences.java delete mode 100644 src/main/java/org/opentripplanner/routing/api/request/request/VehicleParkingRequest.java create mode 100644 src/test/java/org/opentripplanner/routing/api/request/preference/ParkingPreferencesTest.java diff --git a/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java b/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java index 20ca8054308..cb52965a8d5 100644 --- a/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java +++ b/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java @@ -6,6 +6,7 @@ import org.opentripplanner.routing.algorithm.filterchain.api.TransitGeneralizedCostFilterParams; import org.opentripplanner.routing.api.request.framework.CostLinearFunction; import org.opentripplanner.routing.api.request.preference.ItineraryFilterPreferences; +import org.opentripplanner.routing.api.request.preference.ParkingPreferences; import org.opentripplanner.routing.api.request.preference.RoutingPreferences; import org.opentripplanner.routing.core.BicycleOptimizeType; @@ -44,6 +45,7 @@ private void mapCar() { setIfNotNull(req.carReluctance, car::withReluctance); setIfNotNull(req.carParkCost, car::withParkCost); setIfNotNull(req.carParkTime, car::withParkTime); + car.withParking(parking -> mapParking(parking)); }); } @@ -76,6 +78,8 @@ private void mapBike() { setIfNotNull(req.triangleSafetyFactor, triangle::withSafety); }); } + + bike.withParking(parking -> mapParking(parking)); }); } @@ -159,6 +163,16 @@ private TransitGeneralizedCostFilterParams mapTransitGeneralizedCostFilterParams return new TransitGeneralizedCostFilterParams(costLimitFunction, intervalRelaxFactor); } + private void mapParking(ParkingPreferences.Builder builder) { + setIfNotNull( + req.useVehicleParkingAvailabilityInformation, + builder::withUseAvailabilityInformation + ); + + builder.withRequiredVehicleParkingTags(req.requiredVehicleParkingTags); + builder.withBannedVehicleParkingTags(req.bannedVehicleParkingTags); + } + private void mapSystem() { preferences.withSystem(system -> { setIfNotNull(req.geoidElevation, system::withGeoidElevation); diff --git a/src/main/java/org/opentripplanner/api/common/RoutingResource.java b/src/main/java/org/opentripplanner/api/common/RoutingResource.java index e60bfe41b82..143e99d2e93 100644 --- a/src/main/java/org/opentripplanner/api/common/RoutingResource.java +++ b/src/main/java/org/opentripplanner/api/common/RoutingResource.java @@ -27,8 +27,6 @@ import org.opentripplanner.routing.api.request.preference.ItineraryFilterDebugProfile; import org.opentripplanner.routing.api.request.request.filter.SelectRequest; import org.opentripplanner.routing.api.request.request.filter.TransitFilterRequest; -import org.opentripplanner.routing.api.request.request.filter.VehicleParkingFilter.TagsFilter; -import org.opentripplanner.routing.api.request.request.filter.VehicleParkingFilterRequest; import org.opentripplanner.routing.core.BicycleOptimizeType; import org.opentripplanner.standalone.api.OtpServerRequestContext; import org.opentripplanner.standalone.config.framework.file.ConfigFileLoader; @@ -749,20 +747,6 @@ protected RouteRequest buildRequest(MultivaluedMap queryParamete setIfNotNull(allowedVehicleRentalNetworks, rental::setAllowedNetworks); setIfNotNull(bannedVehicleRentalNetworks, rental::setBannedNetworks); } - { - var parking = journey.parking(); - setIfNotNull( - useVehicleParkingAvailabilityInformation, - parking::setUseAvailabilityInformation - ); - - parking.setFilter( - new VehicleParkingFilterRequest( - new TagsFilter(bannedVehicleParkingTags), - new TagsFilter(requiredVehicleParkingTags) - ) - ); - } setIfNotNull(arriveBy, request::setArriveBy); diff --git a/src/main/java/org/opentripplanner/apis/gtfs/mapping/RouteRequestMapper.java b/src/main/java/org/opentripplanner/apis/gtfs/mapping/RouteRequestMapper.java index 9b8d8e02dec..f9a0bcb703e 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/mapping/RouteRequestMapper.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/mapping/RouteRequestMapper.java @@ -21,11 +21,9 @@ import org.opentripplanner.routing.api.request.RouteRequest; import org.opentripplanner.routing.api.request.framework.CostLinearFunction; import org.opentripplanner.routing.api.request.preference.ItineraryFilterDebugProfile; +import org.opentripplanner.routing.api.request.preference.ParkingPreferences; import org.opentripplanner.routing.api.request.request.filter.SelectRequest; import org.opentripplanner.routing.api.request.request.filter.TransitFilterRequest; -import org.opentripplanner.routing.api.request.request.filter.VehicleParkingFilter; -import org.opentripplanner.routing.api.request.request.filter.VehicleParkingFilter.TagsFilter; -import org.opentripplanner.routing.api.request.request.filter.VehicleParkingFilterRequest; import org.opentripplanner.routing.core.BicycleOptimizeType; import org.opentripplanner.transit.model.basic.MainAndSubMode; import org.opentripplanner.transit.model.basic.TransitMode; @@ -84,9 +82,14 @@ public static RouteRequest toRouteRequest( callWith.argument("triangle.safetyFactor", triangle::withSafety); }); } + + bike.withParking(parking -> setParkingPreferences(callWith, parking)); }); - preferences.withCar(car -> callWith.argument("carReluctance", car::withReluctance)); + preferences.withCar(car -> { + callWith.argument("carReluctance", car::withReluctance); + car.withParking(parking -> setParkingPreferences(callWith, parking)); + }); preferences.withWalk(b -> { callWith.argument("walkReluctance", b::withReluctance); @@ -244,19 +247,6 @@ public static RouteRequest toRouteRequest( (Collection v) -> vehicleRental.setBannedNetworks(new HashSet<>(v)) ); - var parking = request.journey().parking(); - callWith.argument("parking.unpreferredCost", parking::setUnpreferredCost); - - callWith.argument( - "parking.filters", - (Collection> filters) -> parking.setFilter(parseFilters(filters)) - ); - - callWith.argument( - "parking.preferred", - (Collection> filters) -> parking.setPreferred(parseFilters(filters)) - ); - callWith.argument( "locale", (String v) -> request.setLocale(GraphQLUtils.getLocale(environment, v)) @@ -264,17 +254,16 @@ public static RouteRequest toRouteRequest( return request; } - private static VehicleParkingFilterRequest parseFilters(Collection> filters) { - var not = parseFilters(filters, "not"); - var select = parseFilters(filters, "select"); - return new VehicleParkingFilterRequest(not, select); + private static Set parseNotFilters(Collection> filters) { + return parseFilters(filters, "not"); + } + + private static Set parseSelectFilters(Collection> filters) { + return parseFilters(filters, "select"); } @Nonnull - private static Set parseFilters( - Collection> filters, - String key - ) { + private static Set parseFilters(Collection> filters, String key) { return filters .stream() .flatMap(f -> @@ -283,14 +272,12 @@ private static Set parseFilters( .collect(Collectors.toSet()); } - private static Stream parseOperation( - Collection>> map - ) { + private static Stream parseOperation(Collection>> map) { return map .stream() - .map(f -> { + .flatMap(f -> { var tags = f.getOrDefault("tags", List.of()); - return new TagsFilter(Set.copyOf(tags)); + return tags.stream(); }); } @@ -314,6 +301,29 @@ private static GenericLocation toGenericLocation(Map m) { return new GenericLocation(lat, lng); } + private static void setParkingPreferences( + CallerWithEnvironment callWith, + ParkingPreferences.Builder parking + ) { + callWith.argument("parking.unpreferredCost", parking::withUnpreferredVehicleParkingTagCost); + + callWith.argument( + "parking.filters", + (Collection> filters) -> { + parking.withRequiredVehicleParkingTags(parseSelectFilters(filters)); + parking.withBannedVehicleParkingTags(parseNotFilters(filters)); + } + ); + + callWith.argument( + "parking.preferred", + (Collection> preferred) -> { + parking.withPreferredVehicleParkingTags(parseSelectFilters(preferred)); + parking.withNotPreferredVehicleParkingTags(parseNotFilters(preferred)); + } + ); + } + private static class CallerWithEnvironment { private final DataFetchingEnvironment environment; diff --git a/src/main/java/org/opentripplanner/model/plan/Place.java b/src/main/java/org/opentripplanner/model/plan/Place.java index f20bb2a0cb9..2a1b10b0250 100644 --- a/src/main/java/org/opentripplanner/model/plan/Place.java +++ b/src/main/java/org/opentripplanner/model/plan/Place.java @@ -135,8 +135,12 @@ public static Place forVehicleParkingEntrance(VehicleParkingEntranceVertex verte traverseMode = TraverseMode.BICYCLE; } + var parkingPreferences = traverseMode == TraverseMode.CAR + ? request.preferences().car().parkingPreferences() + : request.preferences().bike().parkingPreferences(); + boolean realTime = - request.parking().useAvailabilityInformation() && + parkingPreferences.useAvailabilityInformation() && vertex.getVehicleParking().hasRealTimeDataForMode(traverseMode, request.wheelchair()); return new Place( vertex.getName(), diff --git a/src/main/java/org/opentripplanner/routing/api/request/preference/BikePreferences.java b/src/main/java/org/opentripplanner/routing/api/request/preference/BikePreferences.java index 0985a132dd0..b470ec621c8 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/preference/BikePreferences.java +++ b/src/main/java/org/opentripplanner/routing/api/request/preference/BikePreferences.java @@ -30,6 +30,7 @@ public final class BikePreferences implements Serializable { private final Cost switchCost; private final int parkTime; private final Cost parkCost; + private final ParkingPreferences parkingPreferences; private final double stairsReluctance; private final BicycleOptimizeType optimizeType; private final TimeSlopeSafetyTriangle optimizeTriangle; @@ -45,6 +46,7 @@ private BikePreferences() { this.parkTime = 60; /** Cost of parking a bike. */ this.parkCost = Cost.costOfSeconds(120); + this.parkingPreferences = ParkingPreferences.DEFAULT; this.optimizeType = BicycleOptimizeType.SAFE; this.optimizeTriangle = TimeSlopeSafetyTriangle.DEFAULT; // very high reluctance to carry the bike up/down a flight of stairs @@ -61,6 +63,7 @@ private BikePreferences(Builder builder) { this.switchCost = builder.switchCost; this.parkTime = Units.duration(builder.parkTime); this.parkCost = builder.parkCost; + this.parkingPreferences = builder.parkingPreferences; this.optimizeType = Objects.requireNonNull(builder.optimizeType); this.optimizeTriangle = Objects.requireNonNull(builder.optimizeTriangle); this.stairsReluctance = Units.reluctance(builder.stairsReluctance); @@ -134,6 +137,11 @@ public int parkCost() { return parkCost.toSeconds(); } + /** Parking preferences that can be different per request */ + public ParkingPreferences parkingPreferences() { + return parkingPreferences; + } + /** * The set of characteristics that the user wants to optimize for -- defaults to SAFE. */ @@ -164,6 +172,7 @@ public boolean equals(Object o) { switchCost.equals(that.switchCost) && parkTime == that.parkTime && parkCost.equals(that.parkCost) && + parkingPreferences.equals(that.parkingPreferences) && optimizeType == that.optimizeType && optimizeTriangle.equals(that.optimizeTriangle) && doubleEquals(stairsReluctance, that.stairsReluctance) @@ -182,6 +191,7 @@ public int hashCode() { switchCost, parkTime, parkCost, + parkingPreferences, optimizeType, optimizeTriangle, stairsReluctance @@ -201,6 +211,7 @@ public String toString() { .addObj("switchCost", switchCost, DEFAULT.switchCost) .addDurationSec("parkTime", parkTime, DEFAULT.parkTime) .addObj("parkCost", parkCost, DEFAULT.parkCost) + .addObj("parkingPreferences", parkingPreferences, DEFAULT.parkingPreferences) .addEnum("optimizeType", optimizeType, DEFAULT.optimizeType) .addObj("optimizeTriangle", optimizeTriangle, DEFAULT.optimizeTriangle) .toString(); @@ -219,6 +230,7 @@ public static class Builder { private Cost switchCost; private int parkTime; private Cost parkCost; + private ParkingPreferences parkingPreferences; private BicycleOptimizeType optimizeType; private TimeSlopeSafetyTriangle optimizeTriangle; @@ -235,6 +247,7 @@ public Builder(BikePreferences original) { this.switchCost = original.switchCost; this.parkTime = original.parkTime; this.parkCost = original.parkCost; + this.parkingPreferences = original.parkingPreferences; this.optimizeType = original.optimizeType; this.optimizeTriangle = original.optimizeTriangle; this.stairsReluctance = original.stairsReluctance; @@ -325,6 +338,13 @@ public Builder withParkCost(int parkCost) { return this; } + public Builder withParking(Consumer body) { + var builder = ParkingPreferences.of(); + body.accept(builder); + this.parkingPreferences = builder.build(); + return this; + } + public BicycleOptimizeType optimizeType() { return optimizeType; } diff --git a/src/main/java/org/opentripplanner/routing/api/request/preference/CarPreferences.java b/src/main/java/org/opentripplanner/routing/api/request/preference/CarPreferences.java index 014b2b0cdec..5bb5bfcea9c 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/preference/CarPreferences.java +++ b/src/main/java/org/opentripplanner/routing/api/request/preference/CarPreferences.java @@ -23,6 +23,7 @@ public final class CarPreferences implements Serializable { private final double reluctance; private final int parkTime; private final Cost parkCost; + private final ParkingPreferences parkingPreferences; private final int pickupTime; private final Cost pickupCost; private final int dropoffTime; @@ -35,6 +36,7 @@ private CarPreferences() { this.reluctance = 2.0; this.parkTime = 60; this.parkCost = Cost.costOfMinutes(2); + this.parkingPreferences = ParkingPreferences.DEFAULT; this.pickupTime = 60; this.pickupCost = Cost.costOfMinutes(2); this.dropoffTime = 120; @@ -47,6 +49,7 @@ private CarPreferences(Builder builder) { this.reluctance = Units.reluctance(builder.reluctance); this.parkTime = Units.duration(builder.parkTime); this.parkCost = builder.parkCost; + this.parkingPreferences = builder.parkingPreferences; this.pickupTime = Units.duration(builder.pickupTime); this.pickupCost = builder.pickupCost; this.dropoffTime = Units.duration(builder.dropoffTime); @@ -85,6 +88,11 @@ public int parkCost() { return parkCost.toSeconds(); } + /** Parking preferences that can be different per request */ + public ParkingPreferences parkingPreferences() { + return parkingPreferences; + } + /** Time of getting in/out of a carPickup (taxi) */ public int pickupTime() { return pickupTime; @@ -129,6 +137,7 @@ public boolean equals(Object o) { DoubleUtils.doubleEquals(that.reluctance, reluctance) && parkTime == that.parkTime && parkCost.equals(that.parkCost) && + parkingPreferences.equals(that.parkingPreferences) && pickupTime == that.pickupTime && pickupCost.equals(that.pickupCost) && dropoffTime == that.dropoffTime && @@ -144,6 +153,7 @@ public int hashCode() { reluctance, parkTime, parkCost, + parkingPreferences, pickupTime, pickupCost, dropoffTime, @@ -160,6 +170,7 @@ public String toString() { .addNum("reluctance", reluctance, DEFAULT.reluctance) .addNum("parkTime", parkTime, DEFAULT.parkTime) .addObj("parkCost", parkCost, DEFAULT.parkCost) + .addObj("parkingPreferences", parkingPreferences, DEFAULT.parkingPreferences) .addNum("pickupTime", pickupTime, DEFAULT.pickupTime) .addObj("pickupCost", pickupCost, DEFAULT.pickupCost) .addNum("dropoffTime", dropoffTime, DEFAULT.dropoffTime) @@ -176,6 +187,7 @@ public static class Builder { private double reluctance; private int parkTime; private Cost parkCost; + private ParkingPreferences parkingPreferences; private int pickupTime; private Cost pickupCost; private int dropoffTime; @@ -188,6 +200,7 @@ public Builder(CarPreferences original) { this.reluctance = original.reluctance; this.parkTime = original.parkTime; this.parkCost = original.parkCost; + this.parkingPreferences = original.parkingPreferences; this.pickupTime = original.pickupTime; this.pickupCost = original.pickupCost; this.dropoffTime = original.dropoffTime; @@ -219,6 +232,13 @@ public Builder withParkCost(int parkCost) { return this; } + public Builder withParking(Consumer body) { + var builder = ParkingPreferences.of(); + body.accept(builder); + this.parkingPreferences = builder.build(); + return this; + } + public Builder withPickupTime(int pickupTime) { this.pickupTime = pickupTime; return this; diff --git a/src/main/java/org/opentripplanner/routing/api/request/preference/ParkingPreferences.java b/src/main/java/org/opentripplanner/routing/api/request/preference/ParkingPreferences.java new file mode 100644 index 00000000000..adeeb41ceed --- /dev/null +++ b/src/main/java/org/opentripplanner/routing/api/request/preference/ParkingPreferences.java @@ -0,0 +1,186 @@ +package org.opentripplanner.routing.api.request.preference; + +import java.io.Serializable; +import java.util.List; +import java.util.Objects; +import java.util.Set; +import org.opentripplanner.framework.model.Cost; +import org.opentripplanner.framework.tostring.ToStringBuilder; +import org.opentripplanner.routing.api.request.request.filter.VehicleParkingFilter; +import org.opentripplanner.routing.api.request.request.filter.VehicleParkingFilterRequest; + +/** + * The parking preferences contain preferences for car and bicycle parking. These preferences + * include filtering, preference and realtime usage. + *

+ * THIS CLASS IS IMMUTABLE AND THREAD-SAFE. + */ +public final class ParkingPreferences implements Serializable { + + public static final ParkingPreferences DEFAULT = new ParkingPreferences(); + private final Cost unpreferredVehicleParkingTagCost; + private final boolean useAvailabilityInformation; + private final VehicleParkingFilterRequest filter; + private final VehicleParkingFilterRequest preferred; + + /** Create a new instance with default values. */ + private ParkingPreferences() { + this.unpreferredVehicleParkingTagCost = Cost.costOfSeconds(5 * 60); + this.useAvailabilityInformation = true; + this.filter = VehicleParkingFilterRequest.empty(); + this.preferred = VehicleParkingFilterRequest.empty(); + } + + private ParkingPreferences(Builder builder) { + this.unpreferredVehicleParkingTagCost = builder.unpreferredVehicleParkingTagCost; + this.useAvailabilityInformation = builder.useAvailabilityInformation; + this.filter = + new VehicleParkingFilterRequest( + builder.bannedVehicleParkingTags, + builder.requiredVehicleParkingTags + ); + this.preferred = + new VehicleParkingFilterRequest( + builder.notPreferredVehicleParkingTags, + builder.preferredVehicleParkingTags + ); + } + + public static ParkingPreferences.Builder of() { + return new Builder(DEFAULT); + } + + /** + * What cost is applied to using parking that is not preferred. + */ + public Cost unpreferredVehicleParkingTagCost() { + return unpreferredVehicleParkingTagCost; + } + + /** + * Should availability information be used during routing. + */ + public boolean useAvailabilityInformation() { + return useAvailabilityInformation; + } + + /** + * Parking containing select filters must only be usable and parking containing with not filters + * cannot be used. + */ + public VehicleParkingFilterRequest filter() { + return filter; + } + + /** + * Which vehicle parking tags are preferred. Vehicle parking facilities that don't have one of these + * tags receive an extra cost. + *

+ * This is useful if you want to use certain kind of facilities, like lockers for expensive e-bikes. + */ + public VehicleParkingFilterRequest preferred() { + return preferred; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ParkingPreferences that = (ParkingPreferences) o; + return ( + Objects.equals(unpreferredVehicleParkingTagCost, that.unpreferredVehicleParkingTagCost) && + useAvailabilityInformation == that.useAvailabilityInformation && + Objects.equals(filter, that.filter) && + Objects.equals(preferred, that.preferred) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + unpreferredVehicleParkingTagCost, + useAvailabilityInformation, + filter, + preferred + ); + } + + @Override + public String toString() { + return ToStringBuilder + .of(ParkingPreferences.class) + .addObj( + "unpreferredVehicleParkingTagCost", + unpreferredVehicleParkingTagCost, + DEFAULT.unpreferredVehicleParkingTagCost + ) + .addBool( + "useAvailabilityInformation", + useAvailabilityInformation, + DEFAULT.useAvailabilityInformation + ) + .addObj("filter", filter, DEFAULT.filter) + .addObj("preferred", preferred, DEFAULT.preferred) + .toString(); + } + + public static class Builder { + + private final ParkingPreferences original; + private Cost unpreferredVehicleParkingTagCost; + private boolean useAvailabilityInformation; + private List bannedVehicleParkingTags; + private List requiredVehicleParkingTags; + private List preferredVehicleParkingTags; + private List notPreferredVehicleParkingTags; + + private Builder(ParkingPreferences original) { + this.original = original; + this.unpreferredVehicleParkingTagCost = original.unpreferredVehicleParkingTagCost; + this.useAvailabilityInformation = original.useAvailabilityInformation; + this.bannedVehicleParkingTags = original.filter.not(); + this.requiredVehicleParkingTags = original.filter.select(); + this.preferredVehicleParkingTags = original.preferred.select(); + this.notPreferredVehicleParkingTags = original.preferred.not(); + } + + public Builder withUnpreferredVehicleParkingTagCost(int cost) { + this.unpreferredVehicleParkingTagCost = Cost.costOfSeconds(cost); + return this; + } + + public Builder withUseAvailabilityInformation(boolean useAvailabilityInformation) { + this.useAvailabilityInformation = useAvailabilityInformation; + return this; + } + + public Builder withBannedVehicleParkingTags(Set bannedVehicleParkingTags) { + this.bannedVehicleParkingTags = + List.of(new VehicleParkingFilter.TagsFilter(bannedVehicleParkingTags)); + return this; + } + + public Builder withRequiredVehicleParkingTags(Set requiredVehicleParkingTags) { + this.requiredVehicleParkingTags = + List.of(new VehicleParkingFilter.TagsFilter(requiredVehicleParkingTags)); + return this; + } + + public Builder withPreferredVehicleParkingTags(Set preferredVehicleParkingTags) { + this.preferredVehicleParkingTags = + List.of(new VehicleParkingFilter.TagsFilter(preferredVehicleParkingTags)); + return this; + } + + public Builder withNotPreferredVehicleParkingTags(Set notPreferredVehicleParkingTags) { + this.notPreferredVehicleParkingTags = + List.of(new VehicleParkingFilter.TagsFilter(notPreferredVehicleParkingTags)); + return this; + } + + public ParkingPreferences build() { + var newObj = new ParkingPreferences(this); + return original.equals(newObj) ? original : newObj; + } + } +} diff --git a/src/main/java/org/opentripplanner/routing/api/request/request/JourneyRequest.java b/src/main/java/org/opentripplanner/routing/api/request/request/JourneyRequest.java index b500bdd2398..39a775bf7f5 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/request/JourneyRequest.java +++ b/src/main/java/org/opentripplanner/routing/api/request/request/JourneyRequest.java @@ -8,7 +8,6 @@ public class JourneyRequest implements Cloneable, Serializable { // TODO VIA (Hannes): Move the fields below into StreetRequest private VehicleRentalRequest rental = new VehicleRentalRequest(); - private VehicleParkingRequest parking = new VehicleParkingRequest(); private TransitRequest transit = new TransitRequest(); private StreetRequest access = new StreetRequest(); private StreetRequest egress = new StreetRequest(); @@ -19,10 +18,6 @@ public VehicleRentalRequest rental() { return rental; } - public VehicleParkingRequest parking() { - return parking; - } - public TransitRequest transit() { return transit; } @@ -64,7 +59,6 @@ public JourneyRequest clone() { try { var clone = (JourneyRequest) super.clone(); clone.rental = this.rental.clone(); - clone.parking = this.parking.clone(); clone.transit = this.transit.clone(); clone.access = this.access.clone(); clone.egress = this.egress.clone(); diff --git a/src/main/java/org/opentripplanner/routing/api/request/request/VehicleParkingRequest.java b/src/main/java/org/opentripplanner/routing/api/request/request/VehicleParkingRequest.java deleted file mode 100644 index d63ba79b990..00000000000 --- a/src/main/java/org/opentripplanner/routing/api/request/request/VehicleParkingRequest.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.opentripplanner.routing.api.request.request; - -import java.io.Serializable; -import org.opentripplanner.routing.api.request.request.filter.VehicleParkingFilterRequest; - -/** - * Class that stores information about what kind of parking lots should be used for Park & Ride - * and Bike & Ride searches. - */ -public class VehicleParkingRequest implements Cloneable, Serializable { - - private VehicleParkingFilterRequest filter = VehicleParkingFilterRequest.empty(); - private VehicleParkingFilterRequest preferred = VehicleParkingFilterRequest.empty(); - private int unpreferredTagCost = 5 * 60; - - private boolean useAvailabilityInformation = false; - - public void setFilter(VehicleParkingFilterRequest filter) { - this.filter = filter; - } - - public void setPreferred(VehicleParkingFilterRequest filter) { - this.preferred = filter; - } - - /** - * Which vehicle parking tags are preferred. Vehicle parking facilities that don't have one of these - * tags receive an extra cost. - *

- * This is useful if you want to use certain kind of facilities, like lockers for expensive e-bikes. - */ - public VehicleParkingFilterRequest preferred() { - return this.preferred; - } - - public void setUnpreferredCost(int cost) { - unpreferredTagCost = cost; - } - - public int unpreferredCost() { - return unpreferredTagCost; - } - - /** - * If realtime availability data should be used when deciding af a parking facility should be - * used. - */ - public void setUseAvailabilityInformation(boolean b) { - useAvailabilityInformation = b; - } - - public boolean useAvailabilityInformation() { - return useAvailabilityInformation; - } - - public VehicleParkingRequest clone() { - try { - return (VehicleParkingRequest) super.clone(); - } catch (CloneNotSupportedException e) { - /* this will never happen since our super is the cloneable object */ - throw new RuntimeException(e); - } - } - - public VehicleParkingFilterRequest filter() { - return filter; - } -} diff --git a/src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingFilterRequest.java b/src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingFilterRequest.java index abe07010bcd..353ac72ada9 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingFilterRequest.java +++ b/src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingFilterRequest.java @@ -1,5 +1,6 @@ package org.opentripplanner.routing.api.request.request.filter; +import java.io.Serializable; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -11,7 +12,7 @@ * A request object that checks if parking faclities match certain conditions for * inclusion/exclusion or preference/unpreference. */ -public class VehicleParkingFilterRequest { +public class VehicleParkingFilterRequest implements Serializable { private final VehicleParkingFilter[] not; private final VehicleParkingFilter[] select; @@ -28,6 +29,14 @@ public VehicleParkingFilterRequest(VehicleParkingFilter not, VehicleParkingFilte this(List.of(not), List.of(select)); } + public List not() { + return Arrays.asList(not); + } + + public List select() { + return Arrays.asList(select); + } + /** * Create a request with no conditions. */ @@ -65,6 +74,19 @@ public String toString() { .toString(); } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + VehicleParkingFilterRequest that = (VehicleParkingFilterRequest) o; + return (Arrays.equals(not, that.not) && Arrays.equals(select, that.select)); + } + + @Override + public int hashCode() { + return Arrays.hashCode(not) + Arrays.hashCode(select); + } + @Nonnull private static VehicleParkingFilter[] makeFilter(Collection select) { return select.stream().filter(f -> !f.isEmpty()).toArray(VehicleParkingFilter[]::new); diff --git a/src/main/java/org/opentripplanner/standalone/config/routerequest/RouteRequestConfig.java b/src/main/java/org/opentripplanner/standalone/config/routerequest/RouteRequestConfig.java index c89670b7e0a..4de3d281a03 100644 --- a/src/main/java/org/opentripplanner/standalone/config/routerequest/RouteRequestConfig.java +++ b/src/main/java/org/opentripplanner/standalone/config/routerequest/RouteRequestConfig.java @@ -19,14 +19,12 @@ import org.opentripplanner.routing.api.request.StreetMode; import org.opentripplanner.routing.api.request.preference.BikePreferences; import org.opentripplanner.routing.api.request.preference.CarPreferences; +import org.opentripplanner.routing.api.request.preference.ParkingPreferences; import org.opentripplanner.routing.api.request.preference.RoutingPreferences; import org.opentripplanner.routing.api.request.preference.StreetPreferences; import org.opentripplanner.routing.api.request.preference.SystemPreferences; import org.opentripplanner.routing.api.request.preference.TransitPreferences; import org.opentripplanner.routing.api.request.preference.WalkPreferences; -import org.opentripplanner.routing.api.request.request.VehicleParkingRequest; -import org.opentripplanner.routing.api.request.request.filter.VehicleParkingFilter.TagsFilter; -import org.opentripplanner.routing.api.request.request.filter.VehicleParkingFilterRequest; import org.opentripplanner.standalone.config.framework.json.NodeAdapter; import org.opentripplanner.standalone.config.sandbox.DataOverlayParametersMapper; import org.opentripplanner.transit.model.basic.TransitMode; @@ -55,7 +53,6 @@ public static RouteRequest mapRouteRequest(NodeAdapter c, RouteRequest dft) { } RouteRequest request = dft.clone(); - VehicleParkingRequest vehicleParking = request.journey().parking(); // Keep this alphabetically sorted so it is easy to check if a parameter is missing from the // mapping or duplicate exist. @@ -121,44 +118,6 @@ latest arrival time (LAT - EAT). .asDuration(dft.searchWindow()) ); - vehicleParking.setUnpreferredCost( - c - .of("unpreferredVehicleParkingTagCost") - .since(V2_3) - .summary("What cost to add if a parking facility doesn't contain a preferred tag.") - .description("See `preferredVehicleParkingTags`.") - .asInt(vehicleParking.unpreferredCost()) - ); - - var bannedTags = c - .of("bannedVehicleParkingTags") - .since(V2_1) - .summary("Tags with which a vehicle parking will not be used. If empty, no tags are banned.") - .asStringSet(List.of()); - - var requiredTags = c - .of("requiredVehicleParkingTags") - .since(V2_1) - .summary( - "Tags without which a vehicle parking will not be used. If empty, no tags are required." - ) - .asStringSet(List.of()); - vehicleParking.setFilter( - new VehicleParkingFilterRequest(new TagsFilter(bannedTags), new TagsFilter(requiredTags)) - ); - - var preferredTags = c - .of("preferredVehicleParkingTags") - .since(V2_3) - .summary( - "Vehicle parking facilities that don't have one of these tags will receive an extra cost and will therefore be penalised." - ) - .asStringSet(List.of()); - - vehicleParking.setPreferred( - new VehicleParkingFilterRequest(List.of(), List.of(new TagsFilter(preferredTags))) - ); - request.setWheelchair(WheelchairConfig.wheelchairEnabled(c, WHEELCHAIR_ACCESSIBILITY)); NodeAdapter unpreferred = c @@ -462,6 +421,44 @@ private static void mapBikePreferences(NodeAdapter c, BikePreferences.Builder bu "How bad is it to walk the bicycle up/down a flight of stairs compared to taking a detour." ) .asDouble(dft.stairsReluctance()) + ) + .withParking(it -> + it + .withUnpreferredVehicleParkingTagCost( + c + .of("unpreferredVehicleParkingTagCost") + .since(V2_3) + .summary("What cost to add if a parking facility doesn't contain a preferred tag.") + .description("See `preferredVehicleParkingTags`.") + .asInt(ParkingPreferences.DEFAULT.unpreferredVehicleParkingTagCost().toSeconds()) + ) + .withBannedVehicleParkingTags( + c + .of("bannedVehicleParkingTags") + .since(V2_1) + .summary( + "Tags with which a vehicle parking will not be used. If empty, no tags are banned." + ) + .asStringSet(List.of()) + ) + .withRequiredVehicleParkingTags( + c + .of("requiredVehicleParkingTags") + .since(V2_1) + .summary( + "Tags without which a vehicle parking will not be used. If empty, no tags are required." + ) + .asStringSet(List.of()) + ) + .withPreferredVehicleParkingTags( + c + .of("preferredVehicleParkingTags") + .since(V2_3) + .summary( + "Vehicle parking facilities that don't have one of these tags will receive an extra cost and will therefore be penalised." + ) + .asStringSet(List.of()) + ) ); } @@ -712,6 +709,44 @@ private static void mapCarPreferences(NodeAdapter c, CarPreferences.Builder buil .since(V2_0) .summary("The deceleration speed of an automobile, in meters per second per second.") .asDouble(dft.decelerationSpeed()) + ) + .withParking(it -> + it + .withUnpreferredVehicleParkingTagCost( + c + .of("unpreferredVehicleParkingTagCost") + .since(V2_3) + .summary("What cost to add if a parking facility doesn't contain a preferred tag.") + .description("See `preferredVehicleParkingTags`.") + .asInt(ParkingPreferences.DEFAULT.unpreferredVehicleParkingTagCost().toSeconds()) + ) + .withBannedVehicleParkingTags( + c + .of("bannedVehicleParkingTags") + .since(V2_1) + .summary( + "Tags with which a vehicle parking will not be used. If empty, no tags are banned." + ) + .asStringSet(List.of()) + ) + .withRequiredVehicleParkingTags( + c + .of("requiredVehicleParkingTags") + .since(V2_1) + .summary( + "Tags without which a vehicle parking will not be used. If empty, no tags are required." + ) + .asStringSet(List.of()) + ) + .withPreferredVehicleParkingTags( + c + .of("preferredVehicleParkingTags") + .since(V2_3) + .summary( + "Vehicle parking facilities that don't have one of these tags will receive an extra cost and will therefore be penalised." + ) + .asStringSet(List.of()) + ) ); } diff --git a/src/main/java/org/opentripplanner/street/model/edge/StreetVehicleParkingLink.java b/src/main/java/org/opentripplanner/street/model/edge/StreetVehicleParkingLink.java index 460a5e2416a..62e873e6932 100644 --- a/src/main/java/org/opentripplanner/street/model/edge/StreetVehicleParkingLink.java +++ b/src/main/java/org/opentripplanner/street/model/edge/StreetVehicleParkingLink.java @@ -4,7 +4,7 @@ import org.locationtech.jts.geom.LineString; import org.opentripplanner.framework.i18n.I18NString; import org.opentripplanner.framework.tostring.ToStringBuilder; -import org.opentripplanner.routing.api.request.request.VehicleParkingRequest; +import org.opentripplanner.routing.api.request.preference.ParkingPreferences; import org.opentripplanner.routing.vehicle_parking.VehicleParking; import org.opentripplanner.street.model.vertex.StreetVertex; import org.opentripplanner.street.model.vertex.VehicleParkingEntranceVertex; @@ -68,8 +68,10 @@ public State[] traverse(State s0) { } var vehicleParking = vehicleParkingEntranceVertex.getVehicleParking(); - final VehicleParkingRequest parkingRequest = s0.getRequest().parking(); - if (traversalBanned(parkingRequest, vehicleParking)) { + final ParkingPreferences parkingPreferences = s0.currentMode() == TraverseMode.CAR + ? s0.getRequest().preferences().car().parkingPreferences() + : s0.getRequest().preferences().bike().parkingPreferences(); + if (traversalBanned(parkingPreferences, vehicleParking)) { return State.empty(); } @@ -81,10 +83,10 @@ public State[] traverse(State s0) { } private boolean traversalBanned( - VehicleParkingRequest parkingRequest, + ParkingPreferences parkingPreferences, VehicleParking vehicleParking ) { - return !parkingRequest.filter().matches(vehicleParking); + return !parkingPreferences.filter().matches(vehicleParking); } @Override diff --git a/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java b/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java index 93a2b9bed0c..a29bc7e94c3 100644 --- a/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java +++ b/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java @@ -5,8 +5,8 @@ import org.opentripplanner.routing.api.request.StreetMode; import org.opentripplanner.routing.api.request.preference.BikePreferences; import org.opentripplanner.routing.api.request.preference.CarPreferences; +import org.opentripplanner.routing.api.request.preference.ParkingPreferences; import org.opentripplanner.routing.api.request.preference.RoutingPreferences; -import org.opentripplanner.routing.api.request.request.VehicleParkingRequest; import org.opentripplanner.routing.vehicle_parking.VehicleParking; import org.opentripplanner.street.model.vertex.VehicleParkingEntranceVertex; import org.opentripplanner.street.search.TraverseMode; @@ -103,11 +103,12 @@ protected State[] traverseUnPark(State s0) { private State[] traverseUnPark(State s0, int parkingCost, int parkingTime, TraverseMode mode) { final StreetSearchRequest request = s0.getRequest(); + var parkingPreferences = getParkingPreferences(s0.currentMode(), s0.getRequest()); if ( !vehicleParking.hasSpacesAvailable( mode, request.wheelchair(), - request.parking().useAvailabilityInformation() + parkingPreferences.useAvailabilityInformation() ) ) { return State.empty(); @@ -118,7 +119,7 @@ private State[] traverseUnPark(State s0, int parkingCost, int parkingTime, Trave s0e.incrementTimeInSeconds(parkingTime); s0e.setVehicleParked(false, mode); - addUnpreferredTagCost(request.parking(), s0e); + addUnpreferredTagCost(parkingPreferences, s0e); return s0e.makeStateArray(); } @@ -146,11 +147,12 @@ private State[] traversePark(State s0) { } private State[] traversePark(State s0, int parkingCost, int parkingTime) { + var parkingPreferences = getParkingPreferences(s0.currentMode(), s0.getRequest()); if ( !vehicleParking.hasSpacesAvailable( s0.currentMode(), s0.getRequest().wheelchair(), - s0.getRequest().parking().useAvailabilityInformation() + parkingPreferences.useAvailabilityInformation() ) ) { return State.empty(); @@ -161,14 +163,20 @@ private State[] traversePark(State s0, int parkingCost, int parkingTime) { s0e.incrementTimeInSeconds(parkingTime); s0e.setVehicleParked(true, TraverseMode.WALK); - addUnpreferredTagCost(s0.getRequest().parking(), s0e); + addUnpreferredTagCost(parkingPreferences, s0e); return s0e.makeStateArray(); } - private void addUnpreferredTagCost(VehicleParkingRequest req, StateEditor s0e) { - if (!req.preferred().matches(vehicleParking)) { - s0e.incrementWeight(req.unpreferredCost()); + private void addUnpreferredTagCost(ParkingPreferences preferences, StateEditor s0e) { + if (!preferences.preferred().matches(vehicleParking)) { + s0e.incrementWeight(preferences.unpreferredVehicleParkingTagCost().toSeconds()); } } + + private ParkingPreferences getParkingPreferences(TraverseMode mode, StreetSearchRequest request) { + return mode == TraverseMode.CAR + ? request.preferences().car().parkingPreferences() + : request.preferences().bike().parkingPreferences(); + } } diff --git a/src/main/java/org/opentripplanner/street/search/request/StreetSearchRequest.java b/src/main/java/org/opentripplanner/street/search/request/StreetSearchRequest.java index 6f44351d27c..6d8bd5783f3 100644 --- a/src/main/java/org/opentripplanner/street/search/request/StreetSearchRequest.java +++ b/src/main/java/org/opentripplanner/street/search/request/StreetSearchRequest.java @@ -12,7 +12,6 @@ import org.opentripplanner.routing.api.request.RouteRequest; import org.opentripplanner.routing.api.request.StreetMode; import org.opentripplanner.routing.api.request.preference.RoutingPreferences; -import org.opentripplanner.routing.api.request.request.VehicleParkingRequest; import org.opentripplanner.routing.api.request.request.VehicleRentalRequest; import org.opentripplanner.street.model.vertex.Vertex; import org.opentripplanner.street.search.intersection_model.IntersectionTraversalCalculator; @@ -40,7 +39,6 @@ public class StreetSearchRequest implements AStarRequest { private final StreetMode mode; private final boolean arriveBy; private final boolean wheelchair; - private final VehicleParkingRequest parking; private final VehicleRentalRequest rental; private final GenericLocation from; @@ -62,7 +60,6 @@ private StreetSearchRequest() { this.mode = StreetMode.WALK; this.arriveBy = false; this.wheelchair = false; - this.parking = new VehicleParkingRequest(); this.rental = new VehicleRentalRequest(); this.from = null; this.fromEnvelope = null; @@ -76,7 +73,6 @@ private StreetSearchRequest() { this.mode = builder.mode; this.arriveBy = builder.arriveBy; this.wheelchair = builder.wheelchair; - this.parking = builder.parking; this.rental = builder.rental; this.from = builder.from; this.fromEnvelope = createEnvelope(from); @@ -119,10 +115,6 @@ public boolean wheelchair() { return wheelchair; } - public VehicleParkingRequest parking() { - return parking; - } - public VehicleRentalRequest rental() { return rental; } diff --git a/src/main/java/org/opentripplanner/street/search/request/StreetSearchRequestBuilder.java b/src/main/java/org/opentripplanner/street/search/request/StreetSearchRequestBuilder.java index 1f102c6b45f..439e65a3289 100644 --- a/src/main/java/org/opentripplanner/street/search/request/StreetSearchRequestBuilder.java +++ b/src/main/java/org/opentripplanner/street/search/request/StreetSearchRequestBuilder.java @@ -5,7 +5,6 @@ import org.opentripplanner.model.GenericLocation; import org.opentripplanner.routing.api.request.StreetMode; import org.opentripplanner.routing.api.request.preference.RoutingPreferences; -import org.opentripplanner.routing.api.request.request.VehicleParkingRequest; import org.opentripplanner.routing.api.request.request.VehicleRentalRequest; public class StreetSearchRequestBuilder { @@ -15,7 +14,6 @@ public class StreetSearchRequestBuilder { RoutingPreferences preferences; boolean arriveBy; boolean wheelchair; - VehicleParkingRequest parking; VehicleRentalRequest rental; GenericLocation from; GenericLocation to; @@ -26,7 +24,6 @@ public class StreetSearchRequestBuilder { this.preferences = original.preferences(); this.arriveBy = original.arriveBy(); this.wheelchair = original.wheelchair(); - this.parking = original.parking().clone(); this.rental = original.rental(); this.from = original.from(); this.to = original.to(); @@ -61,11 +58,6 @@ public StreetSearchRequestBuilder withWheelchair(boolean wheelchair) { return this; } - public StreetSearchRequestBuilder withParking(VehicleParkingRequest parking) { - this.parking = parking; - return this; - } - public StreetSearchRequestBuilder withRental(VehicleRentalRequest rental) { this.rental = rental; return this; diff --git a/src/main/java/org/opentripplanner/street/search/request/StreetSearchRequestMapper.java b/src/main/java/org/opentripplanner/street/search/request/StreetSearchRequestMapper.java index 902b6d6d92a..9f1f3c567f8 100644 --- a/src/main/java/org/opentripplanner/street/search/request/StreetSearchRequestMapper.java +++ b/src/main/java/org/opentripplanner/street/search/request/StreetSearchRequestMapper.java @@ -11,7 +11,6 @@ public static StreetSearchRequestBuilder map(RouteRequest opt) { .withStartTime(opt.dateTime()) .withPreferences(opt.preferences()) .withWheelchair(opt.wheelchair()) - .withParking(opt.journey().parking()) .withRental(opt.journey().rental()) .withFrom(opt.from()) .withTo(opt.to()); @@ -23,7 +22,6 @@ public static StreetSearchRequestBuilder mapToTransferRequest(RouteRequest opt) .withStartTime(Instant.ofEpochSecond(0)) .withPreferences(opt.preferences()) .withWheelchair(opt.wheelchair()) - .withParking(opt.journey().parking()) .withRental(opt.journey().rental()) .withMode(opt.journey().transfer().mode()); } diff --git a/src/test/java/org/opentripplanner/apis/gtfs/mapping/RouteRequestMapperTest.java b/src/test/java/org/opentripplanner/apis/gtfs/mapping/RouteRequestMapperTest.java index af6352839fb..7e6a7cbb36c 100644 --- a/src/test/java/org/opentripplanner/apis/gtfs/mapping/RouteRequestMapperTest.java +++ b/src/test/java/org/opentripplanner/apis/gtfs/mapping/RouteRequestMapperTest.java @@ -25,7 +25,6 @@ import org.opentripplanner.model.plan.PlanTestConstants; import org.opentripplanner.routing.api.request.RouteRequest; import org.opentripplanner.routing.api.request.preference.TimeSlopeSafetyTriangle; -import org.opentripplanner.routing.api.request.request.VehicleParkingRequest; import org.opentripplanner.routing.core.BicycleOptimizeType; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.routing.graphfinder.GraphFinder; @@ -57,45 +56,6 @@ class RouteRequestMapperTest implements PlanTestConstants { ); } - @Test - void parkingFilters() { - Map arguments = Map.of( - "parking", - Map.of( - "unpreferredCost", - 555, - "filters", - List.of( - Map.of( - "not", - List.of(Map.of("tags", List.of("wheelbender"))), - "select", - List.of(Map.of("tags", List.of("roof", "locker"))) - ) - ), - "preferred", - List.of(Map.of("select", List.of(Map.of("tags", List.of("a", "b"))))) - ) - ); - - var env = executionContext(arguments); - - var routeRequest = RouteRequestMapper.toRouteRequest(env, context); - - assertNotNull(routeRequest); - - final VehicleParkingRequest parking = routeRequest.journey().parking(); - assertEquals( - "VehicleParkingFilterRequest{not: [tags=[wheelbender]], select: [tags=[locker, roof]]}", - parking.filter().toString() - ); - assertEquals( - "VehicleParkingFilterRequest{select: [tags=[a, b]]}", - parking.preferred().toString() - ); - assertEquals(555, parking.unpreferredCost()); - } - static Stream banningCases = Stream.of( of(Map.of(), "[TransitFilterRequest{}]"), of( diff --git a/src/test/java/org/opentripplanner/routing/api/request/preference/ParkingPreferencesTest.java b/src/test/java/org/opentripplanner/routing/api/request/preference/ParkingPreferencesTest.java new file mode 100644 index 00000000000..3f5d2e9b962 --- /dev/null +++ b/src/test/java/org/opentripplanner/routing/api/request/preference/ParkingPreferencesTest.java @@ -0,0 +1,89 @@ +package org.opentripplanner.routing.api.request.preference; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.opentripplanner.routing.api.request.preference.ImmutablePreferencesAsserts.assertEqualsAndHashCode; + +import java.util.Set; +import org.junit.jupiter.api.Test; + +class ParkingPreferencesTest { + + private static final Set PREFERRED_TAGS = Set.of("foo"); + private static final Set NOT_PREFERRED_TAGS = Set.of("bar"); + private static final int UNPREFERRED_COST = 300; + private static final boolean REALTIME = false; + private static final Set REQUIRED_TAGS = Set.of("bar"); + private static final Set BANNED_TAGS = Set.of("not"); + + private final ParkingPreferences subject = createPreferences(); + + @Test + void preferred() { + assertEquals(tagsToString(PREFERRED_TAGS), subject.preferred().select().toString()); + assertEquals(tagsToString(NOT_PREFERRED_TAGS), subject.preferred().not().toString()); + } + + @Test + void filter() { + assertEquals(tagsToString(REQUIRED_TAGS), subject.filter().select().toString()); + assertEquals(tagsToString(BANNED_TAGS), subject.filter().not().toString()); + } + + @Test + void unpreferredCost() { + assertEquals(UNPREFERRED_COST, subject.unpreferredVehicleParkingTagCost().toSeconds()); + } + + @Test + void useAvailabilityInformation() { + assertEquals(REALTIME, subject.useAvailabilityInformation()); + } + + @Test + void testCopyOfEqualsAndHashCode() { + // Return same object if no value is set + assertSame(ParkingPreferences.DEFAULT, ParkingPreferences.of().build()); + + // Create a copy, make a change and set it back again to force creating a new object + var other = ParkingPreferences + .of() + .withPreferredVehicleParkingTags(Set.of()) + .withNotPreferredVehicleParkingTags(Set.of()) + .withUnpreferredVehicleParkingTagCost(0) + .withUseAvailabilityInformation(true) + .withRequiredVehicleParkingTags(Set.of()) + .withBannedVehicleParkingTags(Set.of()) + .build(); + var same = createPreferences(); + assertEqualsAndHashCode(subject, other, same); + } + + @Test + void testToString() { + assertEquals("ParkingPreferences{}", ParkingPreferences.DEFAULT.toString()); + assertEquals( + "ParkingPreferences{" + + "useAvailabilityInformation: false, " + + "filter: VehicleParkingFilterRequest{not: [tags=[not]], select: [tags=[bar]]}, " + + "preferred: VehicleParkingFilterRequest{not: [tags=[bar]], select: [tags=[foo]]}}", + subject.toString() + ); + } + + private static String tagsToString(Set tags) { + return "[tags=" + tags + "]"; + } + + private ParkingPreferences createPreferences() { + return ParkingPreferences + .of() + .withPreferredVehicleParkingTags(PREFERRED_TAGS) + .withNotPreferredVehicleParkingTags(NOT_PREFERRED_TAGS) + .withUnpreferredVehicleParkingTagCost(UNPREFERRED_COST) + .withUseAvailabilityInformation(REALTIME) + .withRequiredVehicleParkingTags(REQUIRED_TAGS) + .withBannedVehicleParkingTags(BANNED_TAGS) + .build(); + } +} diff --git a/src/test/java/org/opentripplanner/street/integration/ParkAndRideTest.java b/src/test/java/org/opentripplanner/street/integration/ParkAndRideTest.java index 10ab2e27232..75793e14861 100644 --- a/src/test/java/org/opentripplanner/street/integration/ParkAndRideTest.java +++ b/src/test/java/org/opentripplanner/street/integration/ParkAndRideTest.java @@ -11,8 +11,6 @@ import org.opentripplanner.routing.api.request.RouteRequest; import org.opentripplanner.routing.api.request.StreetMode; import org.opentripplanner.routing.api.request.request.StreetRequest; -import org.opentripplanner.routing.api.request.request.filter.VehicleParkingFilter.TagsFilter; -import org.opentripplanner.routing.api.request.request.filter.VehicleParkingFilterRequest; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.street.model.vertex.StreetVertex; import org.opentripplanner.street.model.vertex.Vertex; @@ -140,19 +138,26 @@ protected List runStreetSearchAndCreateDescriptor( var request = new RouteRequest(); request.withPreferences(preferences -> preferences - .withBike(b -> b.withParkCost(120).withParkTime(60)) - .withCar(c -> c.withParkCost(240).withParkTime(180)) + .withBike(b -> + b + .withParkCost(120) + .withParkTime(60) + .withParking(parking -> { + parking.withRequiredVehicleParkingTags(requiredTags); + parking.withBannedVehicleParkingTags(bannedTags); + }) + ) + .withCar(c -> + c + .withParkCost(240) + .withParkTime(180) + .withParking(parking -> { + parking.withRequiredVehicleParkingTags(requiredTags); + parking.withBannedVehicleParkingTags(bannedTags); + }) + ) ); request.setWheelchair(requireWheelChairAccessible); - request - .journey() - .parking() - .setFilter( - new VehicleParkingFilterRequest( - List.of(new TagsFilter(bannedTags)), - List.of(new TagsFilter(requiredTags)) - ) - ); request.setArriveBy(arriveBy); var tree = StreetSearchBuilder diff --git a/src/test/java/org/opentripplanner/street/model/edge/StreetVehicleParkingLinkTest.java b/src/test/java/org/opentripplanner/street/model/edge/StreetVehicleParkingLinkTest.java index ce94cc92a4c..13adb4d4c64 100644 --- a/src/test/java/org/opentripplanner/street/model/edge/StreetVehicleParkingLinkTest.java +++ b/src/test/java/org/opentripplanner/street/model/edge/StreetVehicleParkingLinkTest.java @@ -14,9 +14,6 @@ import org.opentripplanner.framework.geometry.WgsCoordinate; import org.opentripplanner.framework.i18n.NonLocalizedString; import org.opentripplanner.routing.api.request.StreetMode; -import org.opentripplanner.routing.api.request.request.VehicleParkingRequest; -import org.opentripplanner.routing.api.request.request.filter.VehicleParkingFilter; -import org.opentripplanner.routing.api.request.request.filter.VehicleParkingFilterRequest; import org.opentripplanner.routing.vehicle_parking.VehicleParking; import org.opentripplanner.routing.vehicle_parking.VehicleParkingEntrance; import org.opentripplanner.street.model.vertex.VehicleParkingEntranceVertex; @@ -59,17 +56,18 @@ void foo(Set parkingTags, Set not, Set select, boolean s .build(); var entranceVertex = new VehicleParkingEntranceVertex(entrance); - var parkingReq = new VehicleParkingRequest(); - - Set notFilter = Set.of(new VehicleParkingFilter.TagsFilter(not)); - Set selectFilter = Set.of(new VehicleParkingFilter.TagsFilter(select)); - - parkingReq.setFilter(new VehicleParkingFilterRequest(notFilter, selectFilter)); var req = StreetSearchRequest.of(); req.withMode(StreetMode.BIKE_TO_PARK); - req.withParking(parkingReq); - req.withPreferences(p -> p.withBike(bike -> bike.withParkCost(0))); + req.withPreferences(p -> + p.withBike(bike -> { + bike.withParkCost(0); + bike.withParking(parkingPreferences -> { + parkingPreferences.withRequiredVehicleParkingTags(select); + parkingPreferences.withBannedVehicleParkingTags(not); + }); + }) + ); var edge = StreetVehicleParkingLink.createStreetVehicleParkingLink( streetVertex, diff --git a/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingEdgeTest.java b/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingEdgeTest.java index a39fed89d6f..30aa0ee9228 100644 --- a/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingEdgeTest.java +++ b/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingEdgeTest.java @@ -8,7 +8,6 @@ import org.opentripplanner.framework.geometry.WgsCoordinate; import org.opentripplanner.framework.i18n.NonLocalizedString; import org.opentripplanner.routing.api.request.StreetMode; -import org.opentripplanner.routing.api.request.request.VehicleParkingRequest; import org.opentripplanner.routing.vehicle_parking.VehicleParking; import org.opentripplanner.routing.vehicle_parking.VehicleParkingSpaces; import org.opentripplanner.street.model.vertex.VehicleParkingEntranceVertex; @@ -156,9 +155,19 @@ private void initEdgeAndRequest( vehicleParkingEdge = VehicleParkingEdge.createVehicleParkingEdge(vertex); - var parking = new VehicleParkingRequest(); - parking.setUseAvailabilityInformation(realtime); - this.request = StreetSearchRequest.of().withMode(parkingMode).withParking(parking).build(); + this.request = + StreetSearchRequest + .of() + .withMode(parkingMode) + .withPreferences(preferences -> { + preferences.withBike(bike -> + bike.withParking(parking -> parking.withUseAvailabilityInformation(realtime)) + ); + preferences.withCar(car -> + car.withParking(parking -> parking.withUseAvailabilityInformation(realtime)) + ); + }) + .build(); } private VehicleParking createVehicleParking( diff --git a/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingPreferredTagsTest.java b/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingPreferredTagsTest.java index 0417aaf717c..3e46ecc5b3e 100644 --- a/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingPreferredTagsTest.java +++ b/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingPreferredTagsTest.java @@ -3,8 +3,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.params.provider.Arguments.of; -import java.util.Collection; -import java.util.List; import java.util.Set; import java.util.stream.Stream; import org.junit.jupiter.params.ParameterizedTest; @@ -13,9 +11,6 @@ import org.opentripplanner.framework.geometry.WgsCoordinate; import org.opentripplanner.framework.i18n.NonLocalizedString; import org.opentripplanner.routing.api.request.StreetMode; -import org.opentripplanner.routing.api.request.request.VehicleParkingRequest; -import org.opentripplanner.routing.api.request.request.filter.VehicleParkingFilter; -import org.opentripplanner.routing.api.request.request.filter.VehicleParkingFilterRequest; import org.opentripplanner.routing.vehicle_parking.VehicleParking; import org.opentripplanner.routing.vehicle_parking.VehicleParkingEntrance; import org.opentripplanner.routing.vehicle_parking.VehicleParkingSpaces; @@ -85,18 +80,18 @@ private void runTest( var fromV = new VehicleParkingEntranceVertex(entrance); var edge = VehicleParkingEdge.createVehicleParkingEdge(fromV); - var parkingReq = new VehicleParkingRequest(); - Collection select = List.of( - new VehicleParkingFilter.TagsFilter(preferredTags) - ); - parkingReq.setPreferred(new VehicleParkingFilterRequest(List.of(), select)); - parkingReq.setUnpreferredCost(EXTRA_COST); - var req = StreetSearchRequest.of(); req.withMode(StreetMode.BIKE_TO_PARK); - req.withParking(parkingReq); req.withArriveBy(arriveBy); - req.withPreferences(p -> p.withBike(bike -> bike.withParkCost(0))); + req.withPreferences(p -> + p.withBike(bike -> { + bike.withParkCost(0); + bike.withParking(parkingPreferences -> { + parkingPreferences.withUnpreferredVehicleParkingTagCost(EXTRA_COST); + parkingPreferences.withPreferredVehicleParkingTags(preferredTags); + }); + }) + ); var result = traverse(fromV, edge, req.build()); From a90722fa965189835fdaeff3b466ff120415f55a Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Mon, 20 Nov 2023 18:54:33 +0200 Subject: [PATCH 03/21] Move park time/cost to be under parking preferences --- docs/RouteRequest.md | 6 +-- docs/RouterConfiguration.md | 2 +- docs/examples/entur/router-config.json | 2 +- .../model/DefaultRouteRequestType.java | 4 +- .../common/RequestToPreferencesMapper.java | 16 ++++--- .../request/preference/BikePreferences.java | 45 ----------------- .../request/preference/CarPreferences.java | 36 -------------- .../preference/ParkingPreferences.java | 48 +++++++++++++++++-- .../routerequest/RouteRequestConfig.java | 40 +++++++++++----- .../street/model/edge/VehicleParkingEdge.java | 26 ++++++++-- .../preference/BikePreferencesTest.java | 16 ------- .../preference/CarPreferencesTest.java | 16 ------- .../preference/ParkingPreferencesTest.java | 25 +++++++++- .../street/integration/ParkAndRideTest.java | 26 +++++----- .../edge/StreetVehicleParkingLinkTest.java | 2 +- .../edge/VehicleParkingPreferredTagsTest.java | 2 +- .../standalone/config/router-config.json | 2 +- 17 files changed, 150 insertions(+), 164 deletions(-) diff --git a/docs/RouteRequest.md b/docs/RouteRequest.md index f814753df4a..d813e317359 100644 --- a/docs/RouteRequest.md +++ b/docs/RouteRequest.md @@ -19,7 +19,7 @@ and in the [transferRequests in build-config.json](BuildConfiguration.md#transfe | arriveBy | `boolean` | Whether the trip should depart or arrive at the specified date and time. | *Optional* | `false` | 2.0 | | [bikeBoardCost](#rd_bikeBoardCost) | `integer` | Prevents unnecessary transfers by adding a cost for boarding a vehicle. | *Optional* | `600` | 2.0 | | bikeParkCost | `integer` | Cost to park a bike. | *Optional* | `120` | 2.0 | -| bikeParkTime | `integer` | Time to park a bike. | *Optional* | `60` | 2.0 | +| bikeParkTime | `duration` | Time to park a bike. | *Optional* | `"PT1M"` | 2.0 | | bikeReluctance | `double` | A multiplier for how bad biking is, compared to being in transit for equal lengths of time. | *Optional* | `2.0` | 2.0 | | bikeSpeed | `double` | Max bike speed along streets, in meters per second | *Optional* | `5.0` | 2.0 | | bikeStairsReluctance | `double` | How bad is it to walk the bicycle up/down a flight of stairs compared to taking a detour. | *Optional* | `10.0` | 2.3 | @@ -35,7 +35,7 @@ and in the [transferRequests in build-config.json](BuildConfiguration.md#transfe | carDecelerationSpeed | `double` | The deceleration speed of an automobile, in meters per second per second. | *Optional* | `2.9` | 2.0 | | carDropoffTime | `integer` | Time to park a car in a park and ride, w/o taking into account driving and walking cost. | *Optional* | `120` | 2.0 | | carParkCost | `integer` | Cost of parking a car. | *Optional* | `120` | 2.1 | -| carParkTime | `integer` | Time to park a car | *Optional* | `60` | 2.1 | +| carParkTime | `duration` | Time to park a car | *Optional* | `"PT1M"` | 2.1 | | carPickupCost | `integer` | Add a cost for car pickup changes when a pickup or drop off takes place | *Optional* | `120` | 2.1 | | carPickupTime | `integer` | Add a time for car pickup changes when a pickup or drop off takes place | *Optional* | `60` | 2.1 | | carReluctance | `double` | A multiplier for how bad driving is, compared to being in transit for equal lengths of time. | *Optional* | `2.0` | 2.0 | @@ -912,7 +912,7 @@ include stairs as a last result. "dropOffTime" : 30, "dropOffCost" : 30 }, - "bikeParkTime" : 60, + "bikeParkTime" : "1m", "bikeParkCost" : 120, "carDropoffTime" : 120, "waitReluctance" : 1.0, diff --git a/docs/RouterConfiguration.md b/docs/RouterConfiguration.md index d0a58384819..6c634fe085d 100644 --- a/docs/RouterConfiguration.md +++ b/docs/RouterConfiguration.md @@ -473,7 +473,7 @@ Used to group requests when monitoring OTP. "dropOffTime" : 30, "dropOffCost" : 30 }, - "bikeParkTime" : 60, + "bikeParkTime" : "1m", "bikeParkCost" : 120, "carDropoffTime" : 120, "waitReluctance" : 1.0, diff --git a/docs/examples/entur/router-config.json b/docs/examples/entur/router-config.json index bc662453c91..0023dab130a 100644 --- a/docs/examples/entur/router-config.json +++ b/docs/examples/entur/router-config.json @@ -21,7 +21,7 @@ "dropOffTime": 30, "dropOffCost": 30 }, - "bikeParkTime": 60, + "bikeParkTime": "1m", "bikeParkCost": 120, "carDropoffTime": 120, "waitReluctance": 1.0, diff --git a/src/ext/java/org/opentripplanner/ext/transmodelapi/model/DefaultRouteRequestType.java b/src/ext/java/org/opentripplanner/ext/transmodelapi/model/DefaultRouteRequestType.java index 0d52fb280d9..56183378ea3 100644 --- a/src/ext/java/org/opentripplanner/ext/transmodelapi/model/DefaultRouteRequestType.java +++ b/src/ext/java/org/opentripplanner/ext/transmodelapi/model/DefaultRouteRequestType.java @@ -220,7 +220,7 @@ private GraphQLObjectType createGraphQLType() { .name("bikeParkTime") .description("Time to park a bike.") .type(Scalars.GraphQLInt) - .dataFetcher(env -> preferences.bike().parkTime()) + .dataFetcher(env -> (int) preferences.bike().parkingPreferences().parkTime().toSeconds()) .build() ) .field( @@ -229,7 +229,7 @@ private GraphQLObjectType createGraphQLType() { .name("bikeParkCost") .description("Cost to park a bike.") .type(Scalars.GraphQLInt) - .dataFetcher(env -> preferences.bike().parkCost()) + .dataFetcher(env -> preferences.bike().parkingPreferences().parkCost().toSeconds()) .build() ) .field( diff --git a/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java b/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java index cb52965a8d5..3b38f9014da 100644 --- a/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java +++ b/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java @@ -43,9 +43,11 @@ void map() { private void mapCar() { preferences.withCar(car -> { setIfNotNull(req.carReluctance, car::withReluctance); - setIfNotNull(req.carParkCost, car::withParkCost); - setIfNotNull(req.carParkTime, car::withParkTime); - car.withParking(parking -> mapParking(parking)); + car.withParking(parking -> { + mapParking(parking); + setIfNotNull(req.carParkCost, parking::withParkCost); + setIfNotNull(req.carParkTime, parking::withParkTime); + }); }); } @@ -65,8 +67,6 @@ private void mapBike() { setIfNotNull(req.bikeBoardCost, bike::withBoardCost); setIfNotNull(req.bikeWalkingSpeed, bike::withWalkingSpeed); setIfNotNull(req.bikeWalkingReluctance, bike::withWalkingReluctance); - setIfNotNull(req.bikeParkCost, bike::withParkCost); - setIfNotNull(req.bikeParkTime, bike::withParkTime); setIfNotNull(req.bikeSwitchTime, bike::withSwitchTime); setIfNotNull(req.bikeSwitchCost, bike::withSwitchCost); setIfNotNull(req.bikeOptimizeType, bike::withOptimizeType); @@ -79,7 +79,11 @@ private void mapBike() { }); } - bike.withParking(parking -> mapParking(parking)); + bike.withParking(parking -> { + mapParking(parking); + setIfNotNull(req.bikeParkCost, parking::withParkCost); + setIfNotNull(req.bikeParkTime, parking::withParkTime); + }); }); } diff --git a/src/main/java/org/opentripplanner/routing/api/request/preference/BikePreferences.java b/src/main/java/org/opentripplanner/routing/api/request/preference/BikePreferences.java index b470ec621c8..6ebb1beb2c6 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/preference/BikePreferences.java +++ b/src/main/java/org/opentripplanner/routing/api/request/preference/BikePreferences.java @@ -28,8 +28,6 @@ public final class BikePreferences implements Serializable { private final double walkingReluctance; private final int switchTime; private final Cost switchCost; - private final int parkTime; - private final Cost parkCost; private final ParkingPreferences parkingPreferences; private final double stairsReluctance; private final BicycleOptimizeType optimizeType; @@ -43,9 +41,6 @@ private BikePreferences() { this.walkingReluctance = 5.0; this.switchTime = 0; this.switchCost = Cost.ZERO; - this.parkTime = 60; - /** Cost of parking a bike. */ - this.parkCost = Cost.costOfSeconds(120); this.parkingPreferences = ParkingPreferences.DEFAULT; this.optimizeType = BicycleOptimizeType.SAFE; this.optimizeTriangle = TimeSlopeSafetyTriangle.DEFAULT; @@ -61,8 +56,6 @@ private BikePreferences(Builder builder) { this.walkingReluctance = Units.reluctance(builder.walkingReluctance); this.switchTime = Units.duration(builder.switchTime); this.switchCost = builder.switchCost; - this.parkTime = Units.duration(builder.parkTime); - this.parkCost = builder.parkCost; this.parkingPreferences = builder.parkingPreferences; this.optimizeType = Objects.requireNonNull(builder.optimizeType); this.optimizeTriangle = Objects.requireNonNull(builder.optimizeTriangle); @@ -127,16 +120,6 @@ public int switchCost() { return switchCost.toSeconds(); } - /** Time to park a bike */ - public int parkTime() { - return parkTime; - } - - /** Cost of parking a bike. */ - public int parkCost() { - return parkCost.toSeconds(); - } - /** Parking preferences that can be different per request */ public ParkingPreferences parkingPreferences() { return parkingPreferences; @@ -170,8 +153,6 @@ public boolean equals(Object o) { doubleEquals(that.walkingReluctance, walkingReluctance) && switchTime == that.switchTime && switchCost.equals(that.switchCost) && - parkTime == that.parkTime && - parkCost.equals(that.parkCost) && parkingPreferences.equals(that.parkingPreferences) && optimizeType == that.optimizeType && optimizeTriangle.equals(that.optimizeTriangle) && @@ -189,8 +170,6 @@ public int hashCode() { walkingReluctance, switchTime, switchCost, - parkTime, - parkCost, parkingPreferences, optimizeType, optimizeTriangle, @@ -209,8 +188,6 @@ public String toString() { .addNum("walkingReluctance", walkingReluctance, DEFAULT.walkingReluctance) .addDurationSec("switchTime", switchTime, DEFAULT.switchTime) .addObj("switchCost", switchCost, DEFAULT.switchCost) - .addDurationSec("parkTime", parkTime, DEFAULT.parkTime) - .addObj("parkCost", parkCost, DEFAULT.parkCost) .addObj("parkingPreferences", parkingPreferences, DEFAULT.parkingPreferences) .addEnum("optimizeType", optimizeType, DEFAULT.optimizeType) .addObj("optimizeTriangle", optimizeTriangle, DEFAULT.optimizeTriangle) @@ -228,8 +205,6 @@ public static class Builder { private double walkingReluctance; private int switchTime; private Cost switchCost; - private int parkTime; - private Cost parkCost; private ParkingPreferences parkingPreferences; private BicycleOptimizeType optimizeType; private TimeSlopeSafetyTriangle optimizeTriangle; @@ -245,8 +220,6 @@ public Builder(BikePreferences original) { this.walkingReluctance = original.walkingReluctance; this.switchTime = original.switchTime; this.switchCost = original.switchCost; - this.parkTime = original.parkTime; - this.parkCost = original.parkCost; this.parkingPreferences = original.parkingPreferences; this.optimizeType = original.optimizeType; this.optimizeTriangle = original.optimizeTriangle; @@ -320,24 +293,6 @@ public Builder withSwitchCost(int switchCost) { return this; } - public int parkTime() { - return parkTime; - } - - public Builder withParkTime(int parkTime) { - this.parkTime = parkTime; - return this; - } - - public Cost parkCost() { - return parkCost; - } - - public Builder withParkCost(int parkCost) { - this.parkCost = Cost.costOfSeconds(parkCost); - return this; - } - public Builder withParking(Consumer body) { var builder = ParkingPreferences.of(); body.accept(builder); diff --git a/src/main/java/org/opentripplanner/routing/api/request/preference/CarPreferences.java b/src/main/java/org/opentripplanner/routing/api/request/preference/CarPreferences.java index 5bb5bfcea9c..9c9945d9410 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/preference/CarPreferences.java +++ b/src/main/java/org/opentripplanner/routing/api/request/preference/CarPreferences.java @@ -21,8 +21,6 @@ public final class CarPreferences implements Serializable { private final double speed; private final double reluctance; - private final int parkTime; - private final Cost parkCost; private final ParkingPreferences parkingPreferences; private final int pickupTime; private final Cost pickupCost; @@ -34,8 +32,6 @@ public final class CarPreferences implements Serializable { private CarPreferences() { this.speed = 40.0; this.reluctance = 2.0; - this.parkTime = 60; - this.parkCost = Cost.costOfMinutes(2); this.parkingPreferences = ParkingPreferences.DEFAULT; this.pickupTime = 60; this.pickupCost = Cost.costOfMinutes(2); @@ -47,8 +43,6 @@ private CarPreferences() { private CarPreferences(Builder builder) { this.speed = Units.speed(builder.speed); this.reluctance = Units.reluctance(builder.reluctance); - this.parkTime = Units.duration(builder.parkTime); - this.parkCost = builder.parkCost; this.parkingPreferences = builder.parkingPreferences; this.pickupTime = Units.duration(builder.pickupTime); this.pickupCost = builder.pickupCost; @@ -78,16 +72,6 @@ public double reluctance() { return reluctance; } - /** Time to park a car. */ - public int parkTime() { - return parkTime; - } - - /** Cost of parking a car. */ - public int parkCost() { - return parkCost.toSeconds(); - } - /** Parking preferences that can be different per request */ public ParkingPreferences parkingPreferences() { return parkingPreferences; @@ -135,8 +119,6 @@ public boolean equals(Object o) { return ( DoubleUtils.doubleEquals(that.speed, speed) && DoubleUtils.doubleEquals(that.reluctance, reluctance) && - parkTime == that.parkTime && - parkCost.equals(that.parkCost) && parkingPreferences.equals(that.parkingPreferences) && pickupTime == that.pickupTime && pickupCost.equals(that.pickupCost) && @@ -151,8 +133,6 @@ public int hashCode() { return Objects.hash( speed, reluctance, - parkTime, - parkCost, parkingPreferences, pickupTime, pickupCost, @@ -168,8 +148,6 @@ public String toString() { .of(CarPreferences.class) .addNum("speed", speed, DEFAULT.speed) .addNum("reluctance", reluctance, DEFAULT.reluctance) - .addNum("parkTime", parkTime, DEFAULT.parkTime) - .addObj("parkCost", parkCost, DEFAULT.parkCost) .addObj("parkingPreferences", parkingPreferences, DEFAULT.parkingPreferences) .addNum("pickupTime", pickupTime, DEFAULT.pickupTime) .addObj("pickupCost", pickupCost, DEFAULT.pickupCost) @@ -185,8 +163,6 @@ public static class Builder { private final CarPreferences original; private double speed; private double reluctance; - private int parkTime; - private Cost parkCost; private ParkingPreferences parkingPreferences; private int pickupTime; private Cost pickupCost; @@ -198,8 +174,6 @@ public Builder(CarPreferences original) { this.original = original; this.speed = original.speed; this.reluctance = original.reluctance; - this.parkTime = original.parkTime; - this.parkCost = original.parkCost; this.parkingPreferences = original.parkingPreferences; this.pickupTime = original.pickupTime; this.pickupCost = original.pickupCost; @@ -222,16 +196,6 @@ public Builder withReluctance(double reluctance) { return this; } - public Builder withParkTime(int parkTime) { - this.parkTime = parkTime; - return this; - } - - public Builder withParkCost(int parkCost) { - this.parkCost = Cost.costOfSeconds(parkCost); - return this; - } - public Builder withParking(Consumer body) { var builder = ParkingPreferences.of(); body.accept(builder); diff --git a/src/main/java/org/opentripplanner/routing/api/request/preference/ParkingPreferences.java b/src/main/java/org/opentripplanner/routing/api/request/preference/ParkingPreferences.java index adeeb41ceed..eba10d97021 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/preference/ParkingPreferences.java +++ b/src/main/java/org/opentripplanner/routing/api/request/preference/ParkingPreferences.java @@ -1,6 +1,7 @@ package org.opentripplanner.routing.api.request.preference; import java.io.Serializable; +import java.time.Duration; import java.util.List; import java.util.Objects; import java.util.Set; @@ -22,13 +23,17 @@ public final class ParkingPreferences implements Serializable { private final boolean useAvailabilityInformation; private final VehicleParkingFilterRequest filter; private final VehicleParkingFilterRequest preferred; + private final Duration parkTime; + private final Cost parkCost; /** Create a new instance with default values. */ private ParkingPreferences() { - this.unpreferredVehicleParkingTagCost = Cost.costOfSeconds(5 * 60); + this.unpreferredVehicleParkingTagCost = Cost.costOfMinutes(5); this.useAvailabilityInformation = true; this.filter = VehicleParkingFilterRequest.empty(); this.preferred = VehicleParkingFilterRequest.empty(); + this.parkTime = Duration.ofMinutes(1); + this.parkCost = Cost.costOfMinutes(2); } private ParkingPreferences(Builder builder) { @@ -44,6 +49,8 @@ private ParkingPreferences(Builder builder) { builder.notPreferredVehicleParkingTags, builder.preferredVehicleParkingTags ); + this.parkTime = builder.parkTime; + this.parkCost = builder.parkCost; } public static ParkingPreferences.Builder of() { @@ -82,6 +89,16 @@ public VehicleParkingFilterRequest preferred() { return preferred; } + /** Time to park a vehicle */ + public Duration parkTime() { + return parkTime; + } + + /** Cost of parking a bike. */ + public Cost parkCost() { + return parkCost; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -91,7 +108,9 @@ public boolean equals(Object o) { Objects.equals(unpreferredVehicleParkingTagCost, that.unpreferredVehicleParkingTagCost) && useAvailabilityInformation == that.useAvailabilityInformation && Objects.equals(filter, that.filter) && - Objects.equals(preferred, that.preferred) + Objects.equals(preferred, that.preferred) && + Objects.equals(parkCost, that.parkCost) && + Objects.equals(parkTime, that.parkTime) ); } @@ -101,7 +120,9 @@ public int hashCode() { unpreferredVehicleParkingTagCost, useAvailabilityInformation, filter, - preferred + preferred, + parkCost, + parkTime ); } @@ -121,6 +142,8 @@ public String toString() { ) .addObj("filter", filter, DEFAULT.filter) .addObj("preferred", preferred, DEFAULT.preferred) + .addObj("parkCost", parkCost, DEFAULT.parkCost) + .addObj("parkTime", parkTime, DEFAULT.parkTime) .toString(); } @@ -133,6 +156,8 @@ public static class Builder { private List requiredVehicleParkingTags; private List preferredVehicleParkingTags; private List notPreferredVehicleParkingTags; + private Cost parkCost; + private Duration parkTime; private Builder(ParkingPreferences original) { this.original = original; @@ -142,6 +167,8 @@ private Builder(ParkingPreferences original) { this.requiredVehicleParkingTags = original.filter.select(); this.preferredVehicleParkingTags = original.preferred.select(); this.notPreferredVehicleParkingTags = original.preferred.not(); + this.parkCost = original.parkCost; + this.parkTime = original.parkTime; } public Builder withUnpreferredVehicleParkingTagCost(int cost) { @@ -178,6 +205,21 @@ public Builder withNotPreferredVehicleParkingTags(Set notPreferredVehicl return this; } + public Builder withParkCost(int cost) { + this.parkCost = Cost.costOfSeconds(cost); + return this; + } + + public Builder withParkTime(int seconds) { + this.parkTime = Duration.ofSeconds(seconds); + return this; + } + + public Builder withParkTime(Duration duration) { + this.parkTime = duration; + return this; + } + public ParkingPreferences build() { var newObj = new ParkingPreferences(this); return original.equals(newObj) ? original : newObj; diff --git a/src/main/java/org/opentripplanner/standalone/config/routerequest/RouteRequestConfig.java b/src/main/java/org/opentripplanner/standalone/config/routerequest/RouteRequestConfig.java index 4de3d281a03..e64a0a72d21 100644 --- a/src/main/java/org/opentripplanner/standalone/config/routerequest/RouteRequestConfig.java +++ b/src/main/java/org/opentripplanner/standalone/config/routerequest/RouteRequestConfig.java @@ -344,12 +344,6 @@ private static void mapBikePreferences(NodeAdapter c, BikePreferences.Builder bu ) .asInt(dft.boardCost()) ) - .withParkTime( - c.of("bikeParkTime").since(V2_0).summary("Time to park a bike.").asInt(dft.parkTime()) - ) - .withParkCost( - c.of("bikeParkCost").since(V2_0).summary("Cost to park a bike.").asInt(dft.parkCost()) - ) .withWalkingSpeed( c .of("bikeWalkingSpeed") @@ -450,6 +444,20 @@ private static void mapBikePreferences(NodeAdapter c, BikePreferences.Builder bu ) .asStringSet(List.of()) ) + .withParkTime( + c + .of("bikeParkTime") + .since(V2_0) + .summary("Time to park a bike.") + .asDuration(ParkingPreferences.DEFAULT.parkTime()) + ) + .withParkCost( + c + .of("bikeParkCost") + .since(V2_0) + .summary("Cost to park a bike.") + .asInt(ParkingPreferences.DEFAULT.parkCost().toSeconds()) + ) .withPreferredVehicleParkingTags( c .of("preferredVehicleParkingTags") @@ -676,12 +684,6 @@ private static void mapCarPreferences(NodeAdapter c, CarPreferences.Builder buil ) .asInt(dft.dropoffTime()) ) - .withParkCost( - c.of("carParkCost").since(V2_1).summary("Cost of parking a car.").asInt(dft.parkCost()) - ) - .withParkTime( - c.of("carParkTime").since(V2_1).summary("Time to park a car").asInt(dft.parkTime()) - ) .withPickupCost( c .of("carPickupCost") @@ -738,6 +740,20 @@ private static void mapCarPreferences(NodeAdapter c, CarPreferences.Builder buil ) .asStringSet(List.of()) ) + .withParkCost( + c + .of("carParkCost") + .since(V2_1) + .summary("Cost of parking a car.") + .asInt(ParkingPreferences.DEFAULT.parkCost().toSeconds()) + ) + .withParkTime( + c + .of("carParkTime") + .since(V2_1) + .summary("Time to park a car") + .asDuration(ParkingPreferences.DEFAULT.parkTime()) + ) .withPreferredVehicleParkingTags( c .of("preferredVehicleParkingTags") diff --git a/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java b/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java index a29bc7e94c3..595f7929061 100644 --- a/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java +++ b/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java @@ -92,10 +92,20 @@ protected State[] traverseUnPark(State s0) { if (streetMode.includesBiking()) { final BikePreferences bike = s0.getPreferences().bike(); - return traverseUnPark(s0, bike.parkCost(), bike.parkTime(), TraverseMode.BICYCLE); + return traverseUnPark( + s0, + bike.parkingPreferences().parkCost().toSeconds(), + (int) bike.parkingPreferences().parkTime().toSeconds(), + TraverseMode.BICYCLE + ); } else if (streetMode.includesDriving()) { final CarPreferences car = s0.getPreferences().car(); - return traverseUnPark(s0, car.parkCost(), car.parkTime(), TraverseMode.CAR); + return traverseUnPark( + s0, + car.parkingPreferences().parkCost().toSeconds(), + (int) car.parkingPreferences().parkTime().toSeconds(), + TraverseMode.CAR + ); } else { return State.empty(); } @@ -138,9 +148,17 @@ private State[] traversePark(State s0) { return State.empty(); } - return traversePark(s0, preferences.bike().parkCost(), preferences.bike().parkTime()); + return traversePark( + s0, + preferences.bike().parkingPreferences().parkCost().toSeconds(), + (int) preferences.bike().parkingPreferences().parkTime().toSeconds() + ); } else if (streetMode.includesDriving()) { - return traversePark(s0, preferences.car().parkCost(), preferences.car().parkTime()); + return traversePark( + s0, + preferences.car().parkingPreferences().parkCost().toSeconds(), + (int) preferences.car().parkingPreferences().parkTime().toSeconds() + ); } else { return State.empty(); } diff --git a/src/test/java/org/opentripplanner/routing/api/request/preference/BikePreferencesTest.java b/src/test/java/org/opentripplanner/routing/api/request/preference/BikePreferencesTest.java index c15512c82de..e8e3ff576a9 100644 --- a/src/test/java/org/opentripplanner/routing/api/request/preference/BikePreferencesTest.java +++ b/src/test/java/org/opentripplanner/routing/api/request/preference/BikePreferencesTest.java @@ -16,8 +16,6 @@ class BikePreferencesTest { public static final double WALKING_RELUCTANCE = 1.45; public static final int SWITCH_TIME = 200; public static final int SWITCH_COST = 450; - public static final int PARK_TIME = 330; - public static final int PARK_COST = 950; public static final TimeSlopeSafetyTriangle TRIANGLE = TimeSlopeSafetyTriangle .of() .withSlope(1) @@ -33,8 +31,6 @@ class BikePreferencesTest { .withWalkingReluctance(WALKING_RELUCTANCE) .withSwitchTime(SWITCH_TIME) .withSwitchCost(SWITCH_COST) - .withParkTime(PARK_TIME) - .withParkCost(PARK_COST) .withOptimizeType(OPTIMIZE_TYPE) .withOptimizeTriangle(it -> it.withSlope(1).build()) .build(); @@ -74,16 +70,6 @@ void switchCost() { assertEquals(SWITCH_COST, subject.switchCost()); } - @Test - void parkTime() { - assertEquals(PARK_TIME, subject.parkTime()); - } - - @Test - void parkCost() { - assertEquals(PARK_COST, subject.parkCost()); - } - @Test void optimizeType() { assertEquals(OPTIMIZE_TYPE, subject.optimizeType()); @@ -121,8 +107,6 @@ void testToString() { "walkingReluctance: 1.45, " + "switchTime: 3m20s, " + "switchCost: $450, " + - "parkTime: 5m30s, " + - "parkCost: $950, " + "optimizeType: TRIANGLE, " + "optimizeTriangle: TimeSlopeSafetyTriangle[time=0.0, slope=1.0, safety=0.0]" + "}", diff --git a/src/test/java/org/opentripplanner/routing/api/request/preference/CarPreferencesTest.java b/src/test/java/org/opentripplanner/routing/api/request/preference/CarPreferencesTest.java index d94f21d567b..7bc0a1620ab 100644 --- a/src/test/java/org/opentripplanner/routing/api/request/preference/CarPreferencesTest.java +++ b/src/test/java/org/opentripplanner/routing/api/request/preference/CarPreferencesTest.java @@ -12,8 +12,6 @@ class CarPreferencesTest { private static final double EXPECTED_SPEED = 20.0; private static final double RELUCTANCE = 5.111; private static final double EXPECTED_RELUCTANCE = 5.1; - private static final int PARK_TIME = 300; - private static final int PARK_COST = 250; private static final int PICKUP_TIME = 600; private static final int PICKUP_COST = 500; private static final double ACCELERATION_SPEED = 3.1; @@ -24,8 +22,6 @@ class CarPreferencesTest { .of() .withSpeed(SPEED) .withReluctance(RELUCTANCE) - .withParkTime(PARK_TIME) - .withParkCost(PARK_COST) .withPickupTime(PICKUP_TIME) .withPickupCost(PICKUP_COST) .withDropoffTime(DROPOFF_TIME) @@ -43,16 +39,6 @@ void reluctance() { assertEquals(EXPECTED_RELUCTANCE, subject.reluctance()); } - @Test - void parkTime() { - assertEquals(PARK_TIME, subject.parkTime()); - } - - @Test - void parkCost() { - assertEquals(PARK_COST, subject.parkCost()); - } - @Test void pickupTime() { assertEquals(PICKUP_TIME, subject.pickupTime()); @@ -97,8 +83,6 @@ void testToString() { "CarPreferences{" + "speed: 20.0, " + "reluctance: 5.1, " + - "parkTime: 300, " + - "parkCost: $250, " + "pickupTime: 600, " + "pickupCost: $500, " + "dropoffTime: 450, " + diff --git a/src/test/java/org/opentripplanner/routing/api/request/preference/ParkingPreferencesTest.java b/src/test/java/org/opentripplanner/routing/api/request/preference/ParkingPreferencesTest.java index 3f5d2e9b962..0e900dd5f34 100644 --- a/src/test/java/org/opentripplanner/routing/api/request/preference/ParkingPreferencesTest.java +++ b/src/test/java/org/opentripplanner/routing/api/request/preference/ParkingPreferencesTest.java @@ -4,17 +4,21 @@ import static org.junit.jupiter.api.Assertions.assertSame; import static org.opentripplanner.routing.api.request.preference.ImmutablePreferencesAsserts.assertEqualsAndHashCode; +import java.time.Duration; import java.util.Set; import org.junit.jupiter.api.Test; +import org.opentripplanner.framework.model.Cost; class ParkingPreferencesTest { private static final Set PREFERRED_TAGS = Set.of("foo"); private static final Set NOT_PREFERRED_TAGS = Set.of("bar"); - private static final int UNPREFERRED_COST = 300; + private static final int UNPREFERRED_COST = 360; private static final boolean REALTIME = false; private static final Set REQUIRED_TAGS = Set.of("bar"); private static final Set BANNED_TAGS = Set.of("not"); + private static final Cost PARKING_COST = Cost.costOfMinutes(4); + private static final Duration PARKING_TIME = Duration.ofMinutes(2); private final ParkingPreferences subject = createPreferences(); @@ -40,6 +44,16 @@ void useAvailabilityInformation() { assertEquals(REALTIME, subject.useAvailabilityInformation()); } + @Test + void parkCost() { + assertEquals(PARKING_COST, subject.parkCost()); + } + + @Test + void parkTime() { + assertEquals(PARKING_TIME, subject.parkTime()); + } + @Test void testCopyOfEqualsAndHashCode() { // Return same object if no value is set @@ -54,6 +68,8 @@ void testCopyOfEqualsAndHashCode() { .withUseAvailabilityInformation(true) .withRequiredVehicleParkingTags(Set.of()) .withBannedVehicleParkingTags(Set.of()) + .withParkCost(0) + .withParkTime(0) .build(); var same = createPreferences(); assertEqualsAndHashCode(subject, other, same); @@ -64,9 +80,12 @@ void testToString() { assertEquals("ParkingPreferences{}", ParkingPreferences.DEFAULT.toString()); assertEquals( "ParkingPreferences{" + + "unpreferredVehicleParkingTagCost: $360, " + "useAvailabilityInformation: false, " + "filter: VehicleParkingFilterRequest{not: [tags=[not]], select: [tags=[bar]]}, " + - "preferred: VehicleParkingFilterRequest{not: [tags=[bar]], select: [tags=[foo]]}}", + "preferred: VehicleParkingFilterRequest{not: [tags=[bar]], select: [tags=[foo]]}, " + + "parkCost: $240, " + + "parkTime: PT2M}", subject.toString() ); } @@ -84,6 +103,8 @@ private ParkingPreferences createPreferences() { .withUseAvailabilityInformation(REALTIME) .withRequiredVehicleParkingTags(REQUIRED_TAGS) .withBannedVehicleParkingTags(BANNED_TAGS) + .withParkCost(PARKING_COST.toSeconds()) + .withParkTime(PARKING_TIME) .build(); } } diff --git a/src/test/java/org/opentripplanner/street/integration/ParkAndRideTest.java b/src/test/java/org/opentripplanner/street/integration/ParkAndRideTest.java index 75793e14861..6dd53ae0c6e 100644 --- a/src/test/java/org/opentripplanner/street/integration/ParkAndRideTest.java +++ b/src/test/java/org/opentripplanner/street/integration/ParkAndRideTest.java @@ -139,22 +139,20 @@ protected List runStreetSearchAndCreateDescriptor( request.withPreferences(preferences -> preferences .withBike(b -> - b - .withParkCost(120) - .withParkTime(60) - .withParking(parking -> { - parking.withRequiredVehicleParkingTags(requiredTags); - parking.withBannedVehicleParkingTags(bannedTags); - }) + b.withParking(parking -> { + parking.withRequiredVehicleParkingTags(requiredTags); + parking.withBannedVehicleParkingTags(bannedTags); + parking.withParkCost(120); + parking.withParkTime(60); + }) ) .withCar(c -> - c - .withParkCost(240) - .withParkTime(180) - .withParking(parking -> { - parking.withRequiredVehicleParkingTags(requiredTags); - parking.withBannedVehicleParkingTags(bannedTags); - }) + c.withParking(parking -> { + parking.withRequiredVehicleParkingTags(requiredTags); + parking.withBannedVehicleParkingTags(bannedTags); + parking.withParkCost(240); + parking.withParkTime(180); + }) ) ); request.setWheelchair(requireWheelChairAccessible); diff --git a/src/test/java/org/opentripplanner/street/model/edge/StreetVehicleParkingLinkTest.java b/src/test/java/org/opentripplanner/street/model/edge/StreetVehicleParkingLinkTest.java index 13adb4d4c64..a9932381b40 100644 --- a/src/test/java/org/opentripplanner/street/model/edge/StreetVehicleParkingLinkTest.java +++ b/src/test/java/org/opentripplanner/street/model/edge/StreetVehicleParkingLinkTest.java @@ -61,10 +61,10 @@ void foo(Set parkingTags, Set not, Set select, boolean s req.withMode(StreetMode.BIKE_TO_PARK); req.withPreferences(p -> p.withBike(bike -> { - bike.withParkCost(0); bike.withParking(parkingPreferences -> { parkingPreferences.withRequiredVehicleParkingTags(select); parkingPreferences.withBannedVehicleParkingTags(not); + parkingPreferences.withParkCost(0); }); }) ); diff --git a/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingPreferredTagsTest.java b/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingPreferredTagsTest.java index 3e46ecc5b3e..41ecbe162bb 100644 --- a/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingPreferredTagsTest.java +++ b/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingPreferredTagsTest.java @@ -85,10 +85,10 @@ private void runTest( req.withArriveBy(arriveBy); req.withPreferences(p -> p.withBike(bike -> { - bike.withParkCost(0); bike.withParking(parkingPreferences -> { parkingPreferences.withUnpreferredVehicleParkingTagCost(EXTRA_COST); parkingPreferences.withPreferredVehicleParkingTags(preferredTags); + parkingPreferences.withParkCost(0); }); }) ); diff --git a/src/test/resources/standalone/config/router-config.json b/src/test/resources/standalone/config/router-config.json index ebc2e4f7c02..69f859d784d 100644 --- a/src/test/resources/standalone/config/router-config.json +++ b/src/test/resources/standalone/config/router-config.json @@ -34,7 +34,7 @@ "dropOffTime": 30, "dropOffCost": 30 }, - "bikeParkTime": 60, + "bikeParkTime": "1m", "bikeParkCost": 120, "carDropoffTime": 120, "waitReluctance": 1.0, From a4a8819a8addca7345562a5cf98690945da5b837 Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Tue, 21 Nov 2023 10:20:40 +0200 Subject: [PATCH 04/21] Renaming to better follow conventions --- .../model/DefaultRouteRequestType.java | 4 +-- .../common/RequestToPreferencesMapper.java | 4 +-- .../apis/gtfs/mapping/RouteRequestMapper.java | 4 +-- .../org/opentripplanner/model/plan/Place.java | 4 +-- .../request/preference/BikePreferences.java | 26 +++++++++---------- .../request/preference/CarPreferences.java | 26 +++++++++---------- ...es.java => VehicleParkingPreferences.java} | 22 ++++++++-------- .../routerequest/RouteRequestConfig.java | 14 +++++----- .../model/edge/StreetVehicleParkingLink.java | 10 +++---- .../street/model/edge/VehicleParkingEdge.java | 26 +++++++++---------- ...ava => VehicleParkingPreferencesTest.java} | 14 +++++----- 11 files changed, 77 insertions(+), 77 deletions(-) rename src/main/java/org/opentripplanner/routing/api/request/preference/{ParkingPreferences.java => VehicleParkingPreferences.java} (91%) rename src/test/java/org/opentripplanner/routing/api/request/preference/{ParkingPreferencesTest.java => VehicleParkingPreferencesTest.java} (88%) diff --git a/src/ext/java/org/opentripplanner/ext/transmodelapi/model/DefaultRouteRequestType.java b/src/ext/java/org/opentripplanner/ext/transmodelapi/model/DefaultRouteRequestType.java index 56183378ea3..68aba859b09 100644 --- a/src/ext/java/org/opentripplanner/ext/transmodelapi/model/DefaultRouteRequestType.java +++ b/src/ext/java/org/opentripplanner/ext/transmodelapi/model/DefaultRouteRequestType.java @@ -220,7 +220,7 @@ private GraphQLObjectType createGraphQLType() { .name("bikeParkTime") .description("Time to park a bike.") .type(Scalars.GraphQLInt) - .dataFetcher(env -> (int) preferences.bike().parkingPreferences().parkTime().toSeconds()) + .dataFetcher(env -> (int) preferences.bike().parking().parkTime().toSeconds()) .build() ) .field( @@ -229,7 +229,7 @@ private GraphQLObjectType createGraphQLType() { .name("bikeParkCost") .description("Cost to park a bike.") .type(Scalars.GraphQLInt) - .dataFetcher(env -> preferences.bike().parkingPreferences().parkCost().toSeconds()) + .dataFetcher(env -> preferences.bike().parking().parkCost().toSeconds()) .build() ) .field( diff --git a/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java b/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java index 3b38f9014da..3e6cdad050e 100644 --- a/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java +++ b/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java @@ -6,7 +6,7 @@ import org.opentripplanner.routing.algorithm.filterchain.api.TransitGeneralizedCostFilterParams; import org.opentripplanner.routing.api.request.framework.CostLinearFunction; import org.opentripplanner.routing.api.request.preference.ItineraryFilterPreferences; -import org.opentripplanner.routing.api.request.preference.ParkingPreferences; +import org.opentripplanner.routing.api.request.preference.VehicleParkingPreferences; import org.opentripplanner.routing.api.request.preference.RoutingPreferences; import org.opentripplanner.routing.core.BicycleOptimizeType; @@ -167,7 +167,7 @@ private TransitGeneralizedCostFilterParams mapTransitGeneralizedCostFilterParams return new TransitGeneralizedCostFilterParams(costLimitFunction, intervalRelaxFactor); } - private void mapParking(ParkingPreferences.Builder builder) { + private void mapParking(VehicleParkingPreferences.Builder builder) { setIfNotNull( req.useVehicleParkingAvailabilityInformation, builder::withUseAvailabilityInformation diff --git a/src/main/java/org/opentripplanner/apis/gtfs/mapping/RouteRequestMapper.java b/src/main/java/org/opentripplanner/apis/gtfs/mapping/RouteRequestMapper.java index f9a0bcb703e..ab9e8bce823 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/mapping/RouteRequestMapper.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/mapping/RouteRequestMapper.java @@ -21,7 +21,7 @@ import org.opentripplanner.routing.api.request.RouteRequest; import org.opentripplanner.routing.api.request.framework.CostLinearFunction; import org.opentripplanner.routing.api.request.preference.ItineraryFilterDebugProfile; -import org.opentripplanner.routing.api.request.preference.ParkingPreferences; +import org.opentripplanner.routing.api.request.preference.VehicleParkingPreferences; import org.opentripplanner.routing.api.request.request.filter.SelectRequest; import org.opentripplanner.routing.api.request.request.filter.TransitFilterRequest; import org.opentripplanner.routing.core.BicycleOptimizeType; @@ -303,7 +303,7 @@ private static GenericLocation toGenericLocation(Map m) { private static void setParkingPreferences( CallerWithEnvironment callWith, - ParkingPreferences.Builder parking + VehicleParkingPreferences.Builder parking ) { callWith.argument("parking.unpreferredCost", parking::withUnpreferredVehicleParkingTagCost); diff --git a/src/main/java/org/opentripplanner/model/plan/Place.java b/src/main/java/org/opentripplanner/model/plan/Place.java index 2a1b10b0250..3175c2ec81b 100644 --- a/src/main/java/org/opentripplanner/model/plan/Place.java +++ b/src/main/java/org/opentripplanner/model/plan/Place.java @@ -136,8 +136,8 @@ public static Place forVehicleParkingEntrance(VehicleParkingEntranceVertex verte } var parkingPreferences = traverseMode == TraverseMode.CAR - ? request.preferences().car().parkingPreferences() - : request.preferences().bike().parkingPreferences(); + ? request.preferences().car().parking() + : request.preferences().bike().parking(); boolean realTime = parkingPreferences.useAvailabilityInformation() && diff --git a/src/main/java/org/opentripplanner/routing/api/request/preference/BikePreferences.java b/src/main/java/org/opentripplanner/routing/api/request/preference/BikePreferences.java index 6ebb1beb2c6..ab4e03e2cad 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/preference/BikePreferences.java +++ b/src/main/java/org/opentripplanner/routing/api/request/preference/BikePreferences.java @@ -28,7 +28,7 @@ public final class BikePreferences implements Serializable { private final double walkingReluctance; private final int switchTime; private final Cost switchCost; - private final ParkingPreferences parkingPreferences; + private final VehicleParkingPreferences parking; private final double stairsReluctance; private final BicycleOptimizeType optimizeType; private final TimeSlopeSafetyTriangle optimizeTriangle; @@ -41,7 +41,7 @@ private BikePreferences() { this.walkingReluctance = 5.0; this.switchTime = 0; this.switchCost = Cost.ZERO; - this.parkingPreferences = ParkingPreferences.DEFAULT; + this.parking = VehicleParkingPreferences.DEFAULT; this.optimizeType = BicycleOptimizeType.SAFE; this.optimizeTriangle = TimeSlopeSafetyTriangle.DEFAULT; // very high reluctance to carry the bike up/down a flight of stairs @@ -56,7 +56,7 @@ private BikePreferences(Builder builder) { this.walkingReluctance = Units.reluctance(builder.walkingReluctance); this.switchTime = Units.duration(builder.switchTime); this.switchCost = builder.switchCost; - this.parkingPreferences = builder.parkingPreferences; + this.parking = builder.parking; this.optimizeType = Objects.requireNonNull(builder.optimizeType); this.optimizeTriangle = Objects.requireNonNull(builder.optimizeTriangle); this.stairsReluctance = Units.reluctance(builder.stairsReluctance); @@ -121,8 +121,8 @@ public int switchCost() { } /** Parking preferences that can be different per request */ - public ParkingPreferences parkingPreferences() { - return parkingPreferences; + public VehicleParkingPreferences parking() { + return parking; } /** @@ -153,7 +153,7 @@ public boolean equals(Object o) { doubleEquals(that.walkingReluctance, walkingReluctance) && switchTime == that.switchTime && switchCost.equals(that.switchCost) && - parkingPreferences.equals(that.parkingPreferences) && + parking.equals(that.parking) && optimizeType == that.optimizeType && optimizeTriangle.equals(that.optimizeTriangle) && doubleEquals(stairsReluctance, that.stairsReluctance) @@ -170,7 +170,7 @@ public int hashCode() { walkingReluctance, switchTime, switchCost, - parkingPreferences, + parking, optimizeType, optimizeTriangle, stairsReluctance @@ -188,7 +188,7 @@ public String toString() { .addNum("walkingReluctance", walkingReluctance, DEFAULT.walkingReluctance) .addDurationSec("switchTime", switchTime, DEFAULT.switchTime) .addObj("switchCost", switchCost, DEFAULT.switchCost) - .addObj("parkingPreferences", parkingPreferences, DEFAULT.parkingPreferences) + .addObj("parking", parking, DEFAULT.parking) .addEnum("optimizeType", optimizeType, DEFAULT.optimizeType) .addObj("optimizeTriangle", optimizeTriangle, DEFAULT.optimizeTriangle) .toString(); @@ -205,7 +205,7 @@ public static class Builder { private double walkingReluctance; private int switchTime; private Cost switchCost; - private ParkingPreferences parkingPreferences; + private VehicleParkingPreferences parking; private BicycleOptimizeType optimizeType; private TimeSlopeSafetyTriangle optimizeTriangle; @@ -220,7 +220,7 @@ public Builder(BikePreferences original) { this.walkingReluctance = original.walkingReluctance; this.switchTime = original.switchTime; this.switchCost = original.switchCost; - this.parkingPreferences = original.parkingPreferences; + this.parking = original.parking; this.optimizeType = original.optimizeType; this.optimizeTriangle = original.optimizeTriangle; this.stairsReluctance = original.stairsReluctance; @@ -293,10 +293,10 @@ public Builder withSwitchCost(int switchCost) { return this; } - public Builder withParking(Consumer body) { - var builder = ParkingPreferences.of(); + public Builder withParking(Consumer body) { + var builder = VehicleParkingPreferences.of(); body.accept(builder); - this.parkingPreferences = builder.build(); + this.parking = builder.build(); return this; } diff --git a/src/main/java/org/opentripplanner/routing/api/request/preference/CarPreferences.java b/src/main/java/org/opentripplanner/routing/api/request/preference/CarPreferences.java index 9c9945d9410..11ccf26c4b6 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/preference/CarPreferences.java +++ b/src/main/java/org/opentripplanner/routing/api/request/preference/CarPreferences.java @@ -21,7 +21,7 @@ public final class CarPreferences implements Serializable { private final double speed; private final double reluctance; - private final ParkingPreferences parkingPreferences; + private final VehicleParkingPreferences parking; private final int pickupTime; private final Cost pickupCost; private final int dropoffTime; @@ -32,7 +32,7 @@ public final class CarPreferences implements Serializable { private CarPreferences() { this.speed = 40.0; this.reluctance = 2.0; - this.parkingPreferences = ParkingPreferences.DEFAULT; + this.parking = VehicleParkingPreferences.DEFAULT; this.pickupTime = 60; this.pickupCost = Cost.costOfMinutes(2); this.dropoffTime = 120; @@ -43,7 +43,7 @@ private CarPreferences() { private CarPreferences(Builder builder) { this.speed = Units.speed(builder.speed); this.reluctance = Units.reluctance(builder.reluctance); - this.parkingPreferences = builder.parkingPreferences; + this.parking = builder.parking; this.pickupTime = Units.duration(builder.pickupTime); this.pickupCost = builder.pickupCost; this.dropoffTime = Units.duration(builder.dropoffTime); @@ -73,8 +73,8 @@ public double reluctance() { } /** Parking preferences that can be different per request */ - public ParkingPreferences parkingPreferences() { - return parkingPreferences; + public VehicleParkingPreferences parking() { + return parking; } /** Time of getting in/out of a carPickup (taxi) */ @@ -119,7 +119,7 @@ public boolean equals(Object o) { return ( DoubleUtils.doubleEquals(that.speed, speed) && DoubleUtils.doubleEquals(that.reluctance, reluctance) && - parkingPreferences.equals(that.parkingPreferences) && + parking.equals(that.parking) && pickupTime == that.pickupTime && pickupCost.equals(that.pickupCost) && dropoffTime == that.dropoffTime && @@ -133,7 +133,7 @@ public int hashCode() { return Objects.hash( speed, reluctance, - parkingPreferences, + parking, pickupTime, pickupCost, dropoffTime, @@ -148,7 +148,7 @@ public String toString() { .of(CarPreferences.class) .addNum("speed", speed, DEFAULT.speed) .addNum("reluctance", reluctance, DEFAULT.reluctance) - .addObj("parkingPreferences", parkingPreferences, DEFAULT.parkingPreferences) + .addObj("parking", parking, DEFAULT.parking) .addNum("pickupTime", pickupTime, DEFAULT.pickupTime) .addObj("pickupCost", pickupCost, DEFAULT.pickupCost) .addNum("dropoffTime", dropoffTime, DEFAULT.dropoffTime) @@ -163,7 +163,7 @@ public static class Builder { private final CarPreferences original; private double speed; private double reluctance; - private ParkingPreferences parkingPreferences; + private VehicleParkingPreferences parking; private int pickupTime; private Cost pickupCost; private int dropoffTime; @@ -174,7 +174,7 @@ public Builder(CarPreferences original) { this.original = original; this.speed = original.speed; this.reluctance = original.reluctance; - this.parkingPreferences = original.parkingPreferences; + this.parking = original.parking; this.pickupTime = original.pickupTime; this.pickupCost = original.pickupCost; this.dropoffTime = original.dropoffTime; @@ -196,10 +196,10 @@ public Builder withReluctance(double reluctance) { return this; } - public Builder withParking(Consumer body) { - var builder = ParkingPreferences.of(); + public Builder withParking(Consumer body) { + var builder = VehicleParkingPreferences.of(); body.accept(builder); - this.parkingPreferences = builder.build(); + this.parking = builder.build(); return this; } diff --git a/src/main/java/org/opentripplanner/routing/api/request/preference/ParkingPreferences.java b/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java similarity index 91% rename from src/main/java/org/opentripplanner/routing/api/request/preference/ParkingPreferences.java rename to src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java index eba10d97021..bcfa8805547 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/preference/ParkingPreferences.java +++ b/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java @@ -16,9 +16,9 @@ *

* THIS CLASS IS IMMUTABLE AND THREAD-SAFE. */ -public final class ParkingPreferences implements Serializable { +public final class VehicleParkingPreferences implements Serializable { - public static final ParkingPreferences DEFAULT = new ParkingPreferences(); + public static final VehicleParkingPreferences DEFAULT = new VehicleParkingPreferences(); private final Cost unpreferredVehicleParkingTagCost; private final boolean useAvailabilityInformation; private final VehicleParkingFilterRequest filter; @@ -27,7 +27,7 @@ public final class ParkingPreferences implements Serializable { private final Cost parkCost; /** Create a new instance with default values. */ - private ParkingPreferences() { + private VehicleParkingPreferences() { this.unpreferredVehicleParkingTagCost = Cost.costOfMinutes(5); this.useAvailabilityInformation = true; this.filter = VehicleParkingFilterRequest.empty(); @@ -36,7 +36,7 @@ private ParkingPreferences() { this.parkCost = Cost.costOfMinutes(2); } - private ParkingPreferences(Builder builder) { + private VehicleParkingPreferences(Builder builder) { this.unpreferredVehicleParkingTagCost = builder.unpreferredVehicleParkingTagCost; this.useAvailabilityInformation = builder.useAvailabilityInformation; this.filter = @@ -53,7 +53,7 @@ private ParkingPreferences(Builder builder) { this.parkCost = builder.parkCost; } - public static ParkingPreferences.Builder of() { + public static VehicleParkingPreferences.Builder of() { return new Builder(DEFAULT); } @@ -103,7 +103,7 @@ public Cost parkCost() { public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - ParkingPreferences that = (ParkingPreferences) o; + VehicleParkingPreferences that = (VehicleParkingPreferences) o; return ( Objects.equals(unpreferredVehicleParkingTagCost, that.unpreferredVehicleParkingTagCost) && useAvailabilityInformation == that.useAvailabilityInformation && @@ -129,7 +129,7 @@ public int hashCode() { @Override public String toString() { return ToStringBuilder - .of(ParkingPreferences.class) + .of(VehicleParkingPreferences.class) .addObj( "unpreferredVehicleParkingTagCost", unpreferredVehicleParkingTagCost, @@ -149,7 +149,7 @@ public String toString() { public static class Builder { - private final ParkingPreferences original; + private final VehicleParkingPreferences original; private Cost unpreferredVehicleParkingTagCost; private boolean useAvailabilityInformation; private List bannedVehicleParkingTags; @@ -159,7 +159,7 @@ public static class Builder { private Cost parkCost; private Duration parkTime; - private Builder(ParkingPreferences original) { + private Builder(VehicleParkingPreferences original) { this.original = original; this.unpreferredVehicleParkingTagCost = original.unpreferredVehicleParkingTagCost; this.useAvailabilityInformation = original.useAvailabilityInformation; @@ -220,8 +220,8 @@ public Builder withParkTime(Duration duration) { return this; } - public ParkingPreferences build() { - var newObj = new ParkingPreferences(this); + public VehicleParkingPreferences build() { + var newObj = new VehicleParkingPreferences(this); return original.equals(newObj) ? original : newObj; } } diff --git a/src/main/java/org/opentripplanner/standalone/config/routerequest/RouteRequestConfig.java b/src/main/java/org/opentripplanner/standalone/config/routerequest/RouteRequestConfig.java index e64a0a72d21..f814785e362 100644 --- a/src/main/java/org/opentripplanner/standalone/config/routerequest/RouteRequestConfig.java +++ b/src/main/java/org/opentripplanner/standalone/config/routerequest/RouteRequestConfig.java @@ -19,7 +19,7 @@ import org.opentripplanner.routing.api.request.StreetMode; import org.opentripplanner.routing.api.request.preference.BikePreferences; import org.opentripplanner.routing.api.request.preference.CarPreferences; -import org.opentripplanner.routing.api.request.preference.ParkingPreferences; +import org.opentripplanner.routing.api.request.preference.VehicleParkingPreferences; import org.opentripplanner.routing.api.request.preference.RoutingPreferences; import org.opentripplanner.routing.api.request.preference.StreetPreferences; import org.opentripplanner.routing.api.request.preference.SystemPreferences; @@ -424,7 +424,7 @@ private static void mapBikePreferences(NodeAdapter c, BikePreferences.Builder bu .since(V2_3) .summary("What cost to add if a parking facility doesn't contain a preferred tag.") .description("See `preferredVehicleParkingTags`.") - .asInt(ParkingPreferences.DEFAULT.unpreferredVehicleParkingTagCost().toSeconds()) + .asInt(VehicleParkingPreferences.DEFAULT.unpreferredVehicleParkingTagCost().toSeconds()) ) .withBannedVehicleParkingTags( c @@ -449,14 +449,14 @@ private static void mapBikePreferences(NodeAdapter c, BikePreferences.Builder bu .of("bikeParkTime") .since(V2_0) .summary("Time to park a bike.") - .asDuration(ParkingPreferences.DEFAULT.parkTime()) + .asDuration(VehicleParkingPreferences.DEFAULT.parkTime()) ) .withParkCost( c .of("bikeParkCost") .since(V2_0) .summary("Cost to park a bike.") - .asInt(ParkingPreferences.DEFAULT.parkCost().toSeconds()) + .asInt(VehicleParkingPreferences.DEFAULT.parkCost().toSeconds()) ) .withPreferredVehicleParkingTags( c @@ -720,7 +720,7 @@ private static void mapCarPreferences(NodeAdapter c, CarPreferences.Builder buil .since(V2_3) .summary("What cost to add if a parking facility doesn't contain a preferred tag.") .description("See `preferredVehicleParkingTags`.") - .asInt(ParkingPreferences.DEFAULT.unpreferredVehicleParkingTagCost().toSeconds()) + .asInt(VehicleParkingPreferences.DEFAULT.unpreferredVehicleParkingTagCost().toSeconds()) ) .withBannedVehicleParkingTags( c @@ -745,14 +745,14 @@ private static void mapCarPreferences(NodeAdapter c, CarPreferences.Builder buil .of("carParkCost") .since(V2_1) .summary("Cost of parking a car.") - .asInt(ParkingPreferences.DEFAULT.parkCost().toSeconds()) + .asInt(VehicleParkingPreferences.DEFAULT.parkCost().toSeconds()) ) .withParkTime( c .of("carParkTime") .since(V2_1) .summary("Time to park a car") - .asDuration(ParkingPreferences.DEFAULT.parkTime()) + .asDuration(VehicleParkingPreferences.DEFAULT.parkTime()) ) .withPreferredVehicleParkingTags( c diff --git a/src/main/java/org/opentripplanner/street/model/edge/StreetVehicleParkingLink.java b/src/main/java/org/opentripplanner/street/model/edge/StreetVehicleParkingLink.java index 62e873e6932..e7fbe8f7f29 100644 --- a/src/main/java/org/opentripplanner/street/model/edge/StreetVehicleParkingLink.java +++ b/src/main/java/org/opentripplanner/street/model/edge/StreetVehicleParkingLink.java @@ -4,7 +4,7 @@ import org.locationtech.jts.geom.LineString; import org.opentripplanner.framework.i18n.I18NString; import org.opentripplanner.framework.tostring.ToStringBuilder; -import org.opentripplanner.routing.api.request.preference.ParkingPreferences; +import org.opentripplanner.routing.api.request.preference.VehicleParkingPreferences; import org.opentripplanner.routing.vehicle_parking.VehicleParking; import org.opentripplanner.street.model.vertex.StreetVertex; import org.opentripplanner.street.model.vertex.VehicleParkingEntranceVertex; @@ -68,9 +68,9 @@ public State[] traverse(State s0) { } var vehicleParking = vehicleParkingEntranceVertex.getVehicleParking(); - final ParkingPreferences parkingPreferences = s0.currentMode() == TraverseMode.CAR - ? s0.getRequest().preferences().car().parkingPreferences() - : s0.getRequest().preferences().bike().parkingPreferences(); + final VehicleParkingPreferences parkingPreferences = s0.currentMode() == TraverseMode.CAR + ? s0.getRequest().preferences().car().parking() + : s0.getRequest().preferences().bike().parking(); if (traversalBanned(parkingPreferences, vehicleParking)) { return State.empty(); } @@ -83,7 +83,7 @@ public State[] traverse(State s0) { } private boolean traversalBanned( - ParkingPreferences parkingPreferences, + VehicleParkingPreferences parkingPreferences, VehicleParking vehicleParking ) { return !parkingPreferences.filter().matches(vehicleParking); diff --git a/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java b/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java index 595f7929061..9afd2316e6f 100644 --- a/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java +++ b/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java @@ -5,7 +5,7 @@ import org.opentripplanner.routing.api.request.StreetMode; import org.opentripplanner.routing.api.request.preference.BikePreferences; import org.opentripplanner.routing.api.request.preference.CarPreferences; -import org.opentripplanner.routing.api.request.preference.ParkingPreferences; +import org.opentripplanner.routing.api.request.preference.VehicleParkingPreferences; import org.opentripplanner.routing.api.request.preference.RoutingPreferences; import org.opentripplanner.routing.vehicle_parking.VehicleParking; import org.opentripplanner.street.model.vertex.VehicleParkingEntranceVertex; @@ -94,16 +94,16 @@ protected State[] traverseUnPark(State s0) { final BikePreferences bike = s0.getPreferences().bike(); return traverseUnPark( s0, - bike.parkingPreferences().parkCost().toSeconds(), - (int) bike.parkingPreferences().parkTime().toSeconds(), + bike.parking().parkCost().toSeconds(), + (int) bike.parking().parkTime().toSeconds(), TraverseMode.BICYCLE ); } else if (streetMode.includesDriving()) { final CarPreferences car = s0.getPreferences().car(); return traverseUnPark( s0, - car.parkingPreferences().parkCost().toSeconds(), - (int) car.parkingPreferences().parkTime().toSeconds(), + car.parking().parkCost().toSeconds(), + (int) car.parking().parkTime().toSeconds(), TraverseMode.CAR ); } else { @@ -150,14 +150,14 @@ private State[] traversePark(State s0) { return traversePark( s0, - preferences.bike().parkingPreferences().parkCost().toSeconds(), - (int) preferences.bike().parkingPreferences().parkTime().toSeconds() + preferences.bike().parking().parkCost().toSeconds(), + (int) preferences.bike().parking().parkTime().toSeconds() ); } else if (streetMode.includesDriving()) { return traversePark( s0, - preferences.car().parkingPreferences().parkCost().toSeconds(), - (int) preferences.car().parkingPreferences().parkTime().toSeconds() + preferences.car().parking().parkCost().toSeconds(), + (int) preferences.car().parking().parkTime().toSeconds() ); } else { return State.empty(); @@ -186,15 +186,15 @@ private State[] traversePark(State s0, int parkingCost, int parkingTime) { return s0e.makeStateArray(); } - private void addUnpreferredTagCost(ParkingPreferences preferences, StateEditor s0e) { + private void addUnpreferredTagCost(VehicleParkingPreferences preferences, StateEditor s0e) { if (!preferences.preferred().matches(vehicleParking)) { s0e.incrementWeight(preferences.unpreferredVehicleParkingTagCost().toSeconds()); } } - private ParkingPreferences getParkingPreferences(TraverseMode mode, StreetSearchRequest request) { + private VehicleParkingPreferences getParkingPreferences(TraverseMode mode, StreetSearchRequest request) { return mode == TraverseMode.CAR - ? request.preferences().car().parkingPreferences() - : request.preferences().bike().parkingPreferences(); + ? request.preferences().car().parking() + : request.preferences().bike().parking(); } } diff --git a/src/test/java/org/opentripplanner/routing/api/request/preference/ParkingPreferencesTest.java b/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java similarity index 88% rename from src/test/java/org/opentripplanner/routing/api/request/preference/ParkingPreferencesTest.java rename to src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java index 0e900dd5f34..509b808fc83 100644 --- a/src/test/java/org/opentripplanner/routing/api/request/preference/ParkingPreferencesTest.java +++ b/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test; import org.opentripplanner.framework.model.Cost; -class ParkingPreferencesTest { +class VehicleParkingPreferencesTest { private static final Set PREFERRED_TAGS = Set.of("foo"); private static final Set NOT_PREFERRED_TAGS = Set.of("bar"); @@ -20,7 +20,7 @@ class ParkingPreferencesTest { private static final Cost PARKING_COST = Cost.costOfMinutes(4); private static final Duration PARKING_TIME = Duration.ofMinutes(2); - private final ParkingPreferences subject = createPreferences(); + private final VehicleParkingPreferences subject = createPreferences(); @Test void preferred() { @@ -57,10 +57,10 @@ void parkTime() { @Test void testCopyOfEqualsAndHashCode() { // Return same object if no value is set - assertSame(ParkingPreferences.DEFAULT, ParkingPreferences.of().build()); + assertSame(VehicleParkingPreferences.DEFAULT, VehicleParkingPreferences.of().build()); // Create a copy, make a change and set it back again to force creating a new object - var other = ParkingPreferences + var other = VehicleParkingPreferences .of() .withPreferredVehicleParkingTags(Set.of()) .withNotPreferredVehicleParkingTags(Set.of()) @@ -77,7 +77,7 @@ void testCopyOfEqualsAndHashCode() { @Test void testToString() { - assertEquals("ParkingPreferences{}", ParkingPreferences.DEFAULT.toString()); + assertEquals("ParkingPreferences{}", VehicleParkingPreferences.DEFAULT.toString()); assertEquals( "ParkingPreferences{" + "unpreferredVehicleParkingTagCost: $360, " + @@ -94,8 +94,8 @@ private static String tagsToString(Set tags) { return "[tags=" + tags + "]"; } - private ParkingPreferences createPreferences() { - return ParkingPreferences + private VehicleParkingPreferences createPreferences() { + return VehicleParkingPreferences .of() .withPreferredVehicleParkingTags(PREFERRED_TAGS) .withNotPreferredVehicleParkingTags(NOT_PREFERRED_TAGS) From cb0643f60f47c757ab24de8974606a468e8967be Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Tue, 21 Nov 2023 10:36:32 +0200 Subject: [PATCH 05/21] Fix test --- .../api/request/preference/VehicleParkingPreferencesTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java b/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java index 509b808fc83..d86adaaa82b 100644 --- a/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java +++ b/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java @@ -77,9 +77,9 @@ void testCopyOfEqualsAndHashCode() { @Test void testToString() { - assertEquals("ParkingPreferences{}", VehicleParkingPreferences.DEFAULT.toString()); + assertEquals("VehicleParkingPreferences{}", VehicleParkingPreferences.DEFAULT.toString()); assertEquals( - "ParkingPreferences{" + + "VehicleParkingPreferences{" + "unpreferredVehicleParkingTagCost: $360, " + "useAvailabilityInformation: false, " + "filter: VehicleParkingFilterRequest{not: [tags=[not]], select: [tags=[bar]]}, " + From 09835d610daac17be6f090353d3d18fb651acf8a Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Tue, 21 Nov 2023 10:37:53 +0200 Subject: [PATCH 06/21] Fix formatting --- .../api/common/RequestToPreferencesMapper.java | 2 +- .../config/routerequest/RouteRequestConfig.java | 10 +++++++--- .../street/model/edge/VehicleParkingEdge.java | 7 +++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java b/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java index 3e6cdad050e..6ff9e2f97c0 100644 --- a/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java +++ b/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java @@ -6,8 +6,8 @@ import org.opentripplanner.routing.algorithm.filterchain.api.TransitGeneralizedCostFilterParams; import org.opentripplanner.routing.api.request.framework.CostLinearFunction; import org.opentripplanner.routing.api.request.preference.ItineraryFilterPreferences; -import org.opentripplanner.routing.api.request.preference.VehicleParkingPreferences; import org.opentripplanner.routing.api.request.preference.RoutingPreferences; +import org.opentripplanner.routing.api.request.preference.VehicleParkingPreferences; import org.opentripplanner.routing.core.BicycleOptimizeType; class RequestToPreferencesMapper { diff --git a/src/main/java/org/opentripplanner/standalone/config/routerequest/RouteRequestConfig.java b/src/main/java/org/opentripplanner/standalone/config/routerequest/RouteRequestConfig.java index f814785e362..b0488fb6542 100644 --- a/src/main/java/org/opentripplanner/standalone/config/routerequest/RouteRequestConfig.java +++ b/src/main/java/org/opentripplanner/standalone/config/routerequest/RouteRequestConfig.java @@ -19,11 +19,11 @@ import org.opentripplanner.routing.api.request.StreetMode; import org.opentripplanner.routing.api.request.preference.BikePreferences; import org.opentripplanner.routing.api.request.preference.CarPreferences; -import org.opentripplanner.routing.api.request.preference.VehicleParkingPreferences; import org.opentripplanner.routing.api.request.preference.RoutingPreferences; import org.opentripplanner.routing.api.request.preference.StreetPreferences; import org.opentripplanner.routing.api.request.preference.SystemPreferences; import org.opentripplanner.routing.api.request.preference.TransitPreferences; +import org.opentripplanner.routing.api.request.preference.VehicleParkingPreferences; import org.opentripplanner.routing.api.request.preference.WalkPreferences; import org.opentripplanner.standalone.config.framework.json.NodeAdapter; import org.opentripplanner.standalone.config.sandbox.DataOverlayParametersMapper; @@ -424,7 +424,9 @@ private static void mapBikePreferences(NodeAdapter c, BikePreferences.Builder bu .since(V2_3) .summary("What cost to add if a parking facility doesn't contain a preferred tag.") .description("See `preferredVehicleParkingTags`.") - .asInt(VehicleParkingPreferences.DEFAULT.unpreferredVehicleParkingTagCost().toSeconds()) + .asInt( + VehicleParkingPreferences.DEFAULT.unpreferredVehicleParkingTagCost().toSeconds() + ) ) .withBannedVehicleParkingTags( c @@ -720,7 +722,9 @@ private static void mapCarPreferences(NodeAdapter c, CarPreferences.Builder buil .since(V2_3) .summary("What cost to add if a parking facility doesn't contain a preferred tag.") .description("See `preferredVehicleParkingTags`.") - .asInt(VehicleParkingPreferences.DEFAULT.unpreferredVehicleParkingTagCost().toSeconds()) + .asInt( + VehicleParkingPreferences.DEFAULT.unpreferredVehicleParkingTagCost().toSeconds() + ) ) .withBannedVehicleParkingTags( c diff --git a/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java b/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java index 9afd2316e6f..483822ea30a 100644 --- a/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java +++ b/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java @@ -5,8 +5,8 @@ import org.opentripplanner.routing.api.request.StreetMode; import org.opentripplanner.routing.api.request.preference.BikePreferences; import org.opentripplanner.routing.api.request.preference.CarPreferences; -import org.opentripplanner.routing.api.request.preference.VehicleParkingPreferences; import org.opentripplanner.routing.api.request.preference.RoutingPreferences; +import org.opentripplanner.routing.api.request.preference.VehicleParkingPreferences; import org.opentripplanner.routing.vehicle_parking.VehicleParking; import org.opentripplanner.street.model.vertex.VehicleParkingEntranceVertex; import org.opentripplanner.street.search.TraverseMode; @@ -192,7 +192,10 @@ private void addUnpreferredTagCost(VehicleParkingPreferences preferences, StateE } } - private VehicleParkingPreferences getParkingPreferences(TraverseMode mode, StreetSearchRequest request) { + private VehicleParkingPreferences getParkingPreferences( + TraverseMode mode, + StreetSearchRequest request + ) { return mode == TraverseMode.CAR ? request.preferences().car().parking() : request.preferences().bike().parking(); From df56e77849fee2f0c18159aa759fbd0d49a1d0a5 Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Tue, 21 Nov 2023 12:10:20 +0200 Subject: [PATCH 07/21] Rename test method --- .../api/request/preference/VehicleParkingPreferencesTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java b/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java index d86adaaa82b..cd5be940339 100644 --- a/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java +++ b/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java @@ -55,7 +55,7 @@ void parkTime() { } @Test - void testCopyOfEqualsAndHashCode() { + void testEqualsAndHashCode() { // Return same object if no value is set assertSame(VehicleParkingPreferences.DEFAULT, VehicleParkingPreferences.of().build()); From cb5b04ba14543a45f5ee62af22e760f8ac562782 Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Tue, 21 Nov 2023 14:41:29 +0200 Subject: [PATCH 08/21] Minor refactoring --- .../org/opentripplanner/model/plan/Place.java | 4 +-- .../preference/RoutingPreferences.java | 7 ++++ .../model/edge/StreetVehicleParkingLink.java | 7 ++-- .../street/model/edge/VehicleParkingEdge.java | 34 +++++++++---------- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/opentripplanner/model/plan/Place.java b/src/main/java/org/opentripplanner/model/plan/Place.java index 3175c2ec81b..397702b76a2 100644 --- a/src/main/java/org/opentripplanner/model/plan/Place.java +++ b/src/main/java/org/opentripplanner/model/plan/Place.java @@ -135,9 +135,7 @@ public static Place forVehicleParkingEntrance(VehicleParkingEntranceVertex verte traverseMode = TraverseMode.BICYCLE; } - var parkingPreferences = traverseMode == TraverseMode.CAR - ? request.preferences().car().parking() - : request.preferences().bike().parking(); + var parkingPreferences = request.preferences().parking(traverseMode); boolean realTime = parkingPreferences.useAvailabilityInformation() && diff --git a/src/main/java/org/opentripplanner/routing/api/request/preference/RoutingPreferences.java b/src/main/java/org/opentripplanner/routing/api/request/preference/RoutingPreferences.java index 1077ce49334..bcd095d2daa 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/preference/RoutingPreferences.java +++ b/src/main/java/org/opentripplanner/routing/api/request/preference/RoutingPreferences.java @@ -95,6 +95,13 @@ public VehicleRentalPreferences rental() { return rental; } + /** + * Get parking preferences for the traverse mode. Note, only car and bike are supported. + */ + public VehicleParkingPreferences parking(TraverseMode mode) { + return mode == TraverseMode.CAR ? car.parking() : bike.parking(); + } + @Nonnull public ItineraryFilterPreferences itineraryFilter() { return itineraryFilter; diff --git a/src/main/java/org/opentripplanner/street/model/edge/StreetVehicleParkingLink.java b/src/main/java/org/opentripplanner/street/model/edge/StreetVehicleParkingLink.java index e7fbe8f7f29..e682a7bfac1 100644 --- a/src/main/java/org/opentripplanner/street/model/edge/StreetVehicleParkingLink.java +++ b/src/main/java/org/opentripplanner/street/model/edge/StreetVehicleParkingLink.java @@ -68,9 +68,10 @@ public State[] traverse(State s0) { } var vehicleParking = vehicleParkingEntranceVertex.getVehicleParking(); - final VehicleParkingPreferences parkingPreferences = s0.currentMode() == TraverseMode.CAR - ? s0.getRequest().preferences().car().parking() - : s0.getRequest().preferences().bike().parking(); + final VehicleParkingPreferences parkingPreferences = s0 + .getRequest() + .preferences() + .parking(s0.currentMode()); if (traversalBanned(parkingPreferences, vehicleParking)) { return State.empty(); } diff --git a/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java b/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java index 483822ea30a..0d8311a9f7a 100644 --- a/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java +++ b/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java @@ -1,7 +1,9 @@ package org.opentripplanner.street.model.edge; +import java.time.Duration; import javax.annotation.Nonnull; import org.opentripplanner.framework.i18n.I18NString; +import org.opentripplanner.framework.model.Cost; import org.opentripplanner.routing.api.request.StreetMode; import org.opentripplanner.routing.api.request.preference.BikePreferences; import org.opentripplanner.routing.api.request.preference.CarPreferences; @@ -94,16 +96,16 @@ protected State[] traverseUnPark(State s0) { final BikePreferences bike = s0.getPreferences().bike(); return traverseUnPark( s0, - bike.parking().parkCost().toSeconds(), - (int) bike.parking().parkTime().toSeconds(), + bike.parking().parkCost(), + bike.parking().parkTime(), TraverseMode.BICYCLE ); } else if (streetMode.includesDriving()) { final CarPreferences car = s0.getPreferences().car(); return traverseUnPark( s0, - car.parking().parkCost().toSeconds(), - (int) car.parking().parkTime().toSeconds(), + car.parking().parkCost(), + car.parking().parkTime(), TraverseMode.CAR ); } else { @@ -111,9 +113,14 @@ protected State[] traverseUnPark(State s0) { } } - private State[] traverseUnPark(State s0, int parkingCost, int parkingTime, TraverseMode mode) { + private State[] traverseUnPark( + State s0, + Cost parkingCost, + Duration parkingTime, + TraverseMode mode + ) { final StreetSearchRequest request = s0.getRequest(); - var parkingPreferences = getParkingPreferences(s0.currentMode(), s0.getRequest()); + var parkingPreferences = s0.getRequest().preferences().parking(s0.currentMode()); if ( !vehicleParking.hasSpacesAvailable( mode, @@ -125,8 +132,8 @@ private State[] traverseUnPark(State s0, int parkingCost, int parkingTime, Trave } StateEditor s0e = s0.edit(this); - s0e.incrementWeight(parkingCost); - s0e.incrementTimeInSeconds(parkingTime); + s0e.incrementWeight(parkingCost.toSeconds()); + s0e.incrementTimeInSeconds((int) parkingTime.toSeconds()); s0e.setVehicleParked(false, mode); addUnpreferredTagCost(parkingPreferences, s0e); @@ -165,7 +172,7 @@ private State[] traversePark(State s0) { } private State[] traversePark(State s0, int parkingCost, int parkingTime) { - var parkingPreferences = getParkingPreferences(s0.currentMode(), s0.getRequest()); + var parkingPreferences = s0.getRequest().preferences().parking(s0.currentMode()); if ( !vehicleParking.hasSpacesAvailable( s0.currentMode(), @@ -191,13 +198,4 @@ private void addUnpreferredTagCost(VehicleParkingPreferences preferences, StateE s0e.incrementWeight(preferences.unpreferredVehicleParkingTagCost().toSeconds()); } } - - private VehicleParkingPreferences getParkingPreferences( - TraverseMode mode, - StreetSearchRequest request - ) { - return mode == TraverseMode.CAR - ? request.preferences().car().parking() - : request.preferences().bike().parking(); - } } From 5ee913e2f6fc1ed1112ccedd37be0d129158dfe0 Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Tue, 21 Nov 2023 14:48:31 +0200 Subject: [PATCH 09/21] Add back tests for the GTFS API --- .../gtfs/mapping/RouteRequestMapperTest.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/test/java/org/opentripplanner/apis/gtfs/mapping/RouteRequestMapperTest.java b/src/test/java/org/opentripplanner/apis/gtfs/mapping/RouteRequestMapperTest.java index 7e6a7cbb36c..45595f3af20 100644 --- a/src/test/java/org/opentripplanner/apis/gtfs/mapping/RouteRequestMapperTest.java +++ b/src/test/java/org/opentripplanner/apis/gtfs/mapping/RouteRequestMapperTest.java @@ -25,11 +25,13 @@ import org.opentripplanner.model.plan.PlanTestConstants; import org.opentripplanner.routing.api.request.RouteRequest; import org.opentripplanner.routing.api.request.preference.TimeSlopeSafetyTriangle; +import org.opentripplanner.routing.api.request.preference.VehicleParkingPreferences; import org.opentripplanner.routing.core.BicycleOptimizeType; import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.routing.graphfinder.GraphFinder; import org.opentripplanner.service.realtimevehicles.internal.DefaultRealtimeVehicleService; import org.opentripplanner.service.vehiclerental.internal.DefaultVehicleRentalService; +import org.opentripplanner.street.search.TraverseMode; import org.opentripplanner.test.support.VariableSource; import org.opentripplanner.transit.service.DefaultTransitService; import org.opentripplanner.transit.service.TransitModel; @@ -56,6 +58,37 @@ class RouteRequestMapperTest implements PlanTestConstants { ); } + @Test + void parkingFilters() { + Map arguments = Map.of( + "parking", + Map.of( + "unpreferredCost", + 555, + "filters", + List.of( + Map.of( + "not", + List.of(Map.of("tags", List.of("wheelbender"))), + "select", + List.of(Map.of("tags", List.of("roof", "locker"))) + ) + ), + "preferred", + List.of(Map.of("select", List.of(Map.of("tags", List.of("a", "b"))))) + ) + ); + + var env = executionContext(arguments); + + var routeRequest = RouteRequestMapper.toRouteRequest(env, context); + + assertNotNull(routeRequest); + + testParkingFilters(routeRequest.preferences().parking(TraverseMode.CAR)); + testParkingFilters(routeRequest.preferences().parking(TraverseMode.BICYCLE)); + } + static Stream banningCases = Stream.of( of(Map.of(), "[TransitFilterRequest{}]"), of( @@ -179,4 +212,16 @@ private DataFetchingEnvironment executionContext(Map arguments) .arguments(arguments) .build(); } + + private void testParkingFilters(VehicleParkingPreferences parkingPreferences) { + assertEquals( + "VehicleParkingFilterRequest{not: [tags=[wheelbender]], select: [tags=[locker, roof]]}", + parkingPreferences.filter().toString() + ); + assertEquals( + "VehicleParkingFilterRequest{select: [tags=[a, b]]}", + parkingPreferences.preferred().toString() + ); + assertEquals(555, parkingPreferences.unpreferredVehicleParkingTagCost().toSeconds()); + } } From a21adb25a7f98e88a2d4d04ce896a74a6befbade Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Thu, 23 Nov 2023 14:28:52 +0200 Subject: [PATCH 10/21] Rename useAvailabilityInformation -> ignoreRealtimeAvailability --- .../common/RequestToPreferencesMapper.java | 3 +- .../framework/tostring/ToStringBuilder.java | 4 --- .../org/opentripplanner/model/plan/Place.java | 2 +- .../preference/VehicleParkingPreferences.java | 28 ++++++++----------- .../street/model/edge/VehicleParkingEdge.java | 4 +-- .../tostring/ToStringBuilderTest.java | 5 ---- .../VehicleParkingPreferencesTest.java | 8 +++--- .../model/edge/VehicleParkingEdgeTest.java | 20 ++++++------- 8 files changed, 31 insertions(+), 43 deletions(-) diff --git a/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java b/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java index 6ff9e2f97c0..6bcd9490d98 100644 --- a/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java +++ b/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java @@ -170,7 +170,8 @@ private TransitGeneralizedCostFilterParams mapTransitGeneralizedCostFilterParams private void mapParking(VehicleParkingPreferences.Builder builder) { setIfNotNull( req.useVehicleParkingAvailabilityInformation, - builder::withUseAvailabilityInformation + useVehicleParkingAvailabilityInformation -> + builder.withIgnoreRealtimeAvailability(!useVehicleParkingAvailabilityInformation) ); builder.withRequiredVehicleParkingTags(req.requiredVehicleParkingTags); diff --git a/src/main/java/org/opentripplanner/framework/tostring/ToStringBuilder.java b/src/main/java/org/opentripplanner/framework/tostring/ToStringBuilder.java index 477d9e9938e..f6c17b19af1 100644 --- a/src/main/java/org/opentripplanner/framework/tostring/ToStringBuilder.java +++ b/src/main/java/org/opentripplanner/framework/tostring/ToStringBuilder.java @@ -95,10 +95,6 @@ public ToStringBuilder addBool(String name, Boolean value) { return addIfNotNull(name, value); } - public ToStringBuilder addBool(String name, Boolean value, Boolean ignoreValue) { - return addIfNotIgnored(name, value, ignoreValue, Object::toString); - } - public ToStringBuilder addBoolIfTrue(String name, Boolean value) { if (TRUE.equals(value)) { addLabel(name); diff --git a/src/main/java/org/opentripplanner/model/plan/Place.java b/src/main/java/org/opentripplanner/model/plan/Place.java index 397702b76a2..efdde16899a 100644 --- a/src/main/java/org/opentripplanner/model/plan/Place.java +++ b/src/main/java/org/opentripplanner/model/plan/Place.java @@ -138,7 +138,7 @@ public static Place forVehicleParkingEntrance(VehicleParkingEntranceVertex verte var parkingPreferences = request.preferences().parking(traverseMode); boolean realTime = - parkingPreferences.useAvailabilityInformation() && + !parkingPreferences.ignoreRealtimeAvailability() && vertex.getVehicleParking().hasRealTimeDataForMode(traverseMode, request.wheelchair()); return new Place( vertex.getName(), diff --git a/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java b/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java index bcfa8805547..7bb39b5b0fd 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java +++ b/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java @@ -20,7 +20,7 @@ public final class VehicleParkingPreferences implements Serializable { public static final VehicleParkingPreferences DEFAULT = new VehicleParkingPreferences(); private final Cost unpreferredVehicleParkingTagCost; - private final boolean useAvailabilityInformation; + private final boolean ignoreRealtimeAvailability; private final VehicleParkingFilterRequest filter; private final VehicleParkingFilterRequest preferred; private final Duration parkTime; @@ -29,7 +29,7 @@ public final class VehicleParkingPreferences implements Serializable { /** Create a new instance with default values. */ private VehicleParkingPreferences() { this.unpreferredVehicleParkingTagCost = Cost.costOfMinutes(5); - this.useAvailabilityInformation = true; + this.ignoreRealtimeAvailability = false; this.filter = VehicleParkingFilterRequest.empty(); this.preferred = VehicleParkingFilterRequest.empty(); this.parkTime = Duration.ofMinutes(1); @@ -38,7 +38,7 @@ private VehicleParkingPreferences() { private VehicleParkingPreferences(Builder builder) { this.unpreferredVehicleParkingTagCost = builder.unpreferredVehicleParkingTagCost; - this.useAvailabilityInformation = builder.useAvailabilityInformation; + this.ignoreRealtimeAvailability = builder.ignoreRealtimeAvailability; this.filter = new VehicleParkingFilterRequest( builder.bannedVehicleParkingTags, @@ -67,8 +67,8 @@ public Cost unpreferredVehicleParkingTagCost() { /** * Should availability information be used during routing. */ - public boolean useAvailabilityInformation() { - return useAvailabilityInformation; + public boolean ignoreRealtimeAvailability() { + return ignoreRealtimeAvailability; } /** @@ -106,7 +106,7 @@ public boolean equals(Object o) { VehicleParkingPreferences that = (VehicleParkingPreferences) o; return ( Objects.equals(unpreferredVehicleParkingTagCost, that.unpreferredVehicleParkingTagCost) && - useAvailabilityInformation == that.useAvailabilityInformation && + ignoreRealtimeAvailability == that.ignoreRealtimeAvailability && Objects.equals(filter, that.filter) && Objects.equals(preferred, that.preferred) && Objects.equals(parkCost, that.parkCost) && @@ -118,7 +118,7 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash( unpreferredVehicleParkingTagCost, - useAvailabilityInformation, + ignoreRealtimeAvailability, filter, preferred, parkCost, @@ -135,11 +135,7 @@ public String toString() { unpreferredVehicleParkingTagCost, DEFAULT.unpreferredVehicleParkingTagCost ) - .addBool( - "useAvailabilityInformation", - useAvailabilityInformation, - DEFAULT.useAvailabilityInformation - ) + .addBoolIfTrue("ignoreRealtimeAvailability", ignoreRealtimeAvailability) .addObj("filter", filter, DEFAULT.filter) .addObj("preferred", preferred, DEFAULT.preferred) .addObj("parkCost", parkCost, DEFAULT.parkCost) @@ -151,7 +147,7 @@ public static class Builder { private final VehicleParkingPreferences original; private Cost unpreferredVehicleParkingTagCost; - private boolean useAvailabilityInformation; + private boolean ignoreRealtimeAvailability; private List bannedVehicleParkingTags; private List requiredVehicleParkingTags; private List preferredVehicleParkingTags; @@ -162,7 +158,7 @@ public static class Builder { private Builder(VehicleParkingPreferences original) { this.original = original; this.unpreferredVehicleParkingTagCost = original.unpreferredVehicleParkingTagCost; - this.useAvailabilityInformation = original.useAvailabilityInformation; + this.ignoreRealtimeAvailability = original.ignoreRealtimeAvailability; this.bannedVehicleParkingTags = original.filter.not(); this.requiredVehicleParkingTags = original.filter.select(); this.preferredVehicleParkingTags = original.preferred.select(); @@ -176,8 +172,8 @@ public Builder withUnpreferredVehicleParkingTagCost(int cost) { return this; } - public Builder withUseAvailabilityInformation(boolean useAvailabilityInformation) { - this.useAvailabilityInformation = useAvailabilityInformation; + public Builder withIgnoreRealtimeAvailability(boolean ignoreRealtimeAvailability) { + this.ignoreRealtimeAvailability = ignoreRealtimeAvailability; return this; } diff --git a/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java b/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java index 0d8311a9f7a..e4352821115 100644 --- a/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java +++ b/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java @@ -125,7 +125,7 @@ private State[] traverseUnPark( !vehicleParking.hasSpacesAvailable( mode, request.wheelchair(), - parkingPreferences.useAvailabilityInformation() + parkingPreferences.ignoreRealtimeAvailability() ) ) { return State.empty(); @@ -177,7 +177,7 @@ private State[] traversePark(State s0, int parkingCost, int parkingTime) { !vehicleParking.hasSpacesAvailable( s0.currentMode(), s0.getRequest().wheelchair(), - parkingPreferences.useAvailabilityInformation() + parkingPreferences.ignoreRealtimeAvailability() ) ) { return State.empty(); diff --git a/src/test/java/org/opentripplanner/framework/tostring/ToStringBuilderTest.java b/src/test/java/org/opentripplanner/framework/tostring/ToStringBuilderTest.java index 1387c9af905..ca35c8272db 100644 --- a/src/test/java/org/opentripplanner/framework/tostring/ToStringBuilderTest.java +++ b/src/test/java/org/opentripplanner/framework/tostring/ToStringBuilderTest.java @@ -77,11 +77,6 @@ public void addBool() { "ToStringBuilderTest{a: true, b: false}", subject().addBool("a", true).addBool("b", false).toString() ); - - assertEquals( - "ToStringBuilderTest{a: true}", - subject().addBool("a", true, false).addBool("b", false, false).toString() - ); } @Test diff --git a/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java b/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java index cd5be940339..fac528ad2e0 100644 --- a/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java +++ b/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java @@ -14,7 +14,7 @@ class VehicleParkingPreferencesTest { private static final Set PREFERRED_TAGS = Set.of("foo"); private static final Set NOT_PREFERRED_TAGS = Set.of("bar"); private static final int UNPREFERRED_COST = 360; - private static final boolean REALTIME = false; + private static final boolean IGNORE_REALTIME = true; private static final Set REQUIRED_TAGS = Set.of("bar"); private static final Set BANNED_TAGS = Set.of("not"); private static final Cost PARKING_COST = Cost.costOfMinutes(4); @@ -41,7 +41,7 @@ void unpreferredCost() { @Test void useAvailabilityInformation() { - assertEquals(REALTIME, subject.useAvailabilityInformation()); + assertEquals(IGNORE_REALTIME, subject.ignoreRealtimeAvailability()); } @Test @@ -65,7 +65,7 @@ void testEqualsAndHashCode() { .withPreferredVehicleParkingTags(Set.of()) .withNotPreferredVehicleParkingTags(Set.of()) .withUnpreferredVehicleParkingTagCost(0) - .withUseAvailabilityInformation(true) + .withIgnoreRealtimeAvailability(false) .withRequiredVehicleParkingTags(Set.of()) .withBannedVehicleParkingTags(Set.of()) .withParkCost(0) @@ -100,7 +100,7 @@ private VehicleParkingPreferences createPreferences() { .withPreferredVehicleParkingTags(PREFERRED_TAGS) .withNotPreferredVehicleParkingTags(NOT_PREFERRED_TAGS) .withUnpreferredVehicleParkingTagCost(UNPREFERRED_COST) - .withUseAvailabilityInformation(REALTIME) + .withIgnoreRealtimeAvailability(IGNORE_REALTIME) .withRequiredVehicleParkingTags(REQUIRED_TAGS) .withBannedVehicleParkingTags(BANNED_TAGS) .withParkCost(PARKING_COST.toSeconds()) diff --git a/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingEdgeTest.java b/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingEdgeTest.java index 30aa0ee9228..919f141a1be 100644 --- a/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingEdgeTest.java +++ b/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingEdgeTest.java @@ -46,7 +46,7 @@ public void realtimeAvailableCarPlacesTest() { false, true, VehicleParkingSpaces.builder().carSpaces(1).build(), - true + false ); var s1 = traverse(); @@ -56,7 +56,7 @@ public void realtimeAvailableCarPlacesTest() { @Test public void realtimeAvailableCarPlacesFallbackTest() { - initEdgeAndRequest(StreetMode.CAR_TO_PARK, false, true, null, true); + initEdgeAndRequest(StreetMode.CAR_TO_PARK, false, true, null, false); var s1 = traverse(); @@ -70,7 +70,7 @@ public void realtimeNotAvailableCarPlacesTest() { false, true, VehicleParkingSpaces.builder().carSpaces(0).build(), - true + false ); var s1 = traverse(); @@ -103,7 +103,7 @@ public void realtimeAvailableBicyclePlacesTest() { true, false, VehicleParkingSpaces.builder().bicycleSpaces(1).build(), - true + false ); var s1 = traverse(); @@ -113,7 +113,7 @@ public void realtimeAvailableBicyclePlacesTest() { @Test public void realtimeAvailableBicyclePlacesFallbackTest() { - initEdgeAndRequest(StreetMode.BIKE_TO_PARK, true, false, null, true); + initEdgeAndRequest(StreetMode.BIKE_TO_PARK, true, false, null, false); var s1 = traverse(); @@ -127,7 +127,7 @@ public void realtimeNotAvailableBicyclePlacesTest() { true, false, VehicleParkingSpaces.builder().bicycleSpaces(0).build(), - true + false ); var s1 = traverse(); @@ -140,7 +140,7 @@ private void initEdgeAndRequest( boolean bicyclePlaces, boolean carPlaces ) { - initEdgeAndRequest(parkingMode, bicyclePlaces, carPlaces, null, false); + initEdgeAndRequest(parkingMode, bicyclePlaces, carPlaces, null, true); } private void initEdgeAndRequest( @@ -148,7 +148,7 @@ private void initEdgeAndRequest( boolean bicyclePlaces, boolean carPlaces, VehicleParkingSpaces availability, - boolean realtime + boolean ignoreRealtime ) { var vehicleParking = createVehicleParking(bicyclePlaces, carPlaces, availability); this.vertex = new VehicleParkingEntranceVertex(vehicleParking.getEntrances().get(0)); @@ -161,10 +161,10 @@ private void initEdgeAndRequest( .withMode(parkingMode) .withPreferences(preferences -> { preferences.withBike(bike -> - bike.withParking(parking -> parking.withUseAvailabilityInformation(realtime)) + bike.withParking(parking -> parking.withIgnoreRealtimeAvailability(ignoreRealtime)) ); preferences.withCar(car -> - car.withParking(parking -> parking.withUseAvailabilityInformation(realtime)) + car.withParking(parking -> parking.withIgnoreRealtimeAvailability(ignoreRealtime)) ); }) .build(); From 13ab477fceeedd93bd1ecd26b3befefe57b77fa2 Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Thu, 23 Nov 2023 14:35:03 +0200 Subject: [PATCH 11/21] Fix comment --- .../api/request/preference/VehicleParkingPreferencesTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java b/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java index fac528ad2e0..826e738d22f 100644 --- a/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java +++ b/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java @@ -59,7 +59,7 @@ void testEqualsAndHashCode() { // Return same object if no value is set assertSame(VehicleParkingPreferences.DEFAULT, VehicleParkingPreferences.of().build()); - // Create a copy, make a change and set it back again to force creating a new object + // Create other with different values and same with the same values as the subject var other = VehicleParkingPreferences .of() .withPreferredVehicleParkingTags(Set.of()) From 7d692773f08dd12f831084e961ec7f29aae1317d Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Thu, 23 Nov 2023 17:22:15 +0200 Subject: [PATCH 12/21] Rename VehicleParkingFilter -> VehicleParkingSelect --- .../preference/VehicleParkingPreferences.java | 18 +++++++++--------- .../filter/VehicleParkingFilterRequest.java | 18 +++++++++--------- ...ngFilter.java => VehicleParkingSelect.java} | 8 ++++---- 3 files changed, 22 insertions(+), 22 deletions(-) rename src/main/java/org/opentripplanner/routing/api/request/request/filter/{VehicleParkingFilter.java => VehicleParkingSelect.java} (81%) diff --git a/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java b/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java index 7bb39b5b0fd..7175817b18c 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java +++ b/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java @@ -7,7 +7,7 @@ import java.util.Set; import org.opentripplanner.framework.model.Cost; import org.opentripplanner.framework.tostring.ToStringBuilder; -import org.opentripplanner.routing.api.request.request.filter.VehicleParkingFilter; +import org.opentripplanner.routing.api.request.request.filter.VehicleParkingSelect; import org.opentripplanner.routing.api.request.request.filter.VehicleParkingFilterRequest; /** @@ -148,10 +148,10 @@ public static class Builder { private final VehicleParkingPreferences original; private Cost unpreferredVehicleParkingTagCost; private boolean ignoreRealtimeAvailability; - private List bannedVehicleParkingTags; - private List requiredVehicleParkingTags; - private List preferredVehicleParkingTags; - private List notPreferredVehicleParkingTags; + private List bannedVehicleParkingTags; + private List requiredVehicleParkingTags; + private List preferredVehicleParkingTags; + private List notPreferredVehicleParkingTags; private Cost parkCost; private Duration parkTime; @@ -179,25 +179,25 @@ public Builder withIgnoreRealtimeAvailability(boolean ignoreRealtimeAvailability public Builder withBannedVehicleParkingTags(Set bannedVehicleParkingTags) { this.bannedVehicleParkingTags = - List.of(new VehicleParkingFilter.TagsFilter(bannedVehicleParkingTags)); + List.of(new VehicleParkingSelect.TagsSelect(bannedVehicleParkingTags)); return this; } public Builder withRequiredVehicleParkingTags(Set requiredVehicleParkingTags) { this.requiredVehicleParkingTags = - List.of(new VehicleParkingFilter.TagsFilter(requiredVehicleParkingTags)); + List.of(new VehicleParkingSelect.TagsSelect(requiredVehicleParkingTags)); return this; } public Builder withPreferredVehicleParkingTags(Set preferredVehicleParkingTags) { this.preferredVehicleParkingTags = - List.of(new VehicleParkingFilter.TagsFilter(preferredVehicleParkingTags)); + List.of(new VehicleParkingSelect.TagsSelect(preferredVehicleParkingTags)); return this; } public Builder withNotPreferredVehicleParkingTags(Set notPreferredVehicleParkingTags) { this.notPreferredVehicleParkingTags = - List.of(new VehicleParkingFilter.TagsFilter(notPreferredVehicleParkingTags)); + List.of(new VehicleParkingSelect.TagsSelect(notPreferredVehicleParkingTags)); return this; } diff --git a/src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingFilterRequest.java b/src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingFilterRequest.java index 353ac72ada9..93c7d289e19 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingFilterRequest.java +++ b/src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingFilterRequest.java @@ -14,26 +14,26 @@ */ public class VehicleParkingFilterRequest implements Serializable { - private final VehicleParkingFilter[] not; - private final VehicleParkingFilter[] select; + private final VehicleParkingSelect[] not; + private final VehicleParkingSelect[] select; public VehicleParkingFilterRequest( - Collection not, - Collection select + Collection not, + Collection select ) { this.not = makeFilter(not); this.select = makeFilter(select); } - public VehicleParkingFilterRequest(VehicleParkingFilter not, VehicleParkingFilter select) { + public VehicleParkingFilterRequest(VehicleParkingSelect not, VehicleParkingSelect select) { this(List.of(not), List.of(select)); } - public List not() { + public List not() { return Arrays.asList(not); } - public List select() { + public List select() { return Arrays.asList(select); } @@ -88,7 +88,7 @@ public int hashCode() { } @Nonnull - private static VehicleParkingFilter[] makeFilter(Collection select) { - return select.stream().filter(f -> !f.isEmpty()).toArray(VehicleParkingFilter[]::new); + private static VehicleParkingSelect[] makeFilter(Collection select) { + return select.stream().filter(f -> !f.isEmpty()).toArray(VehicleParkingSelect[]::new); } } diff --git a/src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingFilter.java b/src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingSelect.java similarity index 81% rename from src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingFilter.java rename to src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingSelect.java index a4c240e7160..8f05531ad34 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingFilter.java +++ b/src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingSelect.java @@ -8,18 +8,18 @@ * A set of conditions that can be used to check if a parking facility should be included/excluded * or preferred/unpreferred. */ -public sealed interface VehicleParkingFilter { +public sealed interface VehicleParkingSelect { /** - * Checks if the parking facilities matches the conditions of the filter. + * Checks if the parking facilities matches the conditions of the select. */ boolean matches(VehicleParking p); /** - * Whether this filter defines any condition. + * Whether this select defines any condition. */ boolean isEmpty(); - record TagsFilter(Set tags) implements VehicleParkingFilter { + record TagsSelect(Set tags) implements VehicleParkingSelect { @Override public boolean matches(VehicleParking p) { return !Collections.disjoint(tags, p.getTags()); From d1f91caa69fb847f77afd777ca283ca9175aff59 Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Thu, 23 Nov 2023 17:24:22 +0200 Subject: [PATCH 13/21] Rename VehicleParkingFilterRequest -> VehicleParkingFilter --- .../preference/VehicleParkingPreferences.java | 18 +++++++++--------- ...rRequest.java => VehicleParkingFilter.java} | 14 +++++++------- 2 files changed, 16 insertions(+), 16 deletions(-) rename src/main/java/org/opentripplanner/routing/api/request/request/filter/{VehicleParkingFilterRequest.java => VehicleParkingFilter.java} (81%) diff --git a/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java b/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java index 7175817b18c..5aaeaf17d07 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java +++ b/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java @@ -8,7 +8,7 @@ import org.opentripplanner.framework.model.Cost; import org.opentripplanner.framework.tostring.ToStringBuilder; import org.opentripplanner.routing.api.request.request.filter.VehicleParkingSelect; -import org.opentripplanner.routing.api.request.request.filter.VehicleParkingFilterRequest; +import org.opentripplanner.routing.api.request.request.filter.VehicleParkingFilter; /** * The parking preferences contain preferences for car and bicycle parking. These preferences @@ -21,8 +21,8 @@ public final class VehicleParkingPreferences implements Serializable { public static final VehicleParkingPreferences DEFAULT = new VehicleParkingPreferences(); private final Cost unpreferredVehicleParkingTagCost; private final boolean ignoreRealtimeAvailability; - private final VehicleParkingFilterRequest filter; - private final VehicleParkingFilterRequest preferred; + private final VehicleParkingFilter filter; + private final VehicleParkingFilter preferred; private final Duration parkTime; private final Cost parkCost; @@ -30,8 +30,8 @@ public final class VehicleParkingPreferences implements Serializable { private VehicleParkingPreferences() { this.unpreferredVehicleParkingTagCost = Cost.costOfMinutes(5); this.ignoreRealtimeAvailability = false; - this.filter = VehicleParkingFilterRequest.empty(); - this.preferred = VehicleParkingFilterRequest.empty(); + this.filter = VehicleParkingFilter.empty(); + this.preferred = VehicleParkingFilter.empty(); this.parkTime = Duration.ofMinutes(1); this.parkCost = Cost.costOfMinutes(2); } @@ -40,12 +40,12 @@ private VehicleParkingPreferences(Builder builder) { this.unpreferredVehicleParkingTagCost = builder.unpreferredVehicleParkingTagCost; this.ignoreRealtimeAvailability = builder.ignoreRealtimeAvailability; this.filter = - new VehicleParkingFilterRequest( + new VehicleParkingFilter( builder.bannedVehicleParkingTags, builder.requiredVehicleParkingTags ); this.preferred = - new VehicleParkingFilterRequest( + new VehicleParkingFilter( builder.notPreferredVehicleParkingTags, builder.preferredVehicleParkingTags ); @@ -75,7 +75,7 @@ public boolean ignoreRealtimeAvailability() { * Parking containing select filters must only be usable and parking containing with not filters * cannot be used. */ - public VehicleParkingFilterRequest filter() { + public VehicleParkingFilter filter() { return filter; } @@ -85,7 +85,7 @@ public VehicleParkingFilterRequest filter() { *

* This is useful if you want to use certain kind of facilities, like lockers for expensive e-bikes. */ - public VehicleParkingFilterRequest preferred() { + public VehicleParkingFilter preferred() { return preferred; } diff --git a/src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingFilterRequest.java b/src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingFilter.java similarity index 81% rename from src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingFilterRequest.java rename to src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingFilter.java index 93c7d289e19..a2c47de3983 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingFilterRequest.java +++ b/src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingFilter.java @@ -9,15 +9,15 @@ import org.opentripplanner.routing.vehicle_parking.VehicleParking; /** - * A request object that checks if parking faclities match certain conditions for + * A filter class that checks if parking faclities match certain conditions for * inclusion/exclusion or preference/unpreference. */ -public class VehicleParkingFilterRequest implements Serializable { +public class VehicleParkingFilter implements Serializable { private final VehicleParkingSelect[] not; private final VehicleParkingSelect[] select; - public VehicleParkingFilterRequest( + public VehicleParkingFilter( Collection not, Collection select ) { @@ -25,7 +25,7 @@ public VehicleParkingFilterRequest( this.select = makeFilter(select); } - public VehicleParkingFilterRequest(VehicleParkingSelect not, VehicleParkingSelect select) { + public VehicleParkingFilter(VehicleParkingSelect not, VehicleParkingSelect select) { this(List.of(not), List.of(select)); } @@ -40,8 +40,8 @@ public List select() { /** * Create a request with no conditions. */ - public static VehicleParkingFilterRequest empty() { - return new VehicleParkingFilterRequest(List.of(), List.of()); + public static VehicleParkingFilter empty() { + return new VehicleParkingFilter(List.of(), List.of()); } /** @@ -78,7 +78,7 @@ public String toString() { public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - VehicleParkingFilterRequest that = (VehicleParkingFilterRequest) o; + VehicleParkingFilter that = (VehicleParkingFilter) o; return (Arrays.equals(not, that.not) && Arrays.equals(select, that.select)); } From 009f9053cf83e683ff60774eb8e0787df27411c5 Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Thu, 23 Nov 2023 17:32:08 +0200 Subject: [PATCH 14/21] Move to classes to another package --- .../api/request/preference/VehicleParkingPreferences.java | 4 ++-- .../{request => preference}/filter/VehicleParkingFilter.java | 2 +- .../{request => preference}/filter/VehicleParkingSelect.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename src/main/java/org/opentripplanner/routing/api/request/{request => preference}/filter/VehicleParkingFilter.java (97%) rename src/main/java/org/opentripplanner/routing/api/request/{request => preference}/filter/VehicleParkingSelect.java (93%) diff --git a/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java b/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java index 5aaeaf17d07..1b480c3d796 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java +++ b/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java @@ -7,8 +7,8 @@ import java.util.Set; import org.opentripplanner.framework.model.Cost; import org.opentripplanner.framework.tostring.ToStringBuilder; -import org.opentripplanner.routing.api.request.request.filter.VehicleParkingSelect; -import org.opentripplanner.routing.api.request.request.filter.VehicleParkingFilter; +import org.opentripplanner.routing.api.request.preference.filter.VehicleParkingSelect; +import org.opentripplanner.routing.api.request.preference.filter.VehicleParkingFilter; /** * The parking preferences contain preferences for car and bicycle parking. These preferences diff --git a/src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingFilter.java b/src/main/java/org/opentripplanner/routing/api/request/preference/filter/VehicleParkingFilter.java similarity index 97% rename from src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingFilter.java rename to src/main/java/org/opentripplanner/routing/api/request/preference/filter/VehicleParkingFilter.java index a2c47de3983..c4f5cee422f 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingFilter.java +++ b/src/main/java/org/opentripplanner/routing/api/request/preference/filter/VehicleParkingFilter.java @@ -1,4 +1,4 @@ -package org.opentripplanner.routing.api.request.request.filter; +package org.opentripplanner.routing.api.request.preference.filter; import java.io.Serializable; import java.util.Arrays; diff --git a/src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingSelect.java b/src/main/java/org/opentripplanner/routing/api/request/preference/filter/VehicleParkingSelect.java similarity index 93% rename from src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingSelect.java rename to src/main/java/org/opentripplanner/routing/api/request/preference/filter/VehicleParkingSelect.java index 8f05531ad34..2d3935461d4 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/request/filter/VehicleParkingSelect.java +++ b/src/main/java/org/opentripplanner/routing/api/request/preference/filter/VehicleParkingSelect.java @@ -1,4 +1,4 @@ -package org.opentripplanner.routing.api.request.request.filter; +package org.opentripplanner.routing.api.request.preference.filter; import java.util.Collections; import java.util.Set; From 271332f8e70888ba1f9a8fe7932c2b155d169076 Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Thu, 23 Nov 2023 17:37:49 +0200 Subject: [PATCH 15/21] Fix formatting --- .../api/request/preference/VehicleParkingPreferences.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java b/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java index 1b480c3d796..166b5a25c85 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java +++ b/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java @@ -7,8 +7,8 @@ import java.util.Set; import org.opentripplanner.framework.model.Cost; import org.opentripplanner.framework.tostring.ToStringBuilder; -import org.opentripplanner.routing.api.request.preference.filter.VehicleParkingSelect; import org.opentripplanner.routing.api.request.preference.filter.VehicleParkingFilter; +import org.opentripplanner.routing.api.request.preference.filter.VehicleParkingSelect; /** * The parking preferences contain preferences for car and bicycle parking. These preferences From a9af343cad72ec2d7e92483e11622ca927ac0960 Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Thu, 23 Nov 2023 17:56:37 +0200 Subject: [PATCH 16/21] Fix realtime check --- .../routing/vehicle_parking/VehicleParking.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/opentripplanner/routing/vehicle_parking/VehicleParking.java b/src/main/java/org/opentripplanner/routing/vehicle_parking/VehicleParking.java index 3aadbdcd37c..b4a8eee17b3 100644 --- a/src/main/java/org/opentripplanner/routing/vehicle_parking/VehicleParking.java +++ b/src/main/java/org/opentripplanner/routing/vehicle_parking/VehicleParking.java @@ -218,24 +218,24 @@ public boolean hasRealTimeData() { public boolean hasSpacesAvailable( TraverseMode traverseMode, boolean wheelchairAccessible, - boolean useAvailability + boolean ignoreRealtimeAvailability ) { switch (traverseMode) { case BICYCLE: - if (useAvailability && hasRealTimeDataForMode(TraverseMode.BICYCLE, false)) { + if (!ignoreRealtimeAvailability && hasRealTimeDataForMode(TraverseMode.BICYCLE, false)) { return availability.getBicycleSpaces() > 0; } else { return bicyclePlaces; } case CAR: if (wheelchairAccessible) { - if (useAvailability && hasRealTimeDataForMode(TraverseMode.CAR, true)) { + if (!ignoreRealtimeAvailability && hasRealTimeDataForMode(TraverseMode.CAR, true)) { return availability.getWheelchairAccessibleCarSpaces() > 0; } else { return wheelchairAccessibleCarPlaces; } } else { - if (useAvailability && hasRealTimeDataForMode(TraverseMode.CAR, false)) { + if (!ignoreRealtimeAvailability && hasRealTimeDataForMode(TraverseMode.CAR, false)) { return availability.getCarSpaces() > 0; } else { return carPlaces; From 19d3a3b953a7e2d8bc769527709210c4209ad9f8 Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Thu, 23 Nov 2023 17:56:53 +0200 Subject: [PATCH 17/21] Update tests --- .../apis/gtfs/mapping/RouteRequestMapperTest.java | 4 ++-- .../request/preference/VehicleParkingPreferencesTest.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/opentripplanner/apis/gtfs/mapping/RouteRequestMapperTest.java b/src/test/java/org/opentripplanner/apis/gtfs/mapping/RouteRequestMapperTest.java index 45595f3af20..fba953cd93a 100644 --- a/src/test/java/org/opentripplanner/apis/gtfs/mapping/RouteRequestMapperTest.java +++ b/src/test/java/org/opentripplanner/apis/gtfs/mapping/RouteRequestMapperTest.java @@ -215,11 +215,11 @@ private DataFetchingEnvironment executionContext(Map arguments) private void testParkingFilters(VehicleParkingPreferences parkingPreferences) { assertEquals( - "VehicleParkingFilterRequest{not: [tags=[wheelbender]], select: [tags=[locker, roof]]}", + "VehicleParkingFilter{not: [tags=[wheelbender]], select: [tags=[locker, roof]]}", parkingPreferences.filter().toString() ); assertEquals( - "VehicleParkingFilterRequest{select: [tags=[a, b]]}", + "VehicleParkingFilter{select: [tags=[a, b]]}", parkingPreferences.preferred().toString() ); assertEquals(555, parkingPreferences.unpreferredVehicleParkingTagCost().toSeconds()); diff --git a/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java b/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java index 826e738d22f..0337f5eea3b 100644 --- a/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java +++ b/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java @@ -81,9 +81,9 @@ void testToString() { assertEquals( "VehicleParkingPreferences{" + "unpreferredVehicleParkingTagCost: $360, " + - "useAvailabilityInformation: false, " + - "filter: VehicleParkingFilterRequest{not: [tags=[not]], select: [tags=[bar]]}, " + - "preferred: VehicleParkingFilterRequest{not: [tags=[bar]], select: [tags=[foo]]}, " + + "ignoreRealtimeAvailability, " + + "filter: VehicleParkingFilter{not: [tags=[not]], select: [tags=[bar]]}, " + + "preferred: VehicleParkingFilter{not: [tags=[bar]], select: [tags=[foo]]}, " + "parkCost: $240, " + "parkTime: PT2M}", subject.toString() From cb3e2733e7b3b9ea87de2f6655f85c33a3d30ed5 Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Fri, 24 Nov 2023 15:17:27 +0200 Subject: [PATCH 18/21] Add descriptions for tags --- docs/RouteRequest.md | 9 ++++++ .../routerequest/RouteRequestConfig.java | 30 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/docs/RouteRequest.md b/docs/RouteRequest.md index d813e317359..1449457f74c 100644 --- a/docs/RouteRequest.md +++ b/docs/RouteRequest.md @@ -466,6 +466,9 @@ Sometimes there is a need to configure a longer alighting times for specific mod Tags with which a vehicle parking will not be used. If empty, no tags are banned. +Vehicle parking tags can originate from different places depending on the origin of the parking(OSM or RT feed). + +

boardSlackForMode

**Since version:** `2.0` ∙ **Type:** `enum map of duration` ∙ **Cardinality:** `Optional` @@ -700,6 +703,9 @@ done because some street modes searches are much more resource intensive than ot Vehicle parking facilities that don't have one of these tags will receive an extra cost and will therefore be penalised. +Vehicle parking tags can originate from different places depending on the origin of the parking(OSM or RT feed). + +

requiredVehicleParkingTags

**Since version:** `2.1` ∙ **Type:** `string[]` ∙ **Cardinality:** `Optional` @@ -707,6 +713,9 @@ Vehicle parking facilities that don't have one of these tags will receive an ext Tags without which a vehicle parking will not be used. If empty, no tags are required. +Vehicle parking tags can originate from different places depending on the origin of the parking(OSM or RT feed). + +

transferOptimization

**Since version:** `2.1` ∙ **Type:** `object` ∙ **Cardinality:** `Optional` diff --git a/src/main/java/org/opentripplanner/standalone/config/routerequest/RouteRequestConfig.java b/src/main/java/org/opentripplanner/standalone/config/routerequest/RouteRequestConfig.java index b0488fb6542..efda12d52c7 100644 --- a/src/main/java/org/opentripplanner/standalone/config/routerequest/RouteRequestConfig.java +++ b/src/main/java/org/opentripplanner/standalone/config/routerequest/RouteRequestConfig.java @@ -435,6 +435,11 @@ private static void mapBikePreferences(NodeAdapter c, BikePreferences.Builder bu .summary( "Tags with which a vehicle parking will not be used. If empty, no tags are banned." ) + .description( + """ + Vehicle parking tags can originate from different places depending on the origin of the parking(OSM or RT feed). + """ + ) .asStringSet(List.of()) ) .withRequiredVehicleParkingTags( @@ -444,6 +449,11 @@ private static void mapBikePreferences(NodeAdapter c, BikePreferences.Builder bu .summary( "Tags without which a vehicle parking will not be used. If empty, no tags are required." ) + .description( + """ + Vehicle parking tags can originate from different places depending on the origin of the parking(OSM or RT feed). + """ + ) .asStringSet(List.of()) ) .withParkTime( @@ -467,6 +477,11 @@ private static void mapBikePreferences(NodeAdapter c, BikePreferences.Builder bu .summary( "Vehicle parking facilities that don't have one of these tags will receive an extra cost and will therefore be penalised." ) + .description( + """ + Vehicle parking tags can originate from different places depending on the origin of the parking(OSM or RT feed). + """ + ) .asStringSet(List.of()) ) ); @@ -733,6 +748,11 @@ private static void mapCarPreferences(NodeAdapter c, CarPreferences.Builder buil .summary( "Tags with which a vehicle parking will not be used. If empty, no tags are banned." ) + .description( + """ + Vehicle parking tags can originate from different places depending on the origin of the parking(OSM or RT feed). + """ + ) .asStringSet(List.of()) ) .withRequiredVehicleParkingTags( @@ -742,6 +762,11 @@ private static void mapCarPreferences(NodeAdapter c, CarPreferences.Builder buil .summary( "Tags without which a vehicle parking will not be used. If empty, no tags are required." ) + .description( + """ + Vehicle parking tags can originate from different places depending on the origin of the parking(OSM or RT feed). + """ + ) .asStringSet(List.of()) ) .withParkCost( @@ -765,6 +790,11 @@ private static void mapCarPreferences(NodeAdapter c, CarPreferences.Builder buil .summary( "Vehicle parking facilities that don't have one of these tags will receive an extra cost and will therefore be penalised." ) + .description( + """ + Vehicle parking tags can originate from different places depending on the origin of the parking(OSM or RT feed). + """ + ) .asStringSet(List.of()) ) ); From 9569d93b051ba27de1f844e917b64b766eda663b Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Fri, 24 Nov 2023 16:07:23 +0200 Subject: [PATCH 19/21] Change params --- .../street/model/edge/VehicleParkingEdge.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java b/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java index e4352821115..6178541656f 100644 --- a/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java +++ b/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java @@ -157,21 +157,21 @@ private State[] traversePark(State s0) { return traversePark( s0, - preferences.bike().parking().parkCost().toSeconds(), - (int) preferences.bike().parking().parkTime().toSeconds() + preferences.bike().parking().parkCost(), + preferences.bike().parking().parkTime() ); } else if (streetMode.includesDriving()) { return traversePark( s0, - preferences.car().parking().parkCost().toSeconds(), - (int) preferences.car().parking().parkTime().toSeconds() + preferences.car().parking().parkCost(), + preferences.car().parking().parkTime() ); } else { return State.empty(); } } - private State[] traversePark(State s0, int parkingCost, int parkingTime) { + private State[] traversePark(State s0, Cost parkingCost, Duration parkingTime) { var parkingPreferences = s0.getRequest().preferences().parking(s0.currentMode()); if ( !vehicleParking.hasSpacesAvailable( @@ -184,8 +184,8 @@ private State[] traversePark(State s0, int parkingCost, int parkingTime) { } StateEditor s0e = s0.edit(this); - s0e.incrementWeight(parkingCost); - s0e.incrementTimeInSeconds(parkingTime); + s0e.incrementWeight(parkingCost.toSeconds()); + s0e.incrementTimeInSeconds((int) parkingTime.toSeconds()); s0e.setVehicleParked(true, TraverseMode.WALK); addUnpreferredTagCost(parkingPreferences, s0e); From 2d540f8cbd4d0de0c369226d9e27675851f6d7e9 Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Mon, 11 Dec 2023 15:45:13 +0200 Subject: [PATCH 20/21] Remove support for using realtime availability in parking routing --- .../common/RequestToPreferencesMapper.java | 6 -- .../api/common/RoutingResource.java | 4 ++ .../org/opentripplanner/model/plan/Place.java | 8 +-- .../preference/VehicleParkingPreferences.java | 28 +-------- .../vehicle_parking/VehicleParking.java | 24 ++------ .../street/model/edge/VehicleParkingEdge.java | 20 ++----- .../VehicleParkingPreferencesTest.java | 9 --- .../model/edge/VehicleParkingEdgeTest.java | 59 +++---------------- 8 files changed, 23 insertions(+), 135 deletions(-) diff --git a/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java b/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java index 6bcd9490d98..211c0a989cf 100644 --- a/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java +++ b/src/main/java/org/opentripplanner/api/common/RequestToPreferencesMapper.java @@ -168,12 +168,6 @@ private TransitGeneralizedCostFilterParams mapTransitGeneralizedCostFilterParams } private void mapParking(VehicleParkingPreferences.Builder builder) { - setIfNotNull( - req.useVehicleParkingAvailabilityInformation, - useVehicleParkingAvailabilityInformation -> - builder.withIgnoreRealtimeAvailability(!useVehicleParkingAvailabilityInformation) - ); - builder.withRequiredVehicleParkingTags(req.requiredVehicleParkingTags); builder.withBannedVehicleParkingTags(req.bannedVehicleParkingTags); } diff --git a/src/main/java/org/opentripplanner/api/common/RoutingResource.java b/src/main/java/org/opentripplanner/api/common/RoutingResource.java index 143e99d2e93..34f162010bb 100644 --- a/src/main/java/org/opentripplanner/api/common/RoutingResource.java +++ b/src/main/java/org/opentripplanner/api/common/RoutingResource.java @@ -651,6 +651,10 @@ public abstract class RoutingResource { @QueryParam("geoidElevation") protected Boolean geoidElevation; + /** + * @deprecated Support has been removed. + */ + @Deprecated @QueryParam("useVehicleParkingAvailabilityInformation") protected Boolean useVehicleParkingAvailabilityInformation; diff --git a/src/main/java/org/opentripplanner/model/plan/Place.java b/src/main/java/org/opentripplanner/model/plan/Place.java index efdde16899a..fe3a9dee420 100644 --- a/src/main/java/org/opentripplanner/model/plan/Place.java +++ b/src/main/java/org/opentripplanner/model/plan/Place.java @@ -135,11 +135,9 @@ public static Place forVehicleParkingEntrance(VehicleParkingEntranceVertex verte traverseMode = TraverseMode.BICYCLE; } - var parkingPreferences = request.preferences().parking(traverseMode); - - boolean realTime = - !parkingPreferences.ignoreRealtimeAvailability() && - vertex.getVehicleParking().hasRealTimeDataForMode(traverseMode, request.wheelchair()); + boolean realTime = vertex + .getVehicleParking() + .hasRealTimeDataForMode(traverseMode, request.wheelchair()); return new Place( vertex.getName(), WgsCoordinate.creatOptionalCoordinate(vertex.getLat(), vertex.getLon()), diff --git a/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java b/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java index 166b5a25c85..c6e97e180a7 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java +++ b/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java @@ -20,7 +20,6 @@ public final class VehicleParkingPreferences implements Serializable { public static final VehicleParkingPreferences DEFAULT = new VehicleParkingPreferences(); private final Cost unpreferredVehicleParkingTagCost; - private final boolean ignoreRealtimeAvailability; private final VehicleParkingFilter filter; private final VehicleParkingFilter preferred; private final Duration parkTime; @@ -29,7 +28,6 @@ public final class VehicleParkingPreferences implements Serializable { /** Create a new instance with default values. */ private VehicleParkingPreferences() { this.unpreferredVehicleParkingTagCost = Cost.costOfMinutes(5); - this.ignoreRealtimeAvailability = false; this.filter = VehicleParkingFilter.empty(); this.preferred = VehicleParkingFilter.empty(); this.parkTime = Duration.ofMinutes(1); @@ -38,7 +36,6 @@ private VehicleParkingPreferences() { private VehicleParkingPreferences(Builder builder) { this.unpreferredVehicleParkingTagCost = builder.unpreferredVehicleParkingTagCost; - this.ignoreRealtimeAvailability = builder.ignoreRealtimeAvailability; this.filter = new VehicleParkingFilter( builder.bannedVehicleParkingTags, @@ -64,13 +61,6 @@ public Cost unpreferredVehicleParkingTagCost() { return unpreferredVehicleParkingTagCost; } - /** - * Should availability information be used during routing. - */ - public boolean ignoreRealtimeAvailability() { - return ignoreRealtimeAvailability; - } - /** * Parking containing select filters must only be usable and parking containing with not filters * cannot be used. @@ -106,7 +96,6 @@ public boolean equals(Object o) { VehicleParkingPreferences that = (VehicleParkingPreferences) o; return ( Objects.equals(unpreferredVehicleParkingTagCost, that.unpreferredVehicleParkingTagCost) && - ignoreRealtimeAvailability == that.ignoreRealtimeAvailability && Objects.equals(filter, that.filter) && Objects.equals(preferred, that.preferred) && Objects.equals(parkCost, that.parkCost) && @@ -116,14 +105,7 @@ public boolean equals(Object o) { @Override public int hashCode() { - return Objects.hash( - unpreferredVehicleParkingTagCost, - ignoreRealtimeAvailability, - filter, - preferred, - parkCost, - parkTime - ); + return Objects.hash(unpreferredVehicleParkingTagCost, filter, preferred, parkCost, parkTime); } @Override @@ -135,7 +117,6 @@ public String toString() { unpreferredVehicleParkingTagCost, DEFAULT.unpreferredVehicleParkingTagCost ) - .addBoolIfTrue("ignoreRealtimeAvailability", ignoreRealtimeAvailability) .addObj("filter", filter, DEFAULT.filter) .addObj("preferred", preferred, DEFAULT.preferred) .addObj("parkCost", parkCost, DEFAULT.parkCost) @@ -147,7 +128,6 @@ public static class Builder { private final VehicleParkingPreferences original; private Cost unpreferredVehicleParkingTagCost; - private boolean ignoreRealtimeAvailability; private List bannedVehicleParkingTags; private List requiredVehicleParkingTags; private List preferredVehicleParkingTags; @@ -158,7 +138,6 @@ public static class Builder { private Builder(VehicleParkingPreferences original) { this.original = original; this.unpreferredVehicleParkingTagCost = original.unpreferredVehicleParkingTagCost; - this.ignoreRealtimeAvailability = original.ignoreRealtimeAvailability; this.bannedVehicleParkingTags = original.filter.not(); this.requiredVehicleParkingTags = original.filter.select(); this.preferredVehicleParkingTags = original.preferred.select(); @@ -172,11 +151,6 @@ public Builder withUnpreferredVehicleParkingTagCost(int cost) { return this; } - public Builder withIgnoreRealtimeAvailability(boolean ignoreRealtimeAvailability) { - this.ignoreRealtimeAvailability = ignoreRealtimeAvailability; - return this; - } - public Builder withBannedVehicleParkingTags(Set bannedVehicleParkingTags) { this.bannedVehicleParkingTags = List.of(new VehicleParkingSelect.TagsSelect(bannedVehicleParkingTags)); diff --git a/src/main/java/org/opentripplanner/routing/vehicle_parking/VehicleParking.java b/src/main/java/org/opentripplanner/routing/vehicle_parking/VehicleParking.java index b4a8eee17b3..e5b0fd083dc 100644 --- a/src/main/java/org/opentripplanner/routing/vehicle_parking/VehicleParking.java +++ b/src/main/java/org/opentripplanner/routing/vehicle_parking/VehicleParking.java @@ -215,31 +215,15 @@ public boolean hasRealTimeData() { return availability != null; } - public boolean hasSpacesAvailable( - TraverseMode traverseMode, - boolean wheelchairAccessible, - boolean ignoreRealtimeAvailability - ) { + public boolean hasSpacesAvailable(TraverseMode traverseMode, boolean wheelchairAccessible) { switch (traverseMode) { case BICYCLE: - if (!ignoreRealtimeAvailability && hasRealTimeDataForMode(TraverseMode.BICYCLE, false)) { - return availability.getBicycleSpaces() > 0; - } else { - return bicyclePlaces; - } + return bicyclePlaces; case CAR: if (wheelchairAccessible) { - if (!ignoreRealtimeAvailability && hasRealTimeDataForMode(TraverseMode.CAR, true)) { - return availability.getWheelchairAccessibleCarSpaces() > 0; - } else { - return wheelchairAccessibleCarPlaces; - } + return wheelchairAccessibleCarPlaces; } else { - if (!ignoreRealtimeAvailability && hasRealTimeDataForMode(TraverseMode.CAR, false)) { - return availability.getCarSpaces() > 0; - } else { - return carPlaces; - } + return carPlaces; } default: return false; diff --git a/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java b/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java index 6178541656f..be909c1dc4c 100644 --- a/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java +++ b/src/main/java/org/opentripplanner/street/model/edge/VehicleParkingEdge.java @@ -120,14 +120,7 @@ private State[] traverseUnPark( TraverseMode mode ) { final StreetSearchRequest request = s0.getRequest(); - var parkingPreferences = s0.getRequest().preferences().parking(s0.currentMode()); - if ( - !vehicleParking.hasSpacesAvailable( - mode, - request.wheelchair(), - parkingPreferences.ignoreRealtimeAvailability() - ) - ) { + if (!vehicleParking.hasSpacesAvailable(mode, request.wheelchair())) { return State.empty(); } @@ -136,6 +129,7 @@ private State[] traverseUnPark( s0e.incrementTimeInSeconds((int) parkingTime.toSeconds()); s0e.setVehicleParked(false, mode); + var parkingPreferences = s0.getRequest().preferences().parking(s0.currentMode()); addUnpreferredTagCost(parkingPreferences, s0e); return s0e.makeStateArray(); @@ -172,14 +166,7 @@ private State[] traversePark(State s0) { } private State[] traversePark(State s0, Cost parkingCost, Duration parkingTime) { - var parkingPreferences = s0.getRequest().preferences().parking(s0.currentMode()); - if ( - !vehicleParking.hasSpacesAvailable( - s0.currentMode(), - s0.getRequest().wheelchair(), - parkingPreferences.ignoreRealtimeAvailability() - ) - ) { + if (!vehicleParking.hasSpacesAvailable(s0.currentMode(), s0.getRequest().wheelchair())) { return State.empty(); } @@ -188,6 +175,7 @@ private State[] traversePark(State s0, Cost parkingCost, Duration parkingTime) { s0e.incrementTimeInSeconds((int) parkingTime.toSeconds()); s0e.setVehicleParked(true, TraverseMode.WALK); + var parkingPreferences = s0.getRequest().preferences().parking(s0.currentMode()); addUnpreferredTagCost(parkingPreferences, s0e); return s0e.makeStateArray(); diff --git a/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java b/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java index 0337f5eea3b..85ce30b8561 100644 --- a/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java +++ b/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java @@ -14,7 +14,6 @@ class VehicleParkingPreferencesTest { private static final Set PREFERRED_TAGS = Set.of("foo"); private static final Set NOT_PREFERRED_TAGS = Set.of("bar"); private static final int UNPREFERRED_COST = 360; - private static final boolean IGNORE_REALTIME = true; private static final Set REQUIRED_TAGS = Set.of("bar"); private static final Set BANNED_TAGS = Set.of("not"); private static final Cost PARKING_COST = Cost.costOfMinutes(4); @@ -39,11 +38,6 @@ void unpreferredCost() { assertEquals(UNPREFERRED_COST, subject.unpreferredVehicleParkingTagCost().toSeconds()); } - @Test - void useAvailabilityInformation() { - assertEquals(IGNORE_REALTIME, subject.ignoreRealtimeAvailability()); - } - @Test void parkCost() { assertEquals(PARKING_COST, subject.parkCost()); @@ -65,7 +59,6 @@ void testEqualsAndHashCode() { .withPreferredVehicleParkingTags(Set.of()) .withNotPreferredVehicleParkingTags(Set.of()) .withUnpreferredVehicleParkingTagCost(0) - .withIgnoreRealtimeAvailability(false) .withRequiredVehicleParkingTags(Set.of()) .withBannedVehicleParkingTags(Set.of()) .withParkCost(0) @@ -81,7 +74,6 @@ void testToString() { assertEquals( "VehicleParkingPreferences{" + "unpreferredVehicleParkingTagCost: $360, " + - "ignoreRealtimeAvailability, " + "filter: VehicleParkingFilter{not: [tags=[not]], select: [tags=[bar]]}, " + "preferred: VehicleParkingFilter{not: [tags=[bar]], select: [tags=[foo]]}, " + "parkCost: $240, " + @@ -100,7 +92,6 @@ private VehicleParkingPreferences createPreferences() { .withPreferredVehicleParkingTags(PREFERRED_TAGS) .withNotPreferredVehicleParkingTags(NOT_PREFERRED_TAGS) .withUnpreferredVehicleParkingTagCost(UNPREFERRED_COST) - .withIgnoreRealtimeAvailability(IGNORE_REALTIME) .withRequiredVehicleParkingTags(REQUIRED_TAGS) .withBannedVehicleParkingTags(BANNED_TAGS) .withParkCost(PARKING_COST.toSeconds()) diff --git a/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingEdgeTest.java b/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingEdgeTest.java index 919f141a1be..7dad61fbd6b 100644 --- a/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingEdgeTest.java +++ b/src/test/java/org/opentripplanner/street/model/edge/VehicleParkingEdgeTest.java @@ -45,8 +45,7 @@ public void realtimeAvailableCarPlacesTest() { StreetMode.CAR_TO_PARK, false, true, - VehicleParkingSpaces.builder().carSpaces(1).build(), - false + VehicleParkingSpaces.builder().carSpaces(1).build() ); var s1 = traverse(); @@ -56,28 +55,13 @@ public void realtimeAvailableCarPlacesTest() { @Test public void realtimeAvailableCarPlacesFallbackTest() { - initEdgeAndRequest(StreetMode.CAR_TO_PARK, false, true, null, false); + initEdgeAndRequest(StreetMode.CAR_TO_PARK, false, true, null); var s1 = traverse(); assertFalse(State.isEmpty(s1)); } - @Test - public void realtimeNotAvailableCarPlacesTest() { - initEdgeAndRequest( - StreetMode.CAR_TO_PARK, - false, - true, - VehicleParkingSpaces.builder().carSpaces(0).build(), - false - ); - - var s1 = traverse(); - - assertTrue(State.isEmpty(s1)); - } - @Test public void availableBicyclePlacesTest() { initEdgeAndRequest(StreetMode.BIKE_TO_PARK, true, false); @@ -102,8 +86,7 @@ public void realtimeAvailableBicyclePlacesTest() { StreetMode.BIKE_TO_PARK, true, false, - VehicleParkingSpaces.builder().bicycleSpaces(1).build(), - false + VehicleParkingSpaces.builder().bicycleSpaces(1).build() ); var s1 = traverse(); @@ -113,61 +96,33 @@ public void realtimeAvailableBicyclePlacesTest() { @Test public void realtimeAvailableBicyclePlacesFallbackTest() { - initEdgeAndRequest(StreetMode.BIKE_TO_PARK, true, false, null, false); + initEdgeAndRequest(StreetMode.BIKE_TO_PARK, true, false, null); var s1 = traverse(); assertFalse(State.isEmpty(s1)); } - @Test - public void realtimeNotAvailableBicyclePlacesTest() { - initEdgeAndRequest( - StreetMode.BIKE_TO_PARK, - true, - false, - VehicleParkingSpaces.builder().bicycleSpaces(0).build(), - false - ); - - var s1 = traverse(); - - assertTrue(State.isEmpty(s1)); - } - private void initEdgeAndRequest( StreetMode parkingMode, boolean bicyclePlaces, boolean carPlaces ) { - initEdgeAndRequest(parkingMode, bicyclePlaces, carPlaces, null, true); + initEdgeAndRequest(parkingMode, bicyclePlaces, carPlaces, null); } private void initEdgeAndRequest( StreetMode parkingMode, boolean bicyclePlaces, boolean carPlaces, - VehicleParkingSpaces availability, - boolean ignoreRealtime + VehicleParkingSpaces availability ) { var vehicleParking = createVehicleParking(bicyclePlaces, carPlaces, availability); this.vertex = new VehicleParkingEntranceVertex(vehicleParking.getEntrances().get(0)); vehicleParkingEdge = VehicleParkingEdge.createVehicleParkingEdge(vertex); - this.request = - StreetSearchRequest - .of() - .withMode(parkingMode) - .withPreferences(preferences -> { - preferences.withBike(bike -> - bike.withParking(parking -> parking.withIgnoreRealtimeAvailability(ignoreRealtime)) - ); - preferences.withCar(car -> - car.withParking(parking -> parking.withIgnoreRealtimeAvailability(ignoreRealtime)) - ); - }) - .build(); + this.request = StreetSearchRequest.of().withMode(parkingMode).build(); } private VehicleParking createVehicleParking( From 3d98683489a55e09b3b44cb6eeac5a6fa0229f90 Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Mon, 11 Dec 2023 16:07:50 +0200 Subject: [PATCH 21/21] Fix preference modification --- .../request/preference/BikePreferences.java | 5 ++--- .../request/preference/CarPreferences.java | 6 +++--- .../preference/VehicleParkingPreferences.java | 10 +++++++++ .../VehicleParkingPreferencesTest.java | 21 ++++--------------- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/opentripplanner/routing/api/request/preference/BikePreferences.java b/src/main/java/org/opentripplanner/routing/api/request/preference/BikePreferences.java index ab4e03e2cad..115e1264036 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/preference/BikePreferences.java +++ b/src/main/java/org/opentripplanner/routing/api/request/preference/BikePreferences.java @@ -1,6 +1,7 @@ package org.opentripplanner.routing.api.request.preference; import static org.opentripplanner.framework.lang.DoubleUtils.doubleEquals; +import static org.opentripplanner.framework.lang.ObjectUtils.ifNotNull; import java.io.Serializable; import java.util.Objects; @@ -294,9 +295,7 @@ public Builder withSwitchCost(int switchCost) { } public Builder withParking(Consumer body) { - var builder = VehicleParkingPreferences.of(); - body.accept(builder); - this.parking = builder.build(); + this.parking = ifNotNull(this.parking, original.parking).copyOf().apply(body).build(); return this; } diff --git a/src/main/java/org/opentripplanner/routing/api/request/preference/CarPreferences.java b/src/main/java/org/opentripplanner/routing/api/request/preference/CarPreferences.java index 11ccf26c4b6..523e19afb70 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/preference/CarPreferences.java +++ b/src/main/java/org/opentripplanner/routing/api/request/preference/CarPreferences.java @@ -1,5 +1,7 @@ package org.opentripplanner.routing.api.request.preference; +import static org.opentripplanner.framework.lang.ObjectUtils.ifNotNull; + import java.io.Serializable; import java.util.Objects; import java.util.function.Consumer; @@ -197,9 +199,7 @@ public Builder withReluctance(double reluctance) { } public Builder withParking(Consumer body) { - var builder = VehicleParkingPreferences.of(); - body.accept(builder); - this.parking = builder.build(); + this.parking = ifNotNull(this.parking, original.parking).copyOf().apply(body).build(); return this; } diff --git a/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java b/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java index c6e97e180a7..c02862c4d79 100644 --- a/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java +++ b/src/main/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferences.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Objects; import java.util.Set; +import java.util.function.Consumer; import org.opentripplanner.framework.model.Cost; import org.opentripplanner.framework.tostring.ToStringBuilder; import org.opentripplanner.routing.api.request.preference.filter.VehicleParkingFilter; @@ -54,6 +55,10 @@ public static VehicleParkingPreferences.Builder of() { return new Builder(DEFAULT); } + public VehicleParkingPreferences.Builder copyOf() { + return new Builder(this); + } + /** * What cost is applied to using parking that is not preferred. */ @@ -190,6 +195,11 @@ public Builder withParkTime(Duration duration) { return this; } + public Builder apply(Consumer body) { + body.accept(this); + return this; + } + public VehicleParkingPreferences build() { var newObj = new VehicleParkingPreferences(this); return original.equals(newObj) ? original : newObj; diff --git a/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java b/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java index 85ce30b8561..35666b53f9f 100644 --- a/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java +++ b/src/test/java/org/opentripplanner/routing/api/request/preference/VehicleParkingPreferencesTest.java @@ -1,7 +1,6 @@ package org.opentripplanner.routing.api.request.preference; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertSame; import static org.opentripplanner.routing.api.request.preference.ImmutablePreferencesAsserts.assertEqualsAndHashCode; import java.time.Duration; @@ -49,22 +48,10 @@ void parkTime() { } @Test - void testEqualsAndHashCode() { - // Return same object if no value is set - assertSame(VehicleParkingPreferences.DEFAULT, VehicleParkingPreferences.of().build()); - - // Create other with different values and same with the same values as the subject - var other = VehicleParkingPreferences - .of() - .withPreferredVehicleParkingTags(Set.of()) - .withNotPreferredVehicleParkingTags(Set.of()) - .withUnpreferredVehicleParkingTagCost(0) - .withRequiredVehicleParkingTags(Set.of()) - .withBannedVehicleParkingTags(Set.of()) - .withParkCost(0) - .withParkTime(0) - .build(); - var same = createPreferences(); + void testCopyOfEqualsAndHashCode() { + // Create a copy, make a change and set it back again to force creating a new object + var other = subject.copyOf().withParkCost(10).build(); + var same = other.copyOf().withParkCost(PARKING_COST.toSeconds()).build(); assertEqualsAndHashCode(subject, other, same); }