diff --git a/src/ext/java/org/opentripplanner/ext/siri/SiriTimetableSnapshotSource.java b/src/ext/java/org/opentripplanner/ext/siri/SiriTimetableSnapshotSource.java index 6d94f261173..7d7cd0e5443 100644 --- a/src/ext/java/org/opentripplanner/ext/siri/SiriTimetableSnapshotSource.java +++ b/src/ext/java/org/opentripplanner/ext/siri/SiriTimetableSnapshotSource.java @@ -10,7 +10,6 @@ import static org.opentripplanner.model.UpdateError.UpdateErrorType.NO_START_DATE; import static org.opentripplanner.model.UpdateError.UpdateErrorType.NO_UPDATES; import static org.opentripplanner.model.UpdateError.UpdateErrorType.TRIP_NOT_FOUND_IN_PATTERN; -import static org.opentripplanner.model.UpdateError.UpdateErrorType.UNKNOWN; import com.google.common.base.Preconditions; import java.time.LocalDate; @@ -890,7 +889,7 @@ private List handleModifiedTrip( if (exactPattern != null) { Timetable currentTimetable = getCurrentTimetable(exactPattern, serviceDate); - TripTimes exactUpdatedTripTimes = createUpdatedTripTimes( + var updateResult = createUpdatedTripTimes( currentTimetable, estimatedVehicleJourney, tripMatchedByServiceJourneyId.getId(), @@ -898,15 +897,15 @@ private List handleModifiedTrip( timeZone, transitModel.getDeduplicator() ); - if (exactUpdatedTripTimes != null) { - times.add(exactUpdatedTripTimes); + if (updateResult.isSuccess()) { + times.add(updateResult.successValue()); patterns.add(exactPattern); } else { LOG.info( "Failed to update TripTimes for trip found by exact match {}", tripMatchedByServiceJourneyId.getId() ); - return List.of(new UpdateError(tripMatchedByServiceJourneyId.getId(), UNKNOWN)); + return List.of(updateResult.failureValue()); } } } else { @@ -942,7 +941,7 @@ private List handleModifiedTrip( TripPattern pattern = getPatternForTrip(matchingTrip, estimatedVehicleJourney); if (pattern != null) { Timetable currentTimetable = getCurrentTimetable(pattern, serviceDate); - TripTimes updatedTripTimes = createUpdatedTripTimes( + var updateResult = createUpdatedTripTimes( currentTimetable, estimatedVehicleJourney, matchingTrip.getId(), @@ -950,10 +949,10 @@ private List handleModifiedTrip( timeZone, transitModel.getDeduplicator() ); - if (updatedTripTimes != null) { + updateResult.ifSuccess(tripTimes -> { patterns.add(pattern); - times.add(updatedTripTimes); - } + times.add(tripTimes); + }); } } } diff --git a/src/ext/java/org/opentripplanner/ext/siri/TimetableHelper.java b/src/ext/java/org/opentripplanner/ext/siri/TimetableHelper.java index 2d6a5a495fb..8a7f39fdd3a 100644 --- a/src/ext/java/org/opentripplanner/ext/siri/TimetableHelper.java +++ b/src/ext/java/org/opentripplanner/ext/siri/TimetableHelper.java @@ -5,6 +5,7 @@ import static org.opentripplanner.model.PickDrop.SCHEDULED; import static org.opentripplanner.model.UpdateError.UpdateErrorType.INVALID_INPUT_STRUCTURE; import static org.opentripplanner.model.UpdateError.UpdateErrorType.NON_INCREASING_TRIP_TIMES; +import static org.opentripplanner.model.UpdateError.UpdateErrorType.TOO_FEW_STOPS; import static org.opentripplanner.model.UpdateError.UpdateErrorType.TRIP_NOT_FOUND_IN_PATTERN; import static org.opentripplanner.model.UpdateError.UpdateErrorType.UNKNOWN; @@ -63,7 +64,7 @@ public class TimetableHelper { * @return new copy of updated TripTimes after TripUpdate has been applied on TripTimes of trip * with the id specified in the trip descriptor of the TripUpdate; null if something went wrong */ - public static TripTimes createUpdatedTripTimes( + public static Result createUpdatedTripTimes( Timetable timetable, EstimatedVehicleJourney journey, FeedScopedId tripId, @@ -78,14 +79,14 @@ public static TripTimes createUpdatedTripTimes( final TripTimes existingTripTimes = timetable.getTripTimes(tripId); if (existingTripTimes == null) { LOG.debug("tripId {} not found in pattern.", tripId); - return null; + return UpdateError.result(tripId, TRIP_NOT_FOUND_IN_PATTERN); } TripTimes oldTimes = new TripTimes(existingTripTimes); if (journey.isCancellation() != null && journey.isCancellation()) { oldTimes.cancelTrip(); - return oldTimes; + return Result.success(oldTimes); } List estimatedCalls = getEstimatedCalls(journey); @@ -109,7 +110,7 @@ public static TripTimes createUpdatedTripTimes( getStopById ); if (modifiedStopTimes == null) { - return null; + return UpdateError.result(tripId, UNKNOWN); } TripTimes newTimes = new TripTimes(oldTimes.getTrip(), modifiedStopTimes, deduplicator); @@ -387,15 +388,15 @@ public static TripTimes createUpdatedTripTimes( tripId, invalidStopIndex.getAsInt() ); - return null; + return UpdateError.result(tripId, NON_INCREASING_TRIP_TIMES); } if (newTimes.getNumStops() != pattern.numberOfStops()) { - return null; + return UpdateError.result(tripId, TOO_FEW_STOPS); } LOG.debug("A valid TripUpdate object was applied using the Timetable class update method."); - return newTimes; + return Result.success(newTimes); } private static int calculateDayOffset(TripTimes oldTimes) {