diff --git a/application/src/ext-test/java/org/opentripplanner/ext/flex/trip/ScheduledDeviatedTripIntegrationTest.java b/application/src/ext-test/java/org/opentripplanner/ext/flex/trip/ScheduledDeviatedTripIntegrationTest.java index 3a8e33cfbf2..81122a4130c 100644 --- a/application/src/ext-test/java/org/opentripplanner/ext/flex/trip/ScheduledDeviatedTripIntegrationTest.java +++ b/application/src/ext-test/java/org/opentripplanner/ext/flex/trip/ScheduledDeviatedTripIntegrationTest.java @@ -183,7 +183,7 @@ void shouldNotInterpolateFlexTimes() { assertEquals(3, pattern.numberOfStops()); - var tripTimes = pattern.getScheduledTimetable().getTripTimes(0); + var tripTimes = pattern.getScheduledTimetable().getTripTimes().getFirst(); var arrivalTime = tripTimes.getArrivalTime(1); assertEquals(StopTime.MISSING_VALUE, arrivalTime); diff --git a/application/src/ext-test/java/org/opentripplanner/ext/realtimeresolver/RealtimeResolverTest.java b/application/src/ext-test/java/org/opentripplanner/ext/realtimeresolver/RealtimeResolverTest.java index 94492d349a3..9fed7527334 100644 --- a/application/src/ext-test/java/org/opentripplanner/ext/realtimeresolver/RealtimeResolverTest.java +++ b/application/src/ext-test/java/org/opentripplanner/ext/realtimeresolver/RealtimeResolverTest.java @@ -74,7 +74,8 @@ void testPopulateLegsWithRealtime() { .asScheduledTransitLeg() .getTripPattern() .getScheduledTimetable() - .getTripTimes(0) + .getTripTimes() + .getFirst() .getArrivalDelay(1); assertEquals(123, leg1ArrivalDelay); assertEquals(0, legs.get(0).getTransitAlerts().size()); @@ -128,7 +129,7 @@ void testPopulateLegsWithRealtimeKeepStaySeated() { private static TripPattern delay(TripPattern pattern1, int seconds) { var originalTimeTable = pattern1.getScheduledTimetable(); - var delayedTripTimes = delay(originalTimeTable.getTripTimes(0), seconds); + var delayedTripTimes = delay(originalTimeTable.getTripTimes().getFirst(), seconds); var delayedTimetable = Timetable.of() .withTripPattern(pattern1) .addTripTimes(delayedTripTimes) @@ -166,7 +167,7 @@ private static TransitService makeTransitService( patterns.forEach(pattern -> { timetableRepository.addTripPattern(pattern.getId(), pattern); - var serviceCode = pattern.getScheduledTimetable().getTripTimes(0).getServiceCode(); + var serviceCode = pattern.getScheduledTimetable().getTripTimes().getFirst().getServiceCode(); timetableRepository.getServiceCodes().put(pattern.getId(), serviceCode); calendarServiceData.putServiceDatesForServiceId(pattern.getId(), List.of(serviceDate)); diff --git a/application/src/main/java/org/opentripplanner/model/Timetable.java b/application/src/main/java/org/opentripplanner/model/Timetable.java index 936e0388592..070fedcfe1a 100644 --- a/application/src/main/java/org/opentripplanner/model/Timetable.java +++ b/application/src/main/java/org/opentripplanner/model/Timetable.java @@ -52,39 +52,6 @@ public TimetableBuilder copyOf() { return new TimetableBuilder(this); } - /** @return the index of TripTimes for this trip ID in this particular Timetable */ - public int getTripIndex(FeedScopedId tripId) { - int ret = 0; - for (TripTimes tt : tripTimes) { - // could replace linear search with indexing in stoptime updater, but not necessary - // at this point since the updater thread is far from pegged. - if (tt.getTrip().getId().equals(tripId)) { - return ret; - } - ret += 1; - } - return -1; - } - - /** - * @return the index of TripTimes for this trip ID in this particular Timetable, ignoring - * AgencyIds. - */ - public int getTripIndex(String tripId) { - int ret = 0; - for (TripTimes tt : tripTimes) { - if (tt.getTrip().getId().getId().equals(tripId)) { - return ret; - } - ret += 1; - } - return -1; - } - - public TripTimes getTripTimes(int tripIndex) { - return tripTimes.get(tripIndex); - } - @Nullable public TripTimes getTripTimes(Trip trip) { for (TripTimes tt : tripTimes) { diff --git a/application/src/main/java/org/opentripplanner/transit/model/network/TripPattern.java b/application/src/main/java/org/opentripplanner/transit/model/network/TripPattern.java index 2b952f451e0..ffe44808c7b 100644 --- a/application/src/main/java/org/opentripplanner/transit/model/network/TripPattern.java +++ b/application/src/main/java/org/opentripplanner/transit/model/network/TripPattern.java @@ -27,8 +27,6 @@ import org.opentripplanner.transit.model.timetable.Direction; import org.opentripplanner.transit.model.timetable.Trip; import org.opentripplanner.transit.model.timetable.TripTimes; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; // TODO OTP2 instances of this class are still mutable after construction with a builder, this will be refactored in a subsequent step /** @@ -58,8 +56,6 @@ public final class TripPattern extends AbstractTransitEntity implements Cloneable, LogInfo { - private static final Logger LOG = LoggerFactory.getLogger(TripPattern.class); - private final Route route; /** diff --git a/application/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java b/application/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java index 6517cced249..7d2893e3af0 100644 --- a/application/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java +++ b/application/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java @@ -71,8 +71,6 @@ import org.opentripplanner.updater.GraphUpdaterStatus; import org.opentripplanner.utils.collection.CollectionsView; import org.opentripplanner.utils.time.ServiceDateUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Default implementation of the Transit Service and Transit Editor Service. @@ -82,7 +80,6 @@ */ public class DefaultTransitService implements TransitEditorService { - private static final Logger LOG = LoggerFactory.getLogger(DefaultTransitService.class); private final TimetableRepository timetableRepository; private final TimetableRepositoryIndex timetableRepositoryIndex; diff --git a/application/src/main/java/org/opentripplanner/updater/trip/gtfs/GtfsRealTimeTripUpdateAdapter.java b/application/src/main/java/org/opentripplanner/updater/trip/gtfs/GtfsRealTimeTripUpdateAdapter.java index 862aff22bfa..d18eaf08e99 100644 --- a/application/src/main/java/org/opentripplanner/updater/trip/gtfs/GtfsRealTimeTripUpdateAdapter.java +++ b/application/src/main/java/org/opentripplanner/updater/trip/gtfs/GtfsRealTimeTripUpdateAdapter.java @@ -935,17 +935,15 @@ private boolean cancelScheduledTrip( if (pattern != null) { // Cancel scheduled trip times for this trip in this pattern final Timetable timetable = pattern.getScheduledTimetable(); - final int tripIndex = timetable.getTripIndex(tripId); - if (tripIndex == -1) { + var tripTimes = timetable.getTripTimes(tripId); + if (tripTimes == null) { debug( tripId, serviceDate, "Could not cancel scheduled trip because it's not in the timetable" ); } else { - final RealTimeTripTimes newTripTimes = timetable - .getTripTimes(tripIndex) - .copyScheduledTimes(); + final RealTimeTripTimes newTripTimes = tripTimes.copyScheduledTimes(); switch (cancelationType) { case CANCEL -> newTripTimes.cancelTrip(); case DELETE -> newTripTimes.deleteTrip(); @@ -981,13 +979,11 @@ private boolean cancelPreviouslyAddedTrip( if (isPreviouslyAddedTrip(tripId, pattern, serviceDate)) { // Cancel trip times for this trip in this pattern final Timetable timetable = snapshotManager.resolve(pattern, serviceDate); - final int tripIndex = timetable.getTripIndex(tripId); - if (tripIndex == -1) { + var tripTimes = timetable.getTripTimes(tripId); + if (tripTimes == null) { debug(tripId, serviceDate, "Could not cancel previously added trip on {}", serviceDate); } else { - final RealTimeTripTimes newTripTimes = timetable - .getTripTimes(tripIndex) - .copyScheduledTimes(); + final RealTimeTripTimes newTripTimes = tripTimes.copyScheduledTimes(); switch (cancelationType) { case CANCEL -> newTripTimes.cancelTrip(); case DELETE -> newTripTimes.deleteTrip(); diff --git a/application/src/main/java/org/opentripplanner/updater/trip/gtfs/TripTimesUpdater.java b/application/src/main/java/org/opentripplanner/updater/trip/gtfs/TripTimesUpdater.java index 9d28fd0cca5..d43d1ec878d 100644 --- a/application/src/main/java/org/opentripplanner/updater/trip/gtfs/TripTimesUpdater.java +++ b/application/src/main/java/org/opentripplanner/updater/trip/gtfs/TripTimesUpdater.java @@ -82,15 +82,15 @@ public static Result createUpdatedTripTimesFromGTFS var feedScopedTripId = new FeedScopedId(timetable.getPattern().getFeedId(), tripId); - int tripIndex = timetable.getTripIndex(tripId); - if (tripIndex == -1) { + var tripTimes = timetable.getTripTimes(feedScopedTripId); + if (tripTimes == null) { LOG.debug("tripId {} not found in pattern.", tripId); return Result.failure(new UpdateError(feedScopedTripId, TRIP_NOT_FOUND_IN_PATTERN)); } else { - LOG.trace("tripId {} found at index {} in timetable.", tripId, tripIndex); + LOG.trace("tripId {} found in timetable.", tripId); } - RealTimeTripTimes newTimes = timetable.getTripTimes(tripIndex).copyScheduledTimes(); + RealTimeTripTimes newTimes = tripTimes.copyScheduledTimes(); List skippedStopIndices = new ArrayList<>(); // The GTFS-RT reference specifies that StopTimeUpdates are sorted by stop_sequence. diff --git a/application/src/test/java/org/opentripplanner/apis/transmodel/mapping/TripRequestMapperTest.java b/application/src/test/java/org/opentripplanner/apis/transmodel/mapping/TripRequestMapperTest.java index 088b47ef942..ec069676dc7 100644 --- a/application/src/test/java/org/opentripplanner/apis/transmodel/mapping/TripRequestMapperTest.java +++ b/application/src/test/java/org/opentripplanner/apis/transmodel/mapping/TripRequestMapperTest.java @@ -87,7 +87,11 @@ public class TripRequestMapperTest implements PlanTestConstants { LocalDate serviceDate = itinerary.startTime().toLocalDate(); patterns.forEach(pattern -> { timetableRepository.addTripPattern(pattern.getId(), pattern); - final int serviceCode = pattern.getScheduledTimetable().getTripTimes(0).getServiceCode(); + final int serviceCode = pattern + .getScheduledTimetable() + .getTripTimes() + .getFirst() + .getServiceCode(); timetableRepository.getServiceCodes().put(pattern.getId(), serviceCode); calendarServiceData.putServiceDatesForServiceId(pattern.getId(), List.of(serviceDate)); }); diff --git a/application/src/test/java/org/opentripplanner/routing/stoptimes/StopTimesHelperTest.java b/application/src/test/java/org/opentripplanner/routing/stoptimes/StopTimesHelperTest.java index 919d407563e..fe552986d32 100644 --- a/application/src/test/java/org/opentripplanner/routing/stoptimes/StopTimesHelperTest.java +++ b/application/src/test/java/org/opentripplanner/routing/stoptimes/StopTimesHelperTest.java @@ -37,7 +37,7 @@ public static void setUp() throws Exception { transitService.getTrip(new FeedScopedId(feedId, "5.1")) ); var tt = originalPattern.getScheduledTimetable(); - var newTripTimes = tt.getTripTimes(0).copyScheduledTimes(); + var newTripTimes = tt.getTripTimes().getFirst().copyScheduledTimes(); newTripTimes.cancelTrip(); pattern = originalPattern .copy() diff --git a/application/src/test/java/org/opentripplanner/transit/model/network/grouppriority/TransitGroupPriorityServiceTest.java b/application/src/test/java/org/opentripplanner/transit/model/network/grouppriority/TransitGroupPriorityServiceTest.java index 2ee728be9de..8440962747e 100644 --- a/application/src/test/java/org/opentripplanner/transit/model/network/grouppriority/TransitGroupPriorityServiceTest.java +++ b/application/src/test/java/org/opentripplanner/transit/model/network/grouppriority/TransitGroupPriorityServiceTest.java @@ -99,11 +99,15 @@ void lookupTransitGroupIdByAgency() { assertEquals(EXP_GROUP_ID_BASE, subject.lookupTransitGroupPriorityId(nullTrip)); assertEquals( EXP_GROUP_1, - subject.lookupTransitGroupPriorityId(busB2.getScheduledTimetable().getTripTimes(0).getTrip()) + subject.lookupTransitGroupPriorityId( + busB2.getScheduledTimetable().getTripTimes().getFirst().getTrip() + ) ); assertEquals( EXP_GROUP_2, - subject.lookupTransitGroupPriorityId(railR3.getScheduledTimetable().getTripTimes(0).getTrip()) + subject.lookupTransitGroupPriorityId( + railR3.getScheduledTimetable().getTripTimes().getFirst().getTrip() + ) ); } @@ -129,7 +133,9 @@ void lookupTransitPriorityGroupIdByGlobalMode() { assertEquals(EXP_GROUP_ID_BASE, subject.lookupTransitGroupPriorityId(nullTrip)); assertEquals( EXP_GROUP_2, - subject.lookupTransitGroupPriorityId(railR1.getScheduledTimetable().getTripTimes(0).getTrip()) + subject.lookupTransitGroupPriorityId( + railR1.getScheduledTimetable().getTripTimes().getFirst().getTrip() + ) ); } diff --git a/application/src/test/java/org/opentripplanner/updater/trip/gtfs/GtfsRealTimeTripUpdateAdapterTest.java b/application/src/test/java/org/opentripplanner/updater/trip/gtfs/GtfsRealTimeTripUpdateAdapterTest.java index f9dfb24c636..4a2f37e0ecf 100644 --- a/application/src/test/java/org/opentripplanner/updater/trip/gtfs/GtfsRealTimeTripUpdateAdapterTest.java +++ b/application/src/test/java/org/opentripplanner/updater/trip/gtfs/GtfsRealTimeTripUpdateAdapterTest.java @@ -5,7 +5,9 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.id; import static org.opentripplanner.updater.trip.UpdateIncrementality.DIFFERENTIAL; import static org.opentripplanner.updater.trip.gtfs.BackwardsDelayPropagationType.REQUIRED_NO_DATA; @@ -202,35 +204,25 @@ public void testHandleModifiedTrip() { assertNotSame(originalTimetableForToday, originalTimetableScheduled); - final int originalTripIndexScheduled = originalTimetableScheduled.getTripIndex( - modifiedTripId - ); - assertTrue( - originalTripIndexScheduled > -1, - "Original trip should be found in scheduled time table" - ); - final TripTimes originalTripTimesScheduled = originalTimetableScheduled.getTripTimes( - originalTripIndexScheduled + var original = originalTimetableScheduled.getTripTimes( + new FeedScopedId(feedId, modifiedTripId) ); + assertNotNull(original, "Original trip should be found in scheduled time table"); assertFalse( - originalTripTimesScheduled.isCanceledOrDeleted(), + original.isCanceledOrDeleted(), "Original trip times should not be canceled in scheduled time table" ); - assertEquals(RealTimeState.SCHEDULED, originalTripTimesScheduled.getRealTimeState()); + assertEquals(RealTimeState.SCHEDULED, original.getRealTimeState()); - final int originalTripIndexForToday = originalTimetableForToday.getTripIndex(modifiedTripId); - assertTrue( - originalTripIndexForToday > -1, - "Original trip should be found in time table for service date" - ); - final TripTimes originalTripTimesForToday = originalTimetableForToday.getTripTimes( - originalTripIndexForToday + var originalTT = originalTimetableForToday.getTripTimes( + new FeedScopedId(feedId, modifiedTripId) ); + assertNotNull(originalTT, "Original trip should be found in time table for service date"); assertTrue( - originalTripTimesForToday.isDeleted(), + originalTT.isDeleted(), "Original trip times should be deleted in time table for service date" ); - assertEquals(RealTimeState.DELETED, originalTripTimesForToday.getRealTimeState()); + assertEquals(RealTimeState.DELETED, originalTT.getRealTimeState()); } // New trip pattern @@ -246,21 +238,12 @@ public void testHandleModifiedTrip() { assertNotSame(newTimetableForToday, newTimetableScheduled); - final int newTimetableForTodayModifiedTripIndex = newTimetableForToday.getTripIndex( - modifiedTripId - ); - assertTrue( - newTimetableForTodayModifiedTripIndex > -1, - "New trip should be found in time table for service date" - ); - assertEquals( - RealTimeState.MODIFIED, - newTimetableForToday.getTripTimes(newTimetableForTodayModifiedTripIndex).getRealTimeState() - ); + var tripTimes = newTimetableForToday.getTripTimes(new FeedScopedId(feedId, modifiedTripId)); + assertNotNull(tripTimes, "New trip should be found in time table for service date"); + assertEquals(RealTimeState.MODIFIED, tripTimes.getRealTimeState()); - assertEquals( - -1, - newTimetableScheduled.getTripIndex(modifiedTripId), + assertNull( + newTimetableScheduled.getTripTimes(id(modifiedTripId)), "New trip should not be found in scheduled time table" ); } diff --git a/application/src/test/java/org/opentripplanner/updater/trip/gtfs/TripTimesUpdaterTest.java b/application/src/test/java/org/opentripplanner/updater/trip/gtfs/TripTimesUpdaterTest.java index 8528487a662..bff36633956 100644 --- a/application/src/test/java/org/opentripplanner/updater/trip/gtfs/TripTimesUpdaterTest.java +++ b/application/src/test/java/org/opentripplanner/updater/trip/gtfs/TripTimesUpdaterTest.java @@ -47,7 +47,7 @@ public class TripTimesUpdaterTest { private static Map patternIndex; private static Timetable timetable; private static String feedId; - private static int trip_1_1_index; + private static FeedScopedId tripId; @BeforeAll public static void setUp() throws Exception { @@ -61,9 +61,9 @@ public static void setUp() throws Exception { pattern.scheduledTripsAsStream().forEach(trip -> patternIndex.put(trip.getId(), pattern)); } - TripPattern pattern = patternIndex.get(new FeedScopedId(feedId, TRIP_ID)); + tripId = new FeedScopedId(feedId, TRIP_ID); + TripPattern pattern = patternIndex.get(tripId); timetable = pattern.getScheduledTimetable(); - trip_1_1_index = timetable.getTripIndex(new FeedScopedId(feedId, TRIP_ID)); } @Test @@ -173,7 +173,7 @@ public void update() { .toEpochSecond() ); var tripUpdate = tripUpdateBuilder.build(); - assertEquals(20 * 60, timetable.getTripTimes(trip_1_1_index).getArrivalTime(2)); + assertEquals(20 * 60, timetable.getTripTimes(tripId).getArrivalTime(2)); var result = TripTimesUpdater.createUpdatedTripTimesFromGTFSRT( timetable, tripUpdate, @@ -188,7 +188,7 @@ public void update() { var updatedTripTimes = p.getTripTimes(); assertNotNull(updatedTripTimes); timetable = timetable.copyOf().addOrUpdateTripTimes(updatedTripTimes).build(); - assertEquals(20 * 60 + 120, timetable.getTripTimes(trip_1_1_index).getArrivalTime(2)); + assertEquals(20 * 60 + 120, timetable.getTripTimes(tripId).getArrivalTime(2)); }); // update trip arrival time incorrectly diff --git a/application/src/test/java/org/opentripplanner/updater/trip/gtfs/moduletests/addition/AddedTest.java b/application/src/test/java/org/opentripplanner/updater/trip/gtfs/moduletests/addition/AddedTest.java index 0d5e620efde..3fdcc0c0f17 100644 --- a/application/src/test/java/org/opentripplanner/updater/trip/gtfs/moduletests/addition/AddedTest.java +++ b/application/src/test/java/org/opentripplanner/updater/trip/gtfs/moduletests/addition/AddedTest.java @@ -2,10 +2,13 @@ import static com.google.transit.realtime.GtfsRealtime.TripDescriptor.ScheduleRelationship.ADDED; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.id; import static org.opentripplanner.updater.spi.UpdateResultAssertions.assertSuccess; import de.mfdz.MfdzRealtimeExtensions.StopTimePropertiesExtension.DropOffPickupType; @@ -128,12 +131,10 @@ private TripPattern assertAddedTrip(String tripId, RealtimeTestEnvironment env) var snapshot = env.getTimetableSnapshot(); TransitService transitService = env.getTransitService(); - Trip trip = transitService.getTrip(TimetableRepositoryForTest.id(ADDED_TRIP_ID)); + Trip trip = transitService.getTrip(id(ADDED_TRIP_ID)); assertNotNull(trip); assertNotNull(transitService.findPattern(trip)); - assertNotNull( - transitService.getTripOnServiceDate(TimetableRepositoryForTest.id(ADDED_TRIP_ID)) - ); + assertNotNull(transitService.getTripOnServiceDate(id(ADDED_TRIP_ID))); var stopA = env.timetableRepository.getSiteRepository().getRegularStop(STOP_A1.getId()); // Get the trip pattern of the added trip which goes through stopA @@ -148,18 +149,12 @@ private TripPattern assertAddedTrip(String tripId, RealtimeTestEnvironment env) assertNotSame(forToday, schedule); - final int forTodayAddedTripIndex = forToday.getTripIndex(tripId); - assertTrue( - forTodayAddedTripIndex > -1, - "Added trip should be found in time table for service date" - ); - assertEquals( - RealTimeState.ADDED, - forToday.getTripTimes(forTodayAddedTripIndex).getRealTimeState() - ); + var tripTimes = forToday.getTripTimes(id(tripId)); + assertNotNull(tripTimes, "Added trip should be found in time table for service date"); + assertEquals(RealTimeState.ADDED, tripTimes.getRealTimeState()); - final int scheduleTripIndex = schedule.getTripIndex(tripId); - assertEquals(-1, scheduleTripIndex, "Added trip should not be found in scheduled time table"); + var scheduledTripTimes = schedule.getTripTimes(id(tripId)); + assertNull(scheduledTripTimes, "Added trip should not be found in scheduled time table"); return tripPattern; } } diff --git a/application/src/test/java/org/opentripplanner/updater/trip/gtfs/moduletests/cancellation/CancellationDeletionTest.java b/application/src/test/java/org/opentripplanner/updater/trip/gtfs/moduletests/cancellation/CancellationDeletionTest.java index f29c1a0bd2c..2a30a7380cf 100644 --- a/application/src/test/java/org/opentripplanner/updater/trip/gtfs/moduletests/cancellation/CancellationDeletionTest.java +++ b/application/src/test/java/org/opentripplanner/updater/trip/gtfs/moduletests/cancellation/CancellationDeletionTest.java @@ -3,6 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.id; import static org.opentripplanner.updater.spi.UpdateResultAssertions.assertSuccess; @@ -45,8 +46,6 @@ void cancelledTrip(ScheduleRelationship relationship, RealTimeState state) { .build(); var pattern1 = env.getPatternForTrip(TRIP_1_ID); - final int tripIndex1 = pattern1.getScheduledTimetable().getTripIndex(id(TRIP_1_ID)); - var update = new TripUpdateBuilder(TRIP_1_ID, SERVICE_DATE, relationship, TIME_ZONE).build(); assertSuccess(env.applyTripUpdate(update)); @@ -54,9 +53,9 @@ void cancelledTrip(ScheduleRelationship relationship, RealTimeState state) { var forToday = snapshot.resolve(pattern1, SERVICE_DATE); var schedule = snapshot.resolve(pattern1, null); assertNotSame(forToday, schedule); - assertNotSame(forToday.getTripTimes(tripIndex1), schedule.getTripTimes(tripIndex1)); + assertNotSame(forToday.getTripTimes(id(TRIP_1_ID)), schedule.getTripTimes(id(TRIP_1_ID))); - var tripTimes = forToday.getTripTimes(tripIndex1); + var tripTimes = forToday.getTripTimes(id(TRIP_1_ID)); assertEquals(state, tripTimes.getRealTimeState()); assertTrue(tripTimes.isCanceledOrDeleted()); @@ -107,14 +106,14 @@ void cancelingAddedTrip(ScheduleRelationship relationship, RealTimeState state) assertNotSame(forToday, schedule); - final int forTodayAddedTripIndex = forToday.getTripIndex(addedTripId); - assertTrue( - forTodayAddedTripIndex > -1, + var realtimeTripTimes = forToday.getTripTimes(id(addedTripId)); + assertNotNull( + realtimeTripTimes, "Added trip should be found in time table for the service date" ); - assertEquals(state, forToday.getTripTimes(forTodayAddedTripIndex).getRealTimeState()); + assertEquals(state, realtimeTripTimes.getRealTimeState()); - final int scheduleTripIndex = schedule.getTripIndex(addedTripId); - assertEquals(-1, scheduleTripIndex, "Added trip should not be found in scheduled time table"); + var scheduledTripTimes = schedule.getTripTimes(id(addedTripId)); + assertNull(scheduledTripTimes, "Added trip should not be found in scheduled time table"); } } diff --git a/application/src/test/java/org/opentripplanner/updater/trip/gtfs/moduletests/delay/DelayedTest.java b/application/src/test/java/org/opentripplanner/updater/trip/gtfs/moduletests/delay/DelayedTest.java index 06ce474f4ec..62e2c242b82 100644 --- a/application/src/test/java/org/opentripplanner/updater/trip/gtfs/moduletests/delay/DelayedTest.java +++ b/application/src/test/java/org/opentripplanner/updater/trip/gtfs/moduletests/delay/DelayedTest.java @@ -3,12 +3,15 @@ import static com.google.transit.realtime.GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.id; +import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.trip; import static org.opentripplanner.updater.spi.UpdateResultAssertions.assertSuccess; import org.junit.jupiter.api.Test; +import org.opentripplanner.transit.model.framework.FeedScopedId; import org.opentripplanner.transit.model.timetable.RealTimeState; import org.opentripplanner.updater.trip.RealtimeTestConstants; import org.opentripplanner.updater.trip.RealtimeTestEnvironment; @@ -22,6 +25,7 @@ class DelayedTest implements RealtimeTestConstants { private static final int DELAY = 1; private static final int STOP_SEQUENCE = 1; + private static final FeedScopedId TRIP_ID = id(TRIP_1_ID); @Test void singleStopDelay() { @@ -40,21 +44,17 @@ void singleStopDelay() { assertEquals(1, result.successful()); var pattern1 = env.getPatternForTrip(TRIP_1_ID); - int trip1Index = pattern1.getScheduledTimetable().getTripIndex(id(TRIP_1_ID)); var snapshot = env.getTimetableSnapshot(); var trip1Realtime = snapshot.resolve(pattern1, SERVICE_DATE); var trip1Scheduled = snapshot.resolve(pattern1, null); assertNotSame(trip1Realtime, trip1Scheduled); - assertNotSame(trip1Realtime.getTripTimes(trip1Index), trip1Scheduled.getTripTimes(trip1Index)); - assertEquals(DELAY, trip1Realtime.getTripTimes(trip1Index).getArrivalDelay(STOP_SEQUENCE)); - assertEquals(DELAY, trip1Realtime.getTripTimes(trip1Index).getDepartureDelay(STOP_SEQUENCE)); + assertNotSame(trip1Realtime.getTripTimes(TRIP_ID), trip1Scheduled.getTripTimes(TRIP_ID)); + assertEquals(DELAY, trip1Realtime.getTripTimes(TRIP_ID).getArrivalDelay(STOP_SEQUENCE)); + assertEquals(DELAY, trip1Realtime.getTripTimes(TRIP_ID).getDepartureDelay(STOP_SEQUENCE)); - assertEquals( - RealTimeState.SCHEDULED, - trip1Scheduled.getTripTimes(trip1Index).getRealTimeState() - ); + assertEquals(RealTimeState.SCHEDULED, trip1Scheduled.getTripTimes(TRIP_ID).getRealTimeState()); assertEquals( "SCHEDULED | A1 0:00:10 0:00:11 | B1 0:00:20 0:00:21", @@ -96,25 +96,16 @@ void complexDelay() { assertNotSame(originalTimetableForToday, originalTimetableScheduled); - final int originalTripIndexScheduled = originalTimetableScheduled.getTripIndex(TRIP_2_ID); - assertTrue( - originalTripIndexScheduled > -1, - "Original trip should be found in scheduled time table" - ); - var originalTripTimesScheduled = originalTimetableScheduled.getTripTimes( - originalTripIndexScheduled - ); + var tripTimes = originalTimetableScheduled.getTripTimes(id(TRIP_2_ID)); + assertNotNull(tripTimes, "Original trip should be found in scheduled time table"); assertFalse( - originalTripTimesScheduled.isCanceledOrDeleted(), + tripTimes.isCanceledOrDeleted(), "Original trip times should not be canceled in scheduled time table" ); - assertEquals(RealTimeState.SCHEDULED, originalTripTimesScheduled.getRealTimeState()); + assertEquals(RealTimeState.SCHEDULED, tripTimes.getRealTimeState()); - final int originalTripIndexForToday = originalTimetableForToday.getTripIndex(TRIP_2_ID); - assertTrue( - originalTripIndexForToday > -1, - "Original trip should be found in time table for service date" - ); + var realtimeTt = originalTimetableForToday.getTripTimes(id(TRIP_2_ID)); + assertNotNull(realtimeTt, "Original trip should be found in time table for service date"); assertEquals( "SCHEDULED | A1 0:01 0:01:01 | B1 0:01:10 0:01:11 | C1 0:01:20 0:01:21", diff --git a/application/src/test/java/org/opentripplanner/updater/trip/gtfs/moduletests/delay/SkippedTest.java b/application/src/test/java/org/opentripplanner/updater/trip/gtfs/moduletests/delay/SkippedTest.java index 0cfabfcd4c6..e9971c661eb 100644 --- a/application/src/test/java/org/opentripplanner/updater/trip/gtfs/moduletests/delay/SkippedTest.java +++ b/application/src/test/java/org/opentripplanner/updater/trip/gtfs/moduletests/delay/SkippedTest.java @@ -3,6 +3,7 @@ import static com.google.transit.realtime.GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -140,38 +141,29 @@ private static void assertOriginalTripPatternIsDeleted( assertNotSame(originalTimetableForToday, originalTimetableScheduled); - int originalTripIndexScheduled = originalTimetableScheduled.getTripIndex(tripId); - assertTrue( - originalTripIndexScheduled > -1, - "Original trip should be found in scheduled time table" - ); - var originalTripTimesScheduled = originalTimetableScheduled.getTripTimes( - originalTripIndexScheduled - ); + var tripTimes = originalTimetableScheduled.getTripTimes(id(tripId)); + assertNotNull(tripTimes, "Original trip should be found in scheduled time table"); assertFalse( - originalTripTimesScheduled.isCanceledOrDeleted(), + tripTimes.isCanceledOrDeleted(), "Original trip times should not be canceled in scheduled time table" ); assertEquals( "SCHEDULED | A1 0:01 0:01:01 | B1 0:01:10 0:01:11 | C1 0:01:20 0:01:21", - TripTimesStringBuilder.encodeTripTimes(originalTripTimesScheduled, originalTripPattern) + TripTimesStringBuilder.encodeTripTimes(tripTimes, originalTripPattern) ); - int originalTripIndexForToday = originalTimetableForToday.getTripIndex(tripId); - assertTrue( - originalTripIndexForToday > -1, + var scheduledTripTimes = originalTimetableForToday.getTripTimes(id(tripId)); + assertNotNull( + scheduledTripTimes, "Original trip should be found in time table for service date" ); - var originalTripTimesForToday = originalTimetableForToday.getTripTimes( - originalTripIndexForToday - ); assertTrue( - originalTripTimesForToday.isDeleted(), + scheduledTripTimes.isDeleted(), "Original trip times should be deleted in time table for service date" ); // original trip should be deleted - assertEquals(RealTimeState.DELETED, originalTripTimesForToday.getRealTimeState()); + assertEquals(RealTimeState.DELETED, scheduledTripTimes.getRealTimeState()); } private static void assertNewTripTimesIsUpdated(RealtimeTestEnvironment env, String tripId) { @@ -184,25 +176,16 @@ private static void assertNewTripTimesIsUpdated(RealtimeTestEnvironment env, Str assertNotSame(originalTimetableForToday, originalTimetableScheduled); - int originalTripIndexScheduled = originalTimetableScheduled.getTripIndex(tripId); + var tripTimes = originalTimetableScheduled.getTripTimes(id(tripId)); - assertTrue( - originalTripIndexScheduled > -1, - "Original trip should be found in scheduled time table" - ); - var originalTripTimesScheduled = originalTimetableScheduled.getTripTimes( - originalTripIndexScheduled - ); + assertNotNull(tripTimes, "Original trip should be found in scheduled time table"); assertFalse( - originalTripTimesScheduled.isCanceledOrDeleted(), + tripTimes.isCanceledOrDeleted(), "Original trip times should not be canceled in scheduled time table" ); - assertEquals(RealTimeState.SCHEDULED, originalTripTimesScheduled.getRealTimeState()); - int originalTripIndexForToday = originalTimetableForToday.getTripIndex(tripId); + assertEquals(RealTimeState.SCHEDULED, tripTimes.getRealTimeState()); + var tt = originalTimetableForToday.getTripTimes(id(tripId)); - assertTrue( - originalTripIndexForToday > -1, - "Original trip should be found in time table for service date" - ); + assertNotNull(tt, "Original trip should be found in time table for service date"); } }