Skip to content

Commit

Permalink
refactor(exceptions): inline exceptions filtering for For loop
Browse files Browse the repository at this point in the history
  • Loading branch information
philip-cline committed Jul 12, 2023
1 parent 677ba68 commit e51456e
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/main/java/com/conveyal/gtfs/loader/JdbcGtfsExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ public JdbcGtfsExporter(String feedId, String outFile, DataSource dataSource, bo
this.fromEditor = fromEditor;
}

/**
* Utility method to check if an exception uses a specific service.
*/
public Boolean exceptionInvolvesService(ScheduleException ex, String serviceId) {
return (
ex.addedService.contains(serviceId) ||
ex.removedService.contains(serviceId) ||
ex.customSchedule.contains(serviceId)
);
}

/**
* Export primary entity tables as well as Pattern and PatternStops tables.
*
Expand Down Expand Up @@ -136,12 +147,10 @@ public FeedLoadResult exportTables() {
for (Calendar cal : calendars) {
Service service = new Service(cal.service_id);
service.calendar = cal;
List<ScheduleException> calendarExceptions = exceptions.stream().filter(ex ->
ex.addedService.contains(cal.service_id) ||
ex.removedService.contains(cal.service_id) ||
ex.customSchedule.contains(cal.service_id)
).collect(Collectors.toList());
for (ScheduleException ex : calendarExceptions) {
for (ScheduleException ex : exceptions.stream()
.filter(ex -> exceptionInvolvesService(ex, cal.service_id))
.collect(Collectors.toList())
) {
if (ex.exemplar.equals(ScheduleException.ExemplarServiceDescriptor.SWAP) &&
(!ex.addedService.contains(cal.service_id) && !ex.removedService.contains(cal.service_id))) {
// Skip swap exception if cal is not referenced by added or removed service.
Expand Down

0 comments on commit e51456e

Please sign in to comment.