diff --git a/application/src/ext-test/java/org/opentripplanner/ext/fares/impl/OrcaFareServiceTest.java b/application/src/ext-test/java/org/opentripplanner/ext/fares/impl/OrcaFareServiceTest.java index c819d4abc2ec..89ea6b22dbc8 100644 --- a/application/src/ext-test/java/org/opentripplanner/ext/fares/impl/OrcaFareServiceTest.java +++ b/application/src/ext-test/java/org/opentripplanner/ext/fares/impl/OrcaFareServiceTest.java @@ -226,12 +226,12 @@ void calculateFareThatIncludesNoFreeTransfers() { ); calculateFare(rides, FareType.youth, Money.ZERO_USD); // We don't get any fares for the skagit transit leg below here because they don't accept ORCA (electronic) - calculateFare(rides, FareType.electronicSpecial, ONE_DOLLAR.plus(ONE_DOLLAR).plus(DEFAULT_TEST_RIDE_PRICE.times(2))); calculateFare( rides, - FareType.electronicRegular, - DEFAULT_TEST_RIDE_PRICE.times(4) + FareType.electronicSpecial, + ONE_DOLLAR.plus(ONE_DOLLAR).plus(DEFAULT_TEST_RIDE_PRICE.times(2)) ); + calculateFare(rides, FareType.electronicRegular, DEFAULT_TEST_RIDE_PRICE.times(4)); calculateFare( rides, FareType.electronicSenior, diff --git a/application/src/ext-test/java/org/opentripplanner/ext/flex/FlexStopTimesForTest.java b/application/src/ext-test/java/org/opentripplanner/ext/flex/FlexStopTimesForTest.java index b67ae85a4346..9cff9177e2e3 100644 --- a/application/src/ext-test/java/org/opentripplanner/ext/flex/FlexStopTimesForTest.java +++ b/application/src/ext-test/java/org/opentripplanner/ext/flex/FlexStopTimesForTest.java @@ -96,7 +96,4 @@ public static StopTime regularStop(int arrivalTime, int departureTime) { stopTime.setTrip(TRIP); return stopTime; } - - - } diff --git a/application/src/ext-test/java/org/opentripplanner/ext/flex/trip/ScheduledDeviatedTripTest.java b/application/src/ext-test/java/org/opentripplanner/ext/flex/trip/ScheduledDeviatedTripTest.java index 4beefeb271e7..5adf8c7264aa 100644 --- a/application/src/ext-test/java/org/opentripplanner/ext/flex/trip/ScheduledDeviatedTripTest.java +++ b/application/src/ext-test/java/org/opentripplanner/ext/flex/trip/ScheduledDeviatedTripTest.java @@ -45,10 +45,7 @@ private static List> isNotScheduledDeviatedTripCases() { areaWithContinuousStopping("10:40"), regularStop("10:50", "11:00") ), - List.of( - regularStop("10:10"), - regularStop("10:20") - ) + List.of(regularStop("10:10"), regularStop("10:20")) ); } @@ -57,6 +54,4 @@ private static List> isNotScheduledDeviatedTripCases() { void isNotScheduledDeviatedTrip(List stopTimes) { assertFalse(ScheduledDeviatedTrip.isScheduledDeviatedFlexTrip(stopTimes)); } - - -} \ No newline at end of file +} diff --git a/application/src/ext-test/java/org/opentripplanner/ext/flex/trip/UnscheduledTripTest.java b/application/src/ext-test/java/org/opentripplanner/ext/flex/trip/UnscheduledTripTest.java index b7f2706d25ac..6ce964045ab8 100644 --- a/application/src/ext-test/java/org/opentripplanner/ext/flex/trip/UnscheduledTripTest.java +++ b/application/src/ext-test/java/org/opentripplanner/ext/flex/trip/UnscheduledTripTest.java @@ -48,12 +48,20 @@ class IsUnscheduledTrip { private static final StopTime SCHEDULED_STOP = FlexStopTimesForTest.regularStop("10:00"); private static final StopTime UNSCHEDULED_STOP = FlexStopTimesForTest.area("10:10", "10:20"); - private static final StopTime CONTINUOUS_PICKUP_STOP = FlexStopTimesForTest.regularStopWithContinuousPickup("10:30"); - private static final StopTime CONTINUOUS_DROP_OFF_STOP = FlexStopTimesForTest.regularStopWithContinuousDropOff("10:40"); + private static final StopTime CONTINUOUS_PICKUP_STOP = FlexStopTimesForTest.regularStopWithContinuousPickup( + "10:30" + ); + private static final StopTime CONTINUOUS_DROP_OFF_STOP = FlexStopTimesForTest.regularStopWithContinuousDropOff( + "10:40" + ); // disallowed by the GTFS spec - private static final StopTime FLEX_AND_CONTINUOUS_PICKUP_STOP = FlexStopTimesForTest.areaWithContinuousPickup("10:50"); - private static final StopTime FLEX_AND_CONTINUOUS_DROP_OFF_STOP = FlexStopTimesForTest.areaWithContinuousDropOff("11:00"); + private static final StopTime FLEX_AND_CONTINUOUS_PICKUP_STOP = FlexStopTimesForTest.areaWithContinuousPickup( + "10:50" + ); + private static final StopTime FLEX_AND_CONTINUOUS_DROP_OFF_STOP = FlexStopTimesForTest.areaWithContinuousDropOff( + "11:00" + ); static List> notUnscheduled() { return List.of( diff --git a/application/src/ext-test/java/org/opentripplanner/ext/restapi/mapping/EnumMapperTest.java b/application/src/ext-test/java/org/opentripplanner/ext/restapi/mapping/EnumMapperTest.java index 5b03ada1c1f1..151c1759a256 100644 --- a/application/src/ext-test/java/org/opentripplanner/ext/restapi/mapping/EnumMapperTest.java +++ b/application/src/ext-test/java/org/opentripplanner/ext/restapi/mapping/EnumMapperTest.java @@ -46,5 +46,4 @@ private , A extends Enum> void verifyExplicitMatch( } assertTrue(rest.isEmpty()); } - } diff --git a/application/src/ext-test/java/org/opentripplanner/ext/siri/updater/azure/AbstractAzureSiriUpdaterTest.java b/application/src/ext-test/java/org/opentripplanner/ext/siri/updater/azure/AbstractAzureSiriUpdaterTest.java index f4cfa8ceb800..c0336bb6d7d0 100644 --- a/application/src/ext-test/java/org/opentripplanner/ext/siri/updater/azure/AbstractAzureSiriUpdaterTest.java +++ b/application/src/ext-test/java/org/opentripplanner/ext/siri/updater/azure/AbstractAzureSiriUpdaterTest.java @@ -1,9 +1,9 @@ package org.opentripplanner.ext.siri.updater.azure; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.mockito.Mockito.*; import com.azure.core.util.ExpandableStringEnum; @@ -56,21 +56,22 @@ public void setUp() throws Exception { when(mockConfig.isFuzzyTripMatching()).thenReturn(true); // Create a spy on AbstractAzureSiriUpdater with the mock configuration - updater = spy(new AbstractAzureSiriUpdater(mockConfig) { - @Override - protected void messageConsumer(ServiceBusReceivedMessageContext messageContext) { - } - - @Override - protected void errorConsumer(ServiceBusErrorContext errorContext) { - } - - @Override - protected void initializeData(String url, - Consumer consumer - ) throws URISyntaxException { - } - }); + updater = + spy( + new AbstractAzureSiriUpdater(mockConfig) { + @Override + protected void messageConsumer(ServiceBusReceivedMessageContext messageContext) {} + + @Override + protected void errorConsumer(ServiceBusErrorContext errorContext) {} + + @Override + protected void initializeData( + String url, + Consumer consumer + ) throws URISyntaxException {} + } + ); task = mock(AbstractAzureSiriUpdater.CheckedRunnable.class); } @@ -81,8 +82,8 @@ protected void initializeData(String url, */ @Test void testExecuteWithRetry_FullBackoffSequence() throws Throwable { - final int totalRunCalls = 10; // 9 failures + 1 success - final int totalSleepCalls = 9; // 9 retries + final int totalRunCalls = 10; // 9 failures + 1 success + final int totalSleepCalls = 9; // 9 retries doNothing().when(updater).sleep(anyInt()); @@ -97,7 +98,8 @@ void testExecuteWithRetry_FullBackoffSequence() throws Throwable { .doThrow(createServiceBusException(ServiceBusFailureReason.SERVICE_BUSY)) .doThrow(createServiceBusException(ServiceBusFailureReason.SERVICE_BUSY)) .doNothing() // Succeed on the 10th attempt - .when(task).run(); + .when(task) + .run(); updater.executeWithRetry(task, "Test Task"); @@ -126,14 +128,20 @@ void testExecuteWithRetry_FullBackoffSequence() throws Throwable { public void testExecuteWithRetry_NonRetryableException() throws Throwable { doNothing().when(updater).sleep(anyInt()); - ServiceBusException serviceBusException = createServiceBusException(ServiceBusFailureReason.MESSAGE_SIZE_EXCEEDED); + ServiceBusException serviceBusException = createServiceBusException( + ServiceBusFailureReason.MESSAGE_SIZE_EXCEEDED + ); doThrow(serviceBusException).when(task).run(); try { updater.executeWithRetry(task, "Test Task"); } catch (ServiceBusException e) { - assertEquals(ServiceBusFailureReason.MESSAGE_SIZE_EXCEEDED, e.getReason(), "Exception should have reason MESSAGE_SIZE_EXCEEDED"); + assertEquals( + ServiceBusFailureReason.MESSAGE_SIZE_EXCEEDED, + e.getReason(), + "Exception should have reason MESSAGE_SIZE_EXCEEDED" + ); } verify(updater, never()).sleep(anyInt()); @@ -153,12 +161,15 @@ public void testExecuteWithRetry_MultipleRetriesThenSuccess() throws Throwable { .doThrow(createServiceBusException(ServiceBusFailureReason.SERVICE_BUSY)) .doThrow(createServiceBusException(ServiceBusFailureReason.SERVICE_BUSY)) .doNothing() - .when(task).run(); + .when(task) + .run(); doAnswer(invocation -> { - latch.countDown(); - return null; - }).when(updater).sleep(anyInt()); + latch.countDown(); + return null; + }) + .when(updater) + .sleep(anyInt()); updater.executeWithRetry(task, "Test Task"); @@ -169,11 +180,14 @@ public void testExecuteWithRetry_MultipleRetriesThenSuccess() throws Throwable { verify(updater, times(retriesBeforeSuccess)).sleep(sleepCaptor.capture()); var sleepDurations = sleepCaptor.getAllValues(); - long[] expectedBackoffSequence = {1000, 2000, 4000}; + long[] expectedBackoffSequence = { 1000, 2000, 4000 }; for (int i = 0; i < expectedBackoffSequence.length; i++) { - assertEquals(expectedBackoffSequence[i], Long.valueOf(sleepDurations.get(i)), - "Backoff duration mismatch at retry " + (i + 1)); + assertEquals( + expectedBackoffSequence[i], + Long.valueOf(sleepDurations.get(i)), + "Backoff duration mismatch at retry " + (i + 1) + ); } verify(task, times(retriesBeforeSuccess + 1)).run(); @@ -205,14 +219,17 @@ public void testExecuteWithRetry_OneRetryThenSuccess() throws Throwable { doThrow(createServiceBusException(ServiceBusFailureReason.SERVICE_BUSY)) .doNothing() - .when(task).run(); + .when(task) + .run(); doAnswer(invocation -> { - if (invocation.getArgument(0).equals(1000)) { - latch.countDown(); - } - return null; - }).when(updater).sleep(anyInt()); + if (invocation.getArgument(0).equals(1000)) { + latch.countDown(); + } + return null; + }) + .when(updater) + .sleep(anyInt()); updater.executeWithRetry(task, "Test Task"); @@ -232,10 +249,17 @@ public void testExecuteWithRetry_OneRetryThenSuccess() throws Throwable { @ParameterizedTest(name = "shouldRetry with reason {0} should return {1}") @MethodSource("provideServiceBusFailureReasons") @DisplayName("Test shouldRetry for all ServiceBusFailureReason values") - void testShouldRetry_ServiceBusFailureReasons(ServiceBusFailureReason reason, boolean expectedRetry) throws Exception { + void testShouldRetry_ServiceBusFailureReasons( + ServiceBusFailureReason reason, + boolean expectedRetry + ) throws Exception { ServiceBusException serviceBusException = createServiceBusException(reason); boolean result = updater.shouldRetry(serviceBusException); - assertEquals(expectedRetry, result, "shouldRetry should return " + expectedRetry + " for reason " + reason); + assertEquals( + expectedRetry, + result, + "shouldRetry should return " + expectedRetry + " for reason " + reason + ); } /** @@ -258,7 +282,11 @@ public void testShouldRetry_NonServiceBusException() { public void testShouldRetry_CoversAllReasons() { long enumCount = getExpandableStringEnumValues(ServiceBusFailureReason.class).size(); long testCaseCount = provideServiceBusFailureReasons().count(); - assertEquals(enumCount, testCaseCount, "All ServiceBusFailureReason values should be covered by tests."); + assertEquals( + enumCount, + testCaseCount, + "All ServiceBusFailureReason values should be covered by tests." + ); } @Test @@ -268,15 +296,24 @@ void testExecuteWithRetry_InterruptedException() throws Throwable { doThrow(createServiceBusException(ServiceBusFailureReason.SERVICE_BUSY)) .doThrow(new InterruptedException("Sleep interrupted")) - .when(task).run(); + .when(task) + .run(); doNothing().when(updater).sleep(1000); - InterruptedException thrownException = assertThrows(InterruptedException.class, () -> { - updater.executeWithRetry(task, "Test Task"); - }, "Expected executeWithRetry to throw InterruptedException"); + InterruptedException thrownException = assertThrows( + InterruptedException.class, + () -> { + updater.executeWithRetry(task, "Test Task"); + }, + "Expected executeWithRetry to throw InterruptedException" + ); - assertEquals("Sleep interrupted", thrownException.getMessage(), "Exception message should match"); + assertEquals( + "Sleep interrupted", + thrownException.getMessage(), + "Exception message should match" + ); verify(updater, times(expectedSleepCalls)).sleep(1000); verify(task, times(expectedRunCalls)).run(); assertTrue(Thread.currentThread().isInterrupted(), "Thread should be interrupted"); @@ -291,7 +328,8 @@ void testExecuteWithRetry_OtpHttpClientException() throws Throwable { .doThrow(new OtpHttpClientException("could not get historical data")) .doThrow(new OtpHttpClientException("could not get historical data")) .doNothing() - .when(task).run(); + .when(task) + .run(); doNothing().when(updater).sleep(anyInt()); @@ -304,8 +342,11 @@ void testExecuteWithRetry_OtpHttpClientException() throws Throwable { List expectedBackoffSequence = Arrays.asList(1000, 2000, 4000); for (int i = 0; i < retryAttempts; i++) { - assertEquals(expectedBackoffSequence.get(i), sleepDurations.get(i), - "Backoff duration mismatch at retry " + (i + 1)); + assertEquals( + expectedBackoffSequence.get(i), + sleepDurations.get(i), + "Backoff duration mismatch at retry " + (i + 1) + ); } verify(task, times(retryAttempts + 1)).run(); @@ -318,9 +359,13 @@ void testExecuteWithRetry_UnexpectedException() throws Throwable { Exception unexpectedException = new NullPointerException("Unexpected null value"); doThrow(unexpectedException).when(task).run(); - Exception thrown = assertThrows(NullPointerException.class, () -> { - updater.executeWithRetry(task, "Test Task"); - }, "Expected executeWithRetry to throw NullPointerException"); + Exception thrown = assertThrows( + NullPointerException.class, + () -> { + updater.executeWithRetry(task, "Test Task"); + }, + "Expected executeWithRetry to throw NullPointerException" + ); assertEquals("Unexpected null value", thrown.getMessage(), "Exception message should match"); verify(updater, never()).sleep(anyInt()); @@ -344,7 +389,6 @@ private static Stream provideServiceBusFailureReasons() { Arguments.of(ServiceBusFailureReason.QUOTA_EXCEEDED, true), Arguments.of(ServiceBusFailureReason.GENERAL_ERROR, true), Arguments.of(ServiceBusFailureReason.UNAUTHORIZED, true), - // Non-Retryable Errors Arguments.of(ServiceBusFailureReason.MESSAGING_ENTITY_NOT_FOUND, false), Arguments.of(ServiceBusFailureReason.MESSAGING_ENTITY_DISABLED, false), @@ -361,7 +405,10 @@ private static Stream provideServiceBusFailureReasons() { * @return A ServiceBusException instance with the specified reason. */ private ServiceBusException createServiceBusException(ServiceBusFailureReason reason) { - ServiceBusException exception = new ServiceBusException(new Throwable(), ServiceBusErrorSource.RECEIVE); + ServiceBusException exception = new ServiceBusException( + new Throwable(), + ServiceBusErrorSource.RECEIVE + ); try { Field reasonField = ServiceBusException.class.getDeclaredField("reason"); reasonField.setAccessible(true); @@ -379,7 +426,9 @@ private ServiceBusException createServiceBusException(ServiceBusFailureReason re * @param The type parameter extending ExpandableStringEnum. * @return A Collection of all registered instances. */ - private static > Collection getExpandableStringEnumValues(Class clazz) { + private static > Collection getExpandableStringEnumValues( + Class clazz + ) { try { Method valuesMethod = ExpandableStringEnum.class.getDeclaredMethod("values", Class.class); valuesMethod.setAccessible(true); @@ -390,4 +439,4 @@ private static > Collection getExpandableSt throw new RuntimeException("Failed to retrieve values from ExpandableStringEnum.", e); } } -} \ No newline at end of file +} diff --git a/application/src/ext-test/java/org/opentripplanner/ext/smoovebikerental/SmooveBikeRentalDataSourceTest.java b/application/src/ext-test/java/org/opentripplanner/ext/smoovebikerental/SmooveBikeRentalDataSourceTest.java index 84161c004841..d8f06ef50c5d 100644 --- a/application/src/ext-test/java/org/opentripplanner/ext/smoovebikerental/SmooveBikeRentalDataSourceTest.java +++ b/application/src/ext-test/java/org/opentripplanner/ext/smoovebikerental/SmooveBikeRentalDataSourceTest.java @@ -7,8 +7,8 @@ import java.util.List; import org.junit.jupiter.api.Test; import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace; -import org.opentripplanner.updater.vehicle_rental.datasources.params.RentalPickupType; import org.opentripplanner.updater.spi.HttpHeaders; +import org.opentripplanner.updater.vehicle_rental.datasources.params.RentalPickupType; class SmooveBikeRentalDataSourceTest { diff --git a/application/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/vehicleparkings/VehicleParkingsLayerTest.java b/application/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/vehicleparkings/VehicleParkingsLayerTest.java index ae4386e9dd6f..cad94672576b 100644 --- a/application/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/vehicleparkings/VehicleParkingsLayerTest.java +++ b/application/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/vehicleparkings/VehicleParkingsLayerTest.java @@ -110,7 +110,11 @@ public void vehicleParkingGeometryTest() { var nodeAdapter = newNodeAdapterForTest(config); var tiles = VectorTileConfig.mapVectorTilesParameters(nodeAdapter, "vectorTiles"); assertEquals(1, tiles.layers().size()); - var builder = new VehicleParkingsLayerBuilder(new DefaultVehicleParkingService(repo), tiles.layers().getFirst(), Locale.US); + var builder = new VehicleParkingsLayerBuilder( + new DefaultVehicleParkingService(repo), + tiles.layers().getFirst(), + Locale.US + ); List geometries = builder.getGeometries(new Envelope(0.99, 1.01, 1.99, 2.01)); diff --git a/application/src/ext/java/org/opentripplanner/ext/flex/trip/ScheduledDeviatedTrip.java b/application/src/ext/java/org/opentripplanner/ext/flex/trip/ScheduledDeviatedTrip.java index 25eac71ebb6a..ce6404a975b2 100644 --- a/application/src/ext/java/org/opentripplanner/ext/flex/trip/ScheduledDeviatedTrip.java +++ b/application/src/ext/java/org/opentripplanner/ext/flex/trip/ScheduledDeviatedTrip.java @@ -57,7 +57,8 @@ public static ScheduledDeviatedTripBuilder of(FeedScopedId id) { public static boolean isScheduledDeviatedFlexTrip(List stopTimes) { Predicate notFixedStop = Predicate.not(st -> st.getStop() instanceof RegularStop); return ( - stopTimes.stream().anyMatch(notFixedStop) && stopTimes.stream().noneMatch(StopTime::combinesContinuousStoppingWithFlexWindow) + stopTimes.stream().anyMatch(notFixedStop) && + stopTimes.stream().noneMatch(StopTime::combinesContinuousStoppingWithFlexWindow) ); } diff --git a/application/src/ext/java/org/opentripplanner/ext/geocoder/StopClusterMapper.java b/application/src/ext/java/org/opentripplanner/ext/geocoder/StopClusterMapper.java index d420d0e8784a..df9531d4b8b1 100644 --- a/application/src/ext/java/org/opentripplanner/ext/geocoder/StopClusterMapper.java +++ b/application/src/ext/java/org/opentripplanner/ext/geocoder/StopClusterMapper.java @@ -208,11 +208,7 @@ StopCluster.Location toLocation(FeedScopedId id) { } else { var group = transitService.getStopLocationsGroup(id); var feedPublisher = toFeedPublisher(transitService.getFeedInfo(id.getFeedId())); - var modes = transitService - .findTransitModes(group) - .stream() - .map(Enum::name) - .toList(); + var modes = transitService.findTransitModes(group).stream().map(Enum::name).toList(); var agencies = agenciesForStopLocationsGroup(group) .stream() .map(StopClusterMapper::toAgency) diff --git a/application/src/ext/java/org/opentripplanner/ext/parkAndRideApi/ParkAndRideResource.java b/application/src/ext/java/org/opentripplanner/ext/parkAndRideApi/ParkAndRideResource.java index 611f4d464201..5fbae4b75d64 100644 --- a/application/src/ext/java/org/opentripplanner/ext/parkAndRideApi/ParkAndRideResource.java +++ b/application/src/ext/java/org/opentripplanner/ext/parkAndRideApi/ParkAndRideResource.java @@ -42,7 +42,8 @@ public ParkAndRideResource( // - serverContext.graphFinder(). This needs at least a comment! // - This can be replaced with a search done with the SiteRepository // - if we have a radius search there. - this.graphFinder = new DirectGraphFinder(serverContext.transitService()::findRegularStopsByBoundingBox); + this.graphFinder = + new DirectGraphFinder(serverContext.transitService()::findRegularStopsByBoundingBox); } /** Envelopes are in latitude, longitude format */ diff --git a/application/src/ext/java/org/opentripplanner/ext/restapi/model/ApiRouterInfo.java b/application/src/ext/java/org/opentripplanner/ext/restapi/model/ApiRouterInfo.java index 95317d400570..87ac08a7d8b6 100644 --- a/application/src/ext/java/org/opentripplanner/ext/restapi/model/ApiRouterInfo.java +++ b/application/src/ext/java/org/opentripplanner/ext/restapi/model/ApiRouterInfo.java @@ -50,7 +50,12 @@ public ApiRouterInfo( this.hasParkRide = this.hasCarPark; this.hasVehicleParking = mapHasVehicleParking(vehicleParkingService); this.travelOptions = - ApiTravelOptionsMaker.makeOptions(graph, vehicleRentalService, vehicleParkingService, transitService); + ApiTravelOptionsMaker.makeOptions( + graph, + vehicleRentalService, + vehicleParkingService, + transitService + ); } public boolean mapHasBikeSharing(VehicleRentalService service) { diff --git a/application/src/ext/java/org/opentripplanner/ext/restapi/resources/IndexAPI.java b/application/src/ext/java/org/opentripplanner/ext/restapi/resources/IndexAPI.java index b9c049f547e4..37330d85f05d 100644 --- a/application/src/ext/java/org/opentripplanner/ext/restapi/resources/IndexAPI.java +++ b/application/src/ext/java/org/opentripplanner/ext/restapi/resources/IndexAPI.java @@ -222,10 +222,7 @@ public List getStopsInRadius( ); var stops = transitService().findRegularStopsByBoundingBox(envelope); - return stops - .stream() - .map(StopMapper::mapToApiShort) - .toList(); + return stops.stream().map(StopMapper::mapToApiShort).toList(); } } diff --git a/application/src/ext/java/org/opentripplanner/ext/siri/updater/azure/AbstractAzureSiriUpdater.java b/application/src/ext/java/org/opentripplanner/ext/siri/updater/azure/AbstractAzureSiriUpdater.java index 545b216dd56f..bb9b23cc0f3f 100644 --- a/application/src/ext/java/org/opentripplanner/ext/siri/updater/azure/AbstractAzureSiriUpdater.java +++ b/application/src/ext/java/org/opentripplanner/ext/siri/updater/azure/AbstractAzureSiriUpdater.java @@ -1,6 +1,5 @@ package org.opentripplanner.ext.siri.updater.azure; - import com.azure.identity.DefaultAzureCredentialBuilder; import com.azure.messaging.servicebus.ServiceBusClientBuilder; import com.azure.messaging.servicebus.ServiceBusErrorContext; @@ -98,9 +97,14 @@ interface CheckedRunnable { public AbstractAzureSiriUpdater(SiriAzureUpdaterParameters config) { this.configRef = Objects.requireNonNull(config.configRef(), "configRef must not be null"); - this.authenticationType = Objects.requireNonNull(config.getAuthenticationType(), "authenticationType must not be null"); + this.authenticationType = + Objects.requireNonNull(config.getAuthenticationType(), "authenticationType must not be null"); this.topicName = Objects.requireNonNull(config.getTopicName(), "topicName must not be null"); - this.dataInitializationUrl = Objects.requireNonNull(config.getDataInitializationUrl(), "dataInitializationUrl must not be null"); + this.dataInitializationUrl = + Objects.requireNonNull( + config.getDataInitializationUrl(), + "dataInitializationUrl must not be null" + ); this.timeout = config.getTimeout(); this.feedId = Objects.requireNonNull(config.feedId(), "feedId must not be null"); this.autoDeleteOnIdle = config.getAutoDeleteOnIdle(); @@ -108,16 +112,18 @@ public AbstractAzureSiriUpdater(SiriAzureUpdaterParameters config) { this.fuzzyTripMatching = config.isFuzzyTripMatching(); if (authenticationType == AuthenticationType.FederatedIdentity) { - this.fullyQualifiedNamespace = Objects.requireNonNull( - config.getFullyQualifiedNamespace(), - "fullyQualifiedNamespace must not be null when using FederatedIdentity authentication" - ); + this.fullyQualifiedNamespace = + Objects.requireNonNull( + config.getFullyQualifiedNamespace(), + "fullyQualifiedNamespace must not be null when using FederatedIdentity authentication" + ); this.serviceBusUrl = null; } else if (authenticationType == AuthenticationType.SharedAccessKey) { - this.serviceBusUrl = Objects.requireNonNull( - config.getServiceBusUrl(), - "serviceBusUrl must not be null when using SharedAccessKey authentication" - ); + this.serviceBusUrl = + Objects.requireNonNull( + config.getServiceBusUrl(), + "serviceBusUrl must not be null when using SharedAccessKey authentication" + ); this.fullyQualifiedNamespace = null; } else { throw new IllegalArgumentException("Unsupported authentication type: " + authenticationType); @@ -143,7 +149,6 @@ public void setup(WriteToGraphCallback writeToGraphCallback) { @Override public void run() { - // In Kubernetes this should be the POD identifier subscriptionName = System.getenv("HOSTNAME"); if (subscriptionName == null || subscriptionName.isBlank()) { @@ -151,20 +156,14 @@ public void run() { } try { - executeWithRetry( - this::setupSubscription, - "Setting up Service Bus subscription to topic" - ); + executeWithRetry(this::setupSubscription, "Setting up Service Bus subscription to topic"); executeWithRetry( () -> initializeData(dataInitializationUrl, messageConsumer), "Initializing historical Siri data" ); - executeWithRetry( - this::startEventProcessor, - "Starting Service Bus event processor" - ); + executeWithRetry(this::startEventProcessor, "Starting Service Bus event processor"); setPrimed(); @@ -181,7 +180,6 @@ public void run() { } } ); - } catch (ServiceBusException e) { LOG.error("Service Bus encountered an error during setup: {}", e.getMessage(), e); } catch (URISyntaxException e) { @@ -235,7 +233,7 @@ protected void executeWithRetry(CheckedRunnable task, String description) throws attemptCounter++; try { sleep(sleepPeriod); - } catch (InterruptedException ie){ + } catch (InterruptedException ie) { LOG.warn("{} was interrupted during sleep.", description); Thread.currentThread().interrupt(); // Restore interrupted status throw ie; @@ -250,21 +248,16 @@ protected boolean shouldRetry(Exception e) { ServiceBusFailureReason reason = sbException.getReason(); if (RETRYABLE_REASONS.contains(reason)) { - LOG.warn("Transient error encountered: {}. Retrying...", reason); return true; - } else if (NON_RETRYABLE_REASONS.contains(reason)) { - LOG.error("Non-recoverable error encountered: {}. Not retrying.", reason); return false; - } else { LOG.warn("Unhandled ServiceBusFailureReason: {}. Retrying by default.", reason); return true; } - } - else if (ExceptionUtils.hasCause(e, OtpHttpClientException.class)){ + } else if (ExceptionUtils.hasCause(e, OtpHttpClientException.class)) { // retry for OtpHttpClientException as it is thrown if historical data can't be read at the moment return true; } @@ -297,8 +290,15 @@ private void setupSubscription() throws ServiceBusException, URISyntaxException .setAutoDeleteOnIdle(autoDeleteOnIdle); // Make sure there is no old subscription on serviceBus - if ( Boolean.TRUE.equals( serviceBusAdmin.getSubscriptionExists(topicName, subscriptionName).block())) { - LOG.info("Subscription '{}' already exists. Deleting existing subscription.", subscriptionName); + if ( + Boolean.TRUE.equals( + serviceBusAdmin.getSubscriptionExists(topicName, subscriptionName).block() + ) + ) { + LOG.info( + "Subscription '{}' already exists. Deleting existing subscription.", + subscriptionName + ); serviceBusAdmin.deleteSubscription(topicName, subscriptionName).block(); LOG.info("Service Bus deleted subscription {}.", subscriptionName); } @@ -314,28 +314,34 @@ private void startEventProcessor() throws ServiceBusException { ServiceBusClientBuilder clientBuilder = new ServiceBusClientBuilder(); if (authenticationType == AuthenticationType.FederatedIdentity) { - Preconditions.checkNotNull(fullyQualifiedNamespace, "fullyQualifiedNamespace must be set for FederatedIdentity authentication"); + Preconditions.checkNotNull( + fullyQualifiedNamespace, + "fullyQualifiedNamespace must be set for FederatedIdentity authentication" + ); clientBuilder .fullyQualifiedNamespace(fullyQualifiedNamespace) .credential(new DefaultAzureCredentialBuilder().build()); } else if (authenticationType == AuthenticationType.SharedAccessKey) { - Preconditions.checkNotNull(serviceBusUrl, "serviceBusUrl must be set for SharedAccessKey authentication"); - clientBuilder - .connectionString(serviceBusUrl); + Preconditions.checkNotNull( + serviceBusUrl, + "serviceBusUrl must be set for SharedAccessKey authentication" + ); + clientBuilder.connectionString(serviceBusUrl); } else { throw new IllegalArgumentException("Unsupported authentication type: " + authenticationType); } - eventProcessor = clientBuilder - .processor() - .topicName(topicName) - .subscriptionName(subscriptionName) - .receiveMode(ServiceBusReceiveMode.RECEIVE_AND_DELETE) - .disableAutoComplete() // Receive and delete does not need autocomplete - .prefetchCount(prefetchCount) - .processError(errorConsumer) - .processMessage(messageConsumer) - .buildProcessorClient(); + eventProcessor = + clientBuilder + .processor() + .topicName(topicName) + .subscriptionName(subscriptionName) + .receiveMode(ServiceBusReceiveMode.RECEIVE_AND_DELETE) + .disableAutoComplete() // Receive and delete does not need autocomplete + .prefetchCount(prefetchCount) + .processError(errorConsumer) + .processMessage(messageConsumer) + .buildProcessorClient(); eventProcessor.start(); LOG.info( @@ -346,7 +352,6 @@ private void startEventProcessor() throws ServiceBusException { ); } - @Override public boolean isPrimed() { return this.isPrimed; @@ -391,7 +396,6 @@ boolean fuzzyTripMatching() { return fuzzyTripMatching; } - protected abstract void initializeData( String url, Consumer consumer @@ -416,8 +420,10 @@ protected void defaultErrorConsumer(ServiceBusErrorContext errorContext) { var reason = e.getReason(); - if (reason == ServiceBusFailureReason.MESSAGING_ENTITY_DISABLED || - reason == ServiceBusFailureReason.MESSAGING_ENTITY_NOT_FOUND) { + if ( + reason == ServiceBusFailureReason.MESSAGING_ENTITY_DISABLED || + reason == ServiceBusFailureReason.MESSAGING_ENTITY_NOT_FOUND + ) { LOG.error( "An unrecoverable error occurred. Stopping processing with reason {} {}", reason, @@ -425,8 +431,10 @@ protected void defaultErrorConsumer(ServiceBusErrorContext errorContext) { ); } else if (reason == ServiceBusFailureReason.MESSAGE_LOCK_LOST) { LOG.error("Message lock lost for message", e); - } else if (reason == ServiceBusFailureReason.SERVICE_BUSY || - reason == ServiceBusFailureReason.UNAUTHORIZED) { + } else if ( + reason == ServiceBusFailureReason.SERVICE_BUSY || + reason == ServiceBusFailureReason.UNAUTHORIZED + ) { LOG.error("Service Bus is busy or unauthorized, wait and try again"); try { // Choosing an arbitrary amount of time to wait until trying again. diff --git a/application/src/ext/java/org/opentripplanner/ext/smoovebikerental/SmooveBikeRentalDataSourceParameters.java b/application/src/ext/java/org/opentripplanner/ext/smoovebikerental/SmooveBikeRentalDataSourceParameters.java index a04ea004bf0b..fc2d67008162 100644 --- a/application/src/ext/java/org/opentripplanner/ext/smoovebikerental/SmooveBikeRentalDataSourceParameters.java +++ b/application/src/ext/java/org/opentripplanner/ext/smoovebikerental/SmooveBikeRentalDataSourceParameters.java @@ -2,9 +2,9 @@ import java.util.Set; import javax.annotation.Nullable; -import org.opentripplanner.updater.vehicle_rental.datasources.params.RentalPickupType; import org.opentripplanner.updater.spi.HttpHeaders; import org.opentripplanner.updater.vehicle_rental.VehicleRentalSourceType; +import org.opentripplanner.updater.vehicle_rental.datasources.params.RentalPickupType; import org.opentripplanner.updater.vehicle_rental.datasources.params.VehicleRentalDataSourceParameters; /** diff --git a/application/src/ext/java/org/opentripplanner/ext/sorlandsbanen/CoachCostCalculator.java b/application/src/ext/java/org/opentripplanner/ext/sorlandsbanen/CoachCostCalculator.java index ba4830f29cfa..0862f5bd2017 100644 --- a/application/src/ext/java/org/opentripplanner/ext/sorlandsbanen/CoachCostCalculator.java +++ b/application/src/ext/java/org/opentripplanner/ext/sorlandsbanen/CoachCostCalculator.java @@ -7,76 +7,74 @@ import org.opentripplanner.routing.algorithm.raptoradapter.transit.TripSchedule; import org.opentripplanner.transit.model.basic.TransitMode; - /** * This cost calculator increases the cost on mode coach by adding an extra reluctance. The * reluctance is hardcoded in this class and cannot be configured. */ -class CoachCostCalculator implements RaptorCostCalculator { +class CoachCostCalculator implements RaptorCostCalculator { private static final int EXTRA_RELUCTANCE_ON_COACH = RaptorCostConverter.toRaptorCost(0.6); private final RaptorCostCalculator delegate; CoachCostCalculator(RaptorCostCalculator delegate) { - this.delegate = delegate; - } - - @Override - public int boardingCost( - boolean firstBoarding, - int prevArrivalTime, - int boardStop, - int boardTime, - T trip, - RaptorTransferConstraint transferConstraints - ) { - return delegate.boardingCost( - firstBoarding, - prevArrivalTime, - boardStop, - boardTime, - trip, - transferConstraints - ); - } + this.delegate = delegate; + } - @Override - public int onTripRelativeRidingCost(int boardTime, T tripScheduledBoarded) { - return delegate.onTripRelativeRidingCost(boardTime, tripScheduledBoarded); - } + @Override + public int boardingCost( + boolean firstBoarding, + int prevArrivalTime, + int boardStop, + int boardTime, + T trip, + RaptorTransferConstraint transferConstraints + ) { + return delegate.boardingCost( + firstBoarding, + prevArrivalTime, + boardStop, + boardTime, + trip, + transferConstraints + ); + } - @Override - public int transitArrivalCost( - int boardCost, - int alightSlack, - int transitTime, - T trip, - int toStop - ) { - int cost = delegate.transitArrivalCost(boardCost, alightSlack, transitTime, trip, toStop); + @Override + public int onTripRelativeRidingCost(int boardTime, T tripScheduledBoarded) { + return delegate.onTripRelativeRidingCost(boardTime, tripScheduledBoarded); + } - // This is a bit ugly, since it relies on the fact that the 'transitReluctanceFactorIndex' - // returns the 'route.getMode().ordinal()' - if(trip.transitReluctanceFactorIndex() == TransitMode.COACH.ordinal()) { - cost += transitTime * EXTRA_RELUCTANCE_ON_COACH; - } - return cost; - } + @Override + public int transitArrivalCost( + int boardCost, + int alightSlack, + int transitTime, + T trip, + int toStop + ) { + int cost = delegate.transitArrivalCost(boardCost, alightSlack, transitTime, trip, toStop); - @Override - public int waitCost(int waitTimeInSeconds) { - return delegate.waitCost(waitTimeInSeconds); + // This is a bit ugly, since it relies on the fact that the 'transitReluctanceFactorIndex' + // returns the 'route.getMode().ordinal()' + if (trip.transitReluctanceFactorIndex() == TransitMode.COACH.ordinal()) { + cost += transitTime * EXTRA_RELUCTANCE_ON_COACH; } + return cost; + } - @Override - public int calculateRemainingMinCost(int minTravelTime, int minNumTransfers, int fromStop) { - return delegate.calculateRemainingMinCost(minTravelTime, minNumTransfers, fromStop); - } + @Override + public int waitCost(int waitTimeInSeconds) { + return delegate.waitCost(waitTimeInSeconds); + } - @Override - public int costEgress(RaptorAccessEgress egress) { - return delegate.costEgress(egress); - } + @Override + public int calculateRemainingMinCost(int minTravelTime, int minNumTransfers, int fromStop) { + return delegate.calculateRemainingMinCost(minTravelTime, minNumTransfers, fromStop); + } + @Override + public int costEgress(RaptorAccessEgress egress) { + return delegate.costEgress(egress); + } } diff --git a/application/src/ext/java/org/opentripplanner/ext/sorlandsbanen/MergePaths.java b/application/src/ext/java/org/opentripplanner/ext/sorlandsbanen/MergePaths.java index 2f7b38a7a08e..392023c3bebd 100644 --- a/application/src/ext/java/org/opentripplanner/ext/sorlandsbanen/MergePaths.java +++ b/application/src/ext/java/org/opentripplanner/ext/sorlandsbanen/MergePaths.java @@ -15,10 +15,15 @@ * Everything from the main result is kept, and any additional rail results from the alternative * search are added. */ -class MergePaths implements BiFunction>, Collection>, Collection>> { +class MergePaths + implements + BiFunction>, Collection>, Collection>> { @Override - public Collection> apply(Collection> main, Collection> alternatives) { + public Collection> apply( + Collection> main, + Collection> alternatives + ) { Map> result = new HashMap<>(); addAllToMap(result, main); addRailToMap(result, alternatives); @@ -27,7 +32,7 @@ public Collection> apply(Collection> main, Collectio private void addAllToMap(Map> map, Collection> paths) { for (var it : paths) { - map.put(new PathKey(it), it); + map.put(new PathKey(it), it); } } diff --git a/application/src/ext/java/org/opentripplanner/ext/sorlandsbanen/PathKey.java b/application/src/ext/java/org/opentripplanner/ext/sorlandsbanen/PathKey.java index e4504b3ed148..27e1c9de4eac 100644 --- a/application/src/ext/java/org/opentripplanner/ext/sorlandsbanen/PathKey.java +++ b/application/src/ext/java/org/opentripplanner/ext/sorlandsbanen/PathKey.java @@ -3,7 +3,6 @@ import org.opentripplanner.raptor.api.path.PathLeg; import org.opentripplanner.raptor.api.path.RaptorPath; - /** * The purpose of this class is to create a key to be able to compare paths so duplicate results * can be ignored. diff --git a/application/src/ext/java/org/opentripplanner/ext/sorlandsbanen/SorlandsbanenNorwayService.java b/application/src/ext/java/org/opentripplanner/ext/sorlandsbanen/SorlandsbanenNorwayService.java index ecccb5d23709..aad437124375 100644 --- a/application/src/ext/java/org/opentripplanner/ext/sorlandsbanen/SorlandsbanenNorwayService.java +++ b/application/src/ext/java/org/opentripplanner/ext/sorlandsbanen/SorlandsbanenNorwayService.java @@ -32,9 +32,12 @@ public class SorlandsbanenNorwayService { private static final double SOUTH_BORDER_LIMIT = 59.1; private static final int MIN_DISTANCE_LIMIT = 120_000; - @Nullable - public ExtraMcRouterSearch createExtraMcRouterSearch(RouteRequest request, AccessEgresses accessEgresses, TransitLayer transitLayer) { + public ExtraMcRouterSearch createExtraMcRouterSearch( + RouteRequest request, + AccessEgresses accessEgresses, + TransitLayer transitLayer + ) { WgsCoordinate from = findStopCoordinate( request.from(), accessEgresses.getAccesses(), @@ -53,9 +56,11 @@ public ExtraMcRouterSearch createExtraMcRouterSearch(RouteRequest return new ExtraMcRouterSearch<>() { @Override - public RaptorTransitDataProvider createTransitDataAlternativeSearch(RaptorTransitDataProvider transitDataMainSearch) { + public RaptorTransitDataProvider createTransitDataAlternativeSearch( + RaptorTransitDataProvider transitDataMainSearch + ) { return new RaptorRoutingRequestTransitData( - (RaptorRoutingRequestTransitData)transitDataMainSearch, + (RaptorRoutingRequestTransitData) transitDataMainSearch, new CoachCostCalculator<>(transitDataMainSearch.multiCriteriaCostCalculator()) ); } diff --git a/application/src/ext/java/org/opentripplanner/ext/stopconsolidation/DecorateConsolidatedStopNames.java b/application/src/ext/java/org/opentripplanner/ext/stopconsolidation/DecorateConsolidatedStopNames.java index 6def5c85fa1f..150ad5ebece0 100644 --- a/application/src/ext/java/org/opentripplanner/ext/stopconsolidation/DecorateConsolidatedStopNames.java +++ b/application/src/ext/java/org/opentripplanner/ext/stopconsolidation/DecorateConsolidatedStopNames.java @@ -62,17 +62,11 @@ private void replaceConsolidatedStops(Itinerary i) { private void removeShortWalkLegs(Itinerary itinerary) { var legs = new ArrayList<>(itinerary.getLegs()); var first = legs.getFirst(); - if ( - service.isPartOfConsolidatedStop(first.getTo().stop) && - isShortWalkLeg(first) - ) { + if (service.isPartOfConsolidatedStop(first.getTo().stop) && isShortWalkLeg(first)) { legs.removeFirst(); } var last = legs.getLast(); - if ( - service.isPartOfConsolidatedStop(last.getFrom().stop) && - isShortWalkLeg(last) - ) { + if (service.isPartOfConsolidatedStop(last.getFrom().stop) && isShortWalkLeg(last)) { legs.removeLast(); } @@ -82,14 +76,15 @@ private void removeShortWalkLegs(Itinerary itinerary) { } private boolean isTransferWithinConsolidatedStop(Leg l) { - return isShortWalkLeg(l) && + return ( + isShortWalkLeg(l) && service.isPartOfConsolidatedStop(l.getFrom().stop) && - service.isPartOfConsolidatedStop(l.getTo().stop); + service.isPartOfConsolidatedStop(l.getTo().stop) + ); } private static boolean isShortWalkLeg(Leg leg) { - return leg.isWalkingLeg() && - leg.getDistanceMeters() < MAX_INTRA_STOP_WALK_DISTANCE_METERS; + return leg.isWalkingLeg() && leg.getDistanceMeters() < MAX_INTRA_STOP_WALK_DISTANCE_METERS; } /** diff --git a/application/src/ext/java/org/opentripplanner/ext/stopconsolidation/internal/DefaultStopConsolidationService.java b/application/src/ext/java/org/opentripplanner/ext/stopconsolidation/internal/DefaultStopConsolidationService.java index 8e6f31fb6fe3..aa84caf4f4dc 100644 --- a/application/src/ext/java/org/opentripplanner/ext/stopconsolidation/internal/DefaultStopConsolidationService.java +++ b/application/src/ext/java/org/opentripplanner/ext/stopconsolidation/internal/DefaultStopConsolidationService.java @@ -4,8 +4,8 @@ import java.util.Objects; import java.util.Optional; import java.util.stream.Stream; -import org.opentripplanner.ext.stopconsolidation.StopConsolidationRepository; import javax.annotation.Nullable; +import org.opentripplanner.ext.stopconsolidation.StopConsolidationRepository; import org.opentripplanner.ext.stopconsolidation.StopConsolidationService; import org.opentripplanner.ext.stopconsolidation.model.ConsolidatedStopGroup; import org.opentripplanner.ext.stopconsolidation.model.StopReplacement; diff --git a/application/src/ext/java/org/opentripplanner/ext/vectortiles/layers/vehicleparkings/VehicleParkingsLayerBuilder.java b/application/src/ext/java/org/opentripplanner/ext/vectortiles/layers/vehicleparkings/VehicleParkingsLayerBuilder.java index 22fb75f7b49b..ea569c7a2956 100644 --- a/application/src/ext/java/org/opentripplanner/ext/vectortiles/layers/vehicleparkings/VehicleParkingsLayerBuilder.java +++ b/application/src/ext/java/org/opentripplanner/ext/vectortiles/layers/vehicleparkings/VehicleParkingsLayerBuilder.java @@ -46,7 +46,8 @@ public VehicleParkingsLayerBuilder( @Override protected List getGeometries(Envelope query) { return service - .listVehicleParkings().stream() + .listVehicleParkings() + .stream() .map(vehicleParking -> { Coordinate coordinate = vehicleParking.getCoordinate().asJtsCoordinate(); Point point = GeometryUtils.getGeometryFactory().createPoint(coordinate); diff --git a/application/src/ext/java/org/opentripplanner/ext/vehiclerentalservicedirectory/VehicleRentalServiceDirectoryFetcher.java b/application/src/ext/java/org/opentripplanner/ext/vehiclerentalservicedirectory/VehicleRentalServiceDirectoryFetcher.java index dc0fa2868ec0..179a158a2a9c 100644 --- a/application/src/ext/java/org/opentripplanner/ext/vehiclerentalservicedirectory/VehicleRentalServiceDirectoryFetcher.java +++ b/application/src/ext/java/org/opentripplanner/ext/vehiclerentalservicedirectory/VehicleRentalServiceDirectoryFetcher.java @@ -18,8 +18,8 @@ import org.opentripplanner.updater.spi.GraphUpdater; import org.opentripplanner.updater.vehicle_rental.VehicleRentalUpdater; import org.opentripplanner.updater.vehicle_rental.datasources.VehicleRentalDataSourceFactory; -import org.opentripplanner.updater.vehicle_rental.datasources.params.RentalPickupType; import org.opentripplanner.updater.vehicle_rental.datasources.params.GbfsVehicleRentalDataSourceParameters; +import org.opentripplanner.updater.vehicle_rental.datasources.params.RentalPickupType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/pom.xml b/pom.xml index 3c4eaf5a3b9b..517b1bde48c6 100644 --- a/pom.xml +++ b/pom.xml @@ -304,7 +304,9 @@ 2.0.0 src/main/java/**/*.java + src/ext/java/**/*.java src/test/java/**/*.java + src/ext-test/java/**/*.java src/**/*.json src/test/resources/org/opentripplanner/apis/**/*.graphql