|
| 1 | +package org.mobilitydata.gtfsvalidator.validator; |
| 2 | + |
| 3 | +import static org.mobilitydata.gtfsvalidator.notice.SeverityLevel.ERROR; |
| 4 | + |
| 5 | +import javax.inject.Inject; |
| 6 | +import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice; |
| 7 | +import org.mobilitydata.gtfsvalidator.annotation.GtfsValidator; |
| 8 | +import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; |
| 9 | +import org.mobilitydata.gtfsvalidator.notice.ValidationNotice; |
| 10 | +import org.mobilitydata.gtfsvalidator.table.*; |
| 11 | +import org.mobilitydata.gtfsvalidator.type.GtfsTime; |
| 12 | + |
| 13 | +/** |
| 14 | + * Validates that if `routes.continuous_pickup` or `routes.continuous_drop_off` are included, then |
| 15 | + * `stop_times.start_pickup_drop_off_window` or `stop_times.end_pickup_drop_off_window` are not |
| 16 | + * defined for any trip of this route. |
| 17 | + * |
| 18 | + * <p>Generated notice: {@link ForbiddenContinuousPickupDropOffNotice}. |
| 19 | + */ |
| 20 | +@GtfsValidator |
| 21 | +public class ContinuousPickupDropOffValidator extends FileValidator { |
| 22 | + private final GtfsRouteTableContainer routeTable; |
| 23 | + private final GtfsTripTableContainer tripTable; |
| 24 | + private final GtfsStopTimeTableContainer stopTimeTable; |
| 25 | + |
| 26 | + @Inject |
| 27 | + public ContinuousPickupDropOffValidator( |
| 28 | + GtfsRouteTableContainer routeTable, |
| 29 | + GtfsTripTableContainer tripTable, |
| 30 | + GtfsStopTimeTableContainer stopTimeTable) { |
| 31 | + this.routeTable = routeTable; |
| 32 | + this.tripTable = tripTable; |
| 33 | + this.stopTimeTable = stopTimeTable; |
| 34 | + } |
| 35 | + |
| 36 | + @Override |
| 37 | + public void validate(NoticeContainer noticeContainer) { |
| 38 | + for (GtfsRoute route : routeTable.getEntities()) { |
| 39 | + boolean continuous = |
| 40 | + (route.continuousPickup() == GtfsContinuousPickupDropOff.ALLOWED |
| 41 | + || route.continuousPickup() == GtfsContinuousPickupDropOff.MUST_PHONE |
| 42 | + || route.continuousPickup() == GtfsContinuousPickupDropOff.ON_REQUEST_TO_DRIVER) |
| 43 | + || (route.continuousDropOff() == GtfsContinuousPickupDropOff.ALLOWED |
| 44 | + || route.continuousDropOff() == GtfsContinuousPickupDropOff.MUST_PHONE |
| 45 | + || route.continuousDropOff() == GtfsContinuousPickupDropOff.ON_REQUEST_TO_DRIVER); |
| 46 | + if (!continuous) { |
| 47 | + continue; |
| 48 | + } |
| 49 | + for (GtfsTrip trip : tripTable.byRouteId(route.routeId())) { |
| 50 | + for (GtfsStopTime stopTime : stopTimeTable.byTripId(trip.tripId())) { |
| 51 | + if (stopTime.hasStartPickupDropOffWindow() || stopTime.hasEndPickupDropOffWindow()) { |
| 52 | + noticeContainer.addValidationNotice( |
| 53 | + new ForbiddenContinuousPickupDropOffNotice( |
| 54 | + route.csvRowNumber(), |
| 55 | + trip.tripId(), |
| 56 | + stopTime.startPickupDropOffWindow(), |
| 57 | + stopTime.endPickupDropOffWindow())); |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Continuous pickup or drop-off are forbidden when routes.continuous_pickup or |
| 66 | + * routes.continuous_drop_off are 0, 2 or 3 and stop_times.start_pickup_drop_off_window or |
| 67 | + * stop_times.end_pickup_drop_off_window are defined for any trip of this route. |
| 68 | + */ |
| 69 | + @GtfsValidationNotice(severity = ERROR) |
| 70 | + public static class ForbiddenContinuousPickupDropOffNotice extends ValidationNotice { |
| 71 | + /** The row number of the route in the CSV file. */ |
| 72 | + private final int routeCsvRowNumber; |
| 73 | + |
| 74 | + /** The ID of the trip. */ |
| 75 | + private final String tripId; |
| 76 | + |
| 77 | + /** The start time of the pickup/drop-off window. */ |
| 78 | + private final GtfsTime startPickupDropOffWindow; |
| 79 | + |
| 80 | + /** The end time of the pickup/drop-off window. */ |
| 81 | + private final GtfsTime endPickupDropOffWindow; |
| 82 | + |
| 83 | + public ForbiddenContinuousPickupDropOffNotice( |
| 84 | + int routeCsvRowNumber, |
| 85 | + String tripId, |
| 86 | + GtfsTime startPickupDropOffWindow, |
| 87 | + GtfsTime endPickupDropOffWindow) { |
| 88 | + this.routeCsvRowNumber = routeCsvRowNumber; |
| 89 | + this.tripId = tripId; |
| 90 | + this.startPickupDropOffWindow = startPickupDropOffWindow; |
| 91 | + this.endPickupDropOffWindow = endPickupDropOffWindow; |
| 92 | + } |
| 93 | + } |
| 94 | +} |
0 commit comments