Skip to content

Commit

Permalink
formatted code
Browse files Browse the repository at this point in the history
  • Loading branch information
qcdyx committed Jan 7, 2025
1 parent 964e155 commit 884d3bb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,38 +1,50 @@
package org.mobilitydata.gtfsvalidator.validator;

import static org.mobilitydata.gtfsvalidator.notice.SeverityLevel.ERROR;

import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidator;
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
import org.mobilitydata.gtfsvalidator.notice.ValidationNotice;
import org.mobilitydata.gtfsvalidator.table.GtfsPickupDropOff;
import org.mobilitydata.gtfsvalidator.table.GtfsStopTime;
import org.mobilitydata.gtfsvalidator.type.GtfsTime;

import static org.mobilitydata.gtfsvalidator.notice.SeverityLevel.ERROR;

/**
* Validates that the `start_pickup_drop_off_window` or `end_pickup_drop_off_window` fields are not
* set when the `pickup_type` is regularly scheduled (0) or must be coordinated with the driver (3),
* and that these fields are not set when the `drop_off_type` is regularly scheduled (0).
*
* <p>Generated notices include: - {@link ForbiddenPickupTypeNotice} - {@link
* ForbiddenDropOffTypeNotice} if the `drop_off_type` is invalid.
*/
@GtfsValidator
public class PickupDropOffTypeValidator extends SingleEntityValidator<GtfsStopTime> {
@Override
public void validate(GtfsStopTime entity, NoticeContainer noticeContainer) {
if ((entity.hasStartPickupDropOffWindow() || entity.hasEndPickupDropOffWindow()) &&
(entity.pickupType().equals(GtfsPickupDropOff.ALLOWED) || entity.pickupType().equals(GtfsPickupDropOff.ON_REQUEST_TO_DRIVER))) {
if ((entity.hasStartPickupDropOffWindow() || entity.hasEndPickupDropOffWindow())
&& (entity.pickupType().equals(GtfsPickupDropOff.ALLOWED)
|| entity.pickupType().equals(GtfsPickupDropOff.ON_REQUEST_TO_DRIVER))) {
noticeContainer.addValidationNotice(
new ForbiddenPickupTypeNotice(
entity.csvRowNumber(),
entity.startPickupDropOffWindow(),
entity.endPickupDropOffWindow()));
new ForbiddenPickupTypeNotice(
entity.csvRowNumber(),
entity.startPickupDropOffWindow(),
entity.endPickupDropOffWindow()));
}

if ((entity.hasStartPickupDropOffWindow() || entity.hasEndPickupDropOffWindow()) &&
entity.dropOffType().equals(GtfsPickupDropOff.ALLOWED)) {
if ((entity.hasStartPickupDropOffWindow() || entity.hasEndPickupDropOffWindow())
&& entity.dropOffType().equals(GtfsPickupDropOff.ALLOWED)) {
noticeContainer.addValidationNotice(
new ForbiddenDropOffTypeNotice(
entity.csvRowNumber(),
entity.startPickupDropOffWindow(),
entity.endPickupDropOffWindow()));
new ForbiddenDropOffTypeNotice(
entity.csvRowNumber(),
entity.startPickupDropOffWindow(),
entity.endPickupDropOffWindow()));
}
}

/**
* pickup_drop_off_window fields are forbidden when the pickup_type is regularly scheduled (0) or must be coordinated with the driver (3).
* pickup_drop_off_window fields are forbidden when the pickup_type is regularly scheduled (0) or
* must be coordinated with the driver (3).
*/
@GtfsValidationNotice(severity = ERROR)
public static class ForbiddenPickupTypeNotice extends ValidationNotice {
Expand All @@ -45,7 +57,8 @@ public static class ForbiddenPickupTypeNotice extends ValidationNotice {
/** The end pickup drop off window of the faulty record. */
private final GtfsTime endPickupDropOffWindow;

public ForbiddenPickupTypeNotice(int csvRowNumber, GtfsTime startPickupDropOffWindow, GtfsTime endPickupDropOffWindow) {
public ForbiddenPickupTypeNotice(
int csvRowNumber, GtfsTime startPickupDropOffWindow, GtfsTime endPickupDropOffWindow) {
this.csvRowNumber = csvRowNumber;
this.startPickupDropOffWindow = startPickupDropOffWindow;
this.endPickupDropOffWindow = endPickupDropOffWindow;
Expand All @@ -66,12 +79,11 @@ public static class ForbiddenDropOffTypeNotice extends ValidationNotice {
/** The end pickup drop off window of the faulty record. */
private final GtfsTime endPickupDropOffWindow;

public ForbiddenDropOffTypeNotice(int csvRowNumber, GtfsTime startPickupDropOffWindow, GtfsTime endPickupDropOffWindow) {
public ForbiddenDropOffTypeNotice(
int csvRowNumber, GtfsTime startPickupDropOffWindow, GtfsTime endPickupDropOffWindow) {
this.csvRowNumber = csvRowNumber;
this.startPickupDropOffWindow = startPickupDropOffWindow;
this.endPickupDropOffWindow = endPickupDropOffWindow;
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,24 @@ private static List<ValidationNotice> generateNotices(GtfsStopTime stopTime) {

@Test
public void forbiddenDropOffTypeShouldGenerateNotice() {
GtfsStopTime stopTime = new GtfsStopTime.Builder()
GtfsStopTime stopTime =
new GtfsStopTime.Builder()
.setCsvRowNumber(1)
.setPickupType(GtfsPickupDropOff.NOT_AVAILABLE)
.setDropOffType(GtfsPickupDropOff.ALLOWED)
.setStartPickupDropOffWindow(GtfsTime.fromString("00:00:02"))
.setEndPickupDropOffWindow(GtfsTime.fromString("00:00:03"))
.build();
assertThat(generateNotices(stopTime)).containsExactly(
new PickupDropOffTypeValidator.ForbiddenDropOffTypeNotice(1, GtfsTime.fromString("00:00:02"), GtfsTime.fromString("00:00:03")));
assertThat(generateNotices(stopTime))
.containsExactly(
new PickupDropOffTypeValidator.ForbiddenDropOffTypeNotice(
1, GtfsTime.fromString("00:00:02"), GtfsTime.fromString("00:00:03")));
}

@Test
public void allowedDropOffTypeShouldNotGenerateNotice() {
GtfsStopTime stopTime = new GtfsStopTime.Builder()
GtfsStopTime stopTime =
new GtfsStopTime.Builder()
.setCsvRowNumber(2)
.setDropOffType(GtfsPickupDropOff.NOT_AVAILABLE)
.build();
Expand All @@ -46,23 +50,27 @@ public void allowedDropOffTypeShouldNotGenerateNotice() {

@Test
public void forbiddenPickupTypeShouldGenerateNotice() {
GtfsStopTime stopTime = new GtfsStopTime.Builder()
GtfsStopTime stopTime =
new GtfsStopTime.Builder()
.setCsvRowNumber(3)
.setPickupType(GtfsPickupDropOff.ALLOWED)
.setDropOffType(GtfsPickupDropOff.NOT_AVAILABLE)
.setStartPickupDropOffWindow(GtfsTime.fromString("08:00:00"))
.setEndPickupDropOffWindow(GtfsTime.fromString("09:00:00"))
.build();
assertThat(generateNotices(stopTime)).containsExactly(
new PickupDropOffTypeValidator.ForbiddenPickupTypeNotice(3, GtfsTime.fromString("08:00:00"), GtfsTime.fromString("09:00:00")));
assertThat(generateNotices(stopTime))
.containsExactly(
new PickupDropOffTypeValidator.ForbiddenPickupTypeNotice(
3, GtfsTime.fromString("08:00:00"), GtfsTime.fromString("09:00:00")));
}

@Test
public void allowedPickupTypeShouldNotGenerateNotice() {
GtfsStopTime stopTime = new GtfsStopTime.Builder()
GtfsStopTime stopTime =
new GtfsStopTime.Builder()
.setCsvRowNumber(4)
.setPickupType(GtfsPickupDropOff.NOT_AVAILABLE)
.build();
assertThat(generateNotices(stopTime)).isEmpty();
}
}
}

0 comments on commit 884d3bb

Please sign in to comment.