Skip to content

Commit

Permalink
Reorder methods
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Jun 1, 2024
1 parent dfcba06 commit 0a03b98
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.opentripplanner.DateTimeHelper;
Expand Down Expand Up @@ -156,20 +157,6 @@ public String getFeedId() {
return TransitModelForTest.FEED_ID;
}

public UpdateResult applyTripUpdates(GtfsRealtime.TripUpdate update) {
return applyTripUpdates(List.of(update));
}

public UpdateResult applyTripUpdates(List<GtfsRealtime.TripUpdate> updates) {
return gtfsSource.applyTripUpdates(
null,
BackwardsDelayPropagationType.REQUIRED_NO_DATA,
true,
updates,
getFeedId()
);
}

public EntityResolver getEntityResolver() {
return new EntityResolver(getTransitService(), getFeedId());
}
Expand Down Expand Up @@ -198,6 +185,31 @@ public TripTimes getTripTimesForTrip(String id) {
return getTripTimesForTrip(id(id), SERVICE_DATE);
}

public DateTimeHelper getDateTimeHelper() {
return dateTimeHelper;
}

public TripPattern getPatternForTrip(Trip trip) {
return transitModel.getTransitModelIndex().getPatternForTrip().get(trip);
}

public TimetableSnapshot getTimetableSnapshot() {
if (siriSource != null) {
return siriSource.getTimetableSnapshot();
} else {
return gtfsSource.getTimetableSnapshot();
}
}

// SIRI updates

public UpdateResult applyEstimatedTimetableWithFuzzyMatcher(
List<EstimatedTimetableDeliveryStructure> updates
) {
SiriFuzzyTripMatcher siriFuzzyTripMatcher = new SiriFuzzyTripMatcher(getTransitService());
return applyEstimatedTimetable(updates, siriFuzzyTripMatcher);
}

public UpdateResult applyEstimatedTimetable(List<EstimatedTimetableDeliveryStructure> updates) {
return siriSource.applyEstimatedTimetable(
null,
Expand All @@ -208,21 +220,30 @@ public UpdateResult applyEstimatedTimetable(List<EstimatedTimetableDeliveryStruc
);
}

public UpdateResult applyEstimatedTimetableWithFuzzyMatcher(
List<EstimatedTimetableDeliveryStructure> updates
) {
SiriFuzzyTripMatcher siriFuzzyTripMatcher = new SiriFuzzyTripMatcher(getTransitService());
return applyEstimatedTimetable(updates, siriFuzzyTripMatcher);
// GTFS-RT updates

public UpdateResult applyTripUpdate(GtfsRealtime.TripUpdate update) {
return applyTripUpdates(List.of(update));
}

public DateTimeHelper getDateTimeHelper() {
return dateTimeHelper;
public UpdateResult applyTripUpdates(List<GtfsRealtime.TripUpdate> updates) {
Objects.requireNonNull(gtfsSource, "Test environment is configured for SIRI only");
return gtfsSource.applyTripUpdates(
null,
BackwardsDelayPropagationType.REQUIRED_NO_DATA,
true,
updates,
getFeedId()
);
}

// private methods

private UpdateResult applyEstimatedTimetable(
List<EstimatedTimetableDeliveryStructure> updates,
SiriFuzzyTripMatcher siriFuzzyTripMatcher
) {
Objects.requireNonNull(siriSource, "Test environment is configured for GTFS-RT only");
return siriSource.applyEstimatedTimetable(
siriFuzzyTripMatcher,
getEntityResolver(),
Expand All @@ -232,20 +253,6 @@ private UpdateResult applyEstimatedTimetable(
);
}

public TripPattern getPatternForTrip(Trip trip) {
return transitModel.getTransitModelIndex().getPatternForTrip().get(trip);
}

public TimetableSnapshot getTimetableSnapshot() {
if (siriSource != null) {
return siriSource.getTimetableSnapshot();
} else {
return gtfsSource.getTimetableSnapshot();
}
}

// private methods

private Trip createTrip(String id, Route route, List<Stop> stops) {
var trip = Trip.of(id(id)).withRoute(route).withServiceId(CAL_ID).build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void cancelledTrip(ScheduleRelationship relationship, RealTimeState state
env.timeZone
)
.build();
var result = env.applyTripUpdates(update);
var result = env.applyTripUpdate(update);

assertEquals(1, result.successful());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void delayed() {
.addDelayedStopTime(STOP_SEQUENCE, DELAY)
.build();

var result = env.applyTripUpdates(tripUpdate);
var result = env.applyTripUpdate(tripUpdate);

assertEquals(1, result.successful());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void scheduledTripWithSkippedAndScheduled() {
.addDelayedStopTime(2, 90)
.build();

var result = env.applyTripUpdates(tripUpdate);
var result = env.applyTripUpdate(tripUpdate);

assertEquals(1, result.successful());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void invalidTripDate(LocalDate date) {
.addDelayedStopTime(3, 90, 90)
.build();

var result = env.applyTripUpdates(update);
var result = env.applyTripUpdate(update);

var snapshot = env.getTimetableSnapshot();
assertTrue(snapshot.isEmpty());
Expand Down

0 comments on commit 0a03b98

Please sign in to comment.