Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vpaturet committed Apr 28, 2023
1 parent db8ec5a commit c233153
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 100 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
/**
* Ensure that passing times are increasing along the service journey.
* The validator checks first that individual TimetabledPassingTimes are valid, i.e:
* - a fixed stop has either arrivalTime or departureTime specified, and arrivalTime < departureTime
* - a flex stop has both earliestDepartureTime and latestArrivalTime specified, and earliestDepartureTime < latestArrivalTime
* - a regular stop has either arrivalTime or departureTime specified, and arrivalTime < departureTime
* - an area stop has both earliestDepartureTime and latestArrivalTime specified, and earliestDepartureTime < latestArrivalTime
* The validator then checks that successive stops have increasing times, taking into account 4 different cases:
* - a fixed stop followed by a fixed stop
* - a flex stop followed by a flex stop
* - a fixed stop followed by a flex stop
* - a flex stop followed by a fixed stop
* - a regular stop followed by a regular stop
* - an area stop followed by an area stop
* - a regular stop followed by an area stop
* - an area stop followed by a regular stop
*/
class ServiceJourneyNonIncreasingPassingTime
extends AbstractHMapValidationRule<String, ServiceJourney> {
Expand All @@ -54,10 +54,10 @@ public Status validate(ServiceJourney sj) {
}

if (
serviceJourneyInfo.hasFixedStop(previousTimetabledPassingTime) &&
serviceJourneyInfo.hasFixedStop(currentTimetabledPassingTime) &&
serviceJourneyInfo.hasRegularStop(previousTimetabledPassingTime) &&
serviceJourneyInfo.hasRegularStop(currentTimetabledPassingTime) &&
(
!isValidFixedStopFollowedByFixedStop(
!isValidRegularStopFollowedByRegularStop(
previousTimetabledPassingTime,
currentTimetabledPassingTime
)
Expand All @@ -66,10 +66,10 @@ public Status validate(ServiceJourney sj) {
return Status.DISCARD;
}
if (
serviceJourneyInfo.hasFlexStop(previousTimetabledPassingTime) &&
serviceJourneyInfo.hasFlexStop(currentTimetabledPassingTime) &&
serviceJourneyInfo.hasAreaStop(previousTimetabledPassingTime) &&
serviceJourneyInfo.hasAreaStop(currentTimetabledPassingTime) &&
(
!isValidFlexStopFollowedByFlexStop(
!isValidAreaStopFollowedByAreaStop(
previousTimetabledPassingTime,
currentTimetabledPassingTime
)
Expand All @@ -79,10 +79,10 @@ public Status validate(ServiceJourney sj) {
}

if (
serviceJourneyInfo.hasFixedStop(previousTimetabledPassingTime) &&
serviceJourneyInfo.hasFlexStop(currentTimetabledPassingTime) &&
serviceJourneyInfo.hasRegularStop(previousTimetabledPassingTime) &&
serviceJourneyInfo.hasAreaStop(currentTimetabledPassingTime) &&
(
!isValidFixedStopFollowedByFlexStop(
!isValidRegularStopFollowedByAreaStop(
previousTimetabledPassingTime,
currentTimetabledPassingTime
)
Expand All @@ -92,10 +92,10 @@ public Status validate(ServiceJourney sj) {
}

if (
serviceJourneyInfo.hasFlexStop(previousTimetabledPassingTime) &&
serviceJourneyInfo.hasFixedStop(currentTimetabledPassingTime) &&
serviceJourneyInfo.hasAreaStop(previousTimetabledPassingTime) &&
serviceJourneyInfo.hasRegularStop(currentTimetabledPassingTime) &&
(
!isValidFlexStopFollowedByFixedStop(
!isValidAreaStopFollowedByRegularStop(
previousTimetabledPassingTime,
currentTimetabledPassingTime
)
Expand Down Expand Up @@ -130,15 +130,15 @@ private boolean isValidTimetabledPassingTime(
}

/**
* A passing time on a fixed stop is complete if either arrival or departure time is present.
* A passing time on a flex stop is complete if both earliest departure time and latest arrival time are present.
* A passing time on a regular stop is complete if either arrival or departure time is present.
* A passing time on a area stop is complete if both earliest departure time and latest arrival time are present.
*
*/
private boolean hasCompletePassingTime(
TimetabledPassingTime timetabledPassingTime,
ServiceJourneyInfo serviceJourneyInfo
) {
if (serviceJourneyInfo.hasFixedStop(timetabledPassingTime)) {
if (serviceJourneyInfo.hasRegularStop(timetabledPassingTime)) {
return (
timetabledPassingTime.getArrivalTime() != null ||
timetabledPassingTime.getDepartureTime() != null
Expand All @@ -151,16 +151,16 @@ private boolean hasCompletePassingTime(
}

/**
* A passing time on a fixed stop is consistent if departure time is after arrival time.
* A passing time on a flex stop is consistent if latest arrival time is after earliest departure time.
* A passing time on a regular stop is consistent if departure time is after arrival time.
* A passing time on a area stop is consistent if latest arrival time is after earliest departure time.
*
*/
private boolean hasConsistentPassingTime(
TimetabledPassingTime timetabledPassingTime,
ServiceJourneyInfo serviceJourneyInfo
) {
if (
serviceJourneyInfo.hasFixedStop(timetabledPassingTime) &&
serviceJourneyInfo.hasRegularStop(timetabledPassingTime) &&
(
timetabledPassingTime.getArrivalTime() == null ||
timetabledPassingTime.getDepartureTime() == null
Expand All @@ -169,7 +169,7 @@ private boolean hasConsistentPassingTime(
return true;
}
if (
serviceJourneyInfo.hasFixedStop(timetabledPassingTime) &&
serviceJourneyInfo.hasRegularStop(timetabledPassingTime) &&
timetabledPassingTime.getArrivalTime() != null &&
timetabledPassingTime.getDepartureTime() != null
) {
Expand All @@ -186,9 +186,9 @@ private boolean hasConsistentPassingTime(
}

/**
* Fixed stop followed by a fixed stop: check that arrivalTime(n+1) > departureTime(n)
* regular stop followed by a regular stop: check that arrivalTime(n+1) > departureTime(n)
*/
private boolean isValidFixedStopFollowedByFixedStop(
private boolean isValidRegularStopFollowedByRegularStop(
TimetabledPassingTime previousTimetabledPassingTime,
TimetabledPassingTime currentTimetabledPassingTime
) {
Expand All @@ -200,17 +200,17 @@ private boolean isValidFixedStopFollowedByFixedStop(
);
if (currentArrivalOrDepartureTime < previousDepartureOrArrivalTime) {
invalidTimetabledPassingTime = currentTimetabledPassingTime;
errorMessage = "non-increasing time between fixed stops";
errorMessage = "non-increasing time between regular stops";
return false;
}
return true;
}

/**
* Flex stop followed by a flex stop: check that earliestDepartureTime(n+1) > earliestDepartureTime(n)
* area stop followed by a area stop: check that earliestDepartureTime(n+1) > earliestDepartureTime(n)
* and latestArrivalTime(n+1) > latestArrivalTime(n)
*/
private boolean isValidFlexStopFollowedByFlexStop(
private boolean isValidAreaStopFollowedByAreaStop(
TimetabledPassingTime previousTimetabledPassingTime,
TimetabledPassingTime currentTimetabledPassingTime
) {
Expand All @@ -228,16 +228,16 @@ private boolean isValidFlexStopFollowedByFlexStop(
currentLatestArrivalTime < previousLatestArrivalTime
) {
invalidTimetabledPassingTime = currentTimetabledPassingTime;
errorMessage = "non-increasing time between flex stops";
errorMessage = "non-increasing time between area stops";
return false;
}
return true;
}

/**
* Fixed stop followed by a flex stop: check that earliestDepartureTime(n+1) > departureTime(n)
* regular stop followed by a area stop: check that earliestDepartureTime(n+1) > departureTime(n)
*/
private boolean isValidFixedStopFollowedByFlexStop(
private boolean isValidRegularStopFollowedByAreaStop(
TimetabledPassingTime previousTimetabledPassingTime,
TimetabledPassingTime currentTimetabledPassingTime
) {
Expand All @@ -251,16 +251,16 @@ private boolean isValidFixedStopFollowedByFlexStop(

if (currentEarliestDepartureTime < previousDepartureOrArrivalTime) {
invalidTimetabledPassingTime = currentTimetabledPassingTime;
errorMessage = "non-increasing time between fixed stop and flex stop";
errorMessage = "non-increasing time between regular stop and area stop";
return false;
}
return true;
}

/**
* Flex stop followed by a fixed stop: check that arrivalTime(n+1) > latestArrivalTime(n)
* area stop followed by a regular stop: check that arrivalTime(n+1) > latestArrivalTime(n)
*/
private boolean isValidFlexStopFollowedByFixedStop(
private boolean isValidAreaStopFollowedByRegularStop(
TimetabledPassingTime previousTimetabledPassingTime,
TimetabledPassingTime currentTimetabledPassingTime
) {
Expand All @@ -271,7 +271,7 @@ private boolean isValidFlexStopFollowedByFixedStop(

if (currentArrivalOrDepartureTime < previousLatestArrivalTime) {
invalidTimetabledPassingTime = currentTimetabledPassingTime;
errorMessage = "non-increasing time between flex stop and fixed stop";
errorMessage = "non-increasing time between area stop and regular stop";
return false;
}
return true;
Expand Down Expand Up @@ -318,7 +318,7 @@ private class ServiceJourneyInfo {
private final List<TimetabledPassingTime> orderedTimetabledPassingTimes;

/**
* Map a timetabledPassingTime to true if its stop is flexible, false otherwise.
* Map a timetabledPassingTime to true if its stop is a stop area, false otherwise.
*/
private final Map<TimetabledPassingTime, Boolean> stopFlexibility;

Expand Down Expand Up @@ -354,12 +354,12 @@ public List<TimetabledPassingTime> getOrderedTimetabledPassingTimes() {
return orderedTimetabledPassingTimes;
}

public boolean hasFlexStop(TimetabledPassingTime timetabledPassingTime) {
public boolean hasAreaStop(TimetabledPassingTime timetabledPassingTime) {
return stopFlexibility.get(timetabledPassingTime);
}

public boolean hasFixedStop(TimetabledPassingTime timetabledPassingTime) {
return !hasFlexStop(timetabledPassingTime);
public boolean hasRegularStop(TimetabledPassingTime timetabledPassingTime) {
return !hasAreaStop(timetabledPassingTime);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ private void run() {
validate(index.serviceJourneyById, ServiceJourneyNonIncreasingPassingTime::new);
validate(index.datedServiceJourneys, new DSJOperatingDayNotFound());
validate(index.datedServiceJourneys, new DSJServiceJourneyNotFound());
validate(index.serviceJourneyInterchangeById, InterchangeServiceJourneyNotFound::new);
}

/**
Expand Down
Loading

0 comments on commit c233153

Please sign in to comment.