-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NonIncreasingTimeValidator and MismatchedTransportModeValidator
- Loading branch information
Showing
20 changed files
with
3,809 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/org/entur/netex/validation/validator/jaxb/JAXBValidationContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/org/entur/netex/validation/validator/jaxb/SiteFrameStopPlaceRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/main/java/org/entur/netex/validation/validator/jaxb/model/stoptime/AbstractStopTime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.entur.netex.validation.validator.jaxb.model.stoptime; | ||
|
||
import java.math.BigInteger; | ||
import java.time.LocalTime; | ||
import org.entur.netex.validation.validator.model.ScheduledStopPointId; | ||
import org.rutebanken.netex.model.TimetabledPassingTime; | ||
|
||
/** | ||
* Wrapper around {@link TimetabledPassingTime} that provides a simpler interface for passing times | ||
* comparison. Passing times are exposed as seconds since midnight, taking into account the day | ||
* offset. | ||
* <p> | ||
* This class does not take Daylight Saving Time transitions into account, this is an error and | ||
* should be fixed. See https://github.com/opentripplanner/OpenTripPlanner/issues/5109 | ||
*/ | ||
abstract sealed class AbstractStopTime | ||
implements StopTime | ||
permits FlexibleStopTime, RegularStopTime { | ||
|
||
private final ScheduledStopPointId scheduledStopPointId; | ||
private final TimetabledPassingTime timetabledPassingTime; | ||
|
||
protected AbstractStopTime( | ||
ScheduledStopPointId scheduledStopPointId, | ||
TimetabledPassingTime timetabledPassingTime | ||
) { | ||
this.scheduledStopPointId = scheduledStopPointId; | ||
this.timetabledPassingTime = timetabledPassingTime; | ||
} | ||
|
||
@Override | ||
public ScheduledStopPointId scheduledStopPointId() { | ||
return scheduledStopPointId; | ||
} | ||
|
||
protected LocalTime arrivalTime() { | ||
return timetabledPassingTime.getArrivalTime(); | ||
} | ||
|
||
protected BigInteger arrivalDayOffset() { | ||
return timetabledPassingTime.getArrivalDayOffset(); | ||
} | ||
|
||
protected LocalTime latestArrivalTime() { | ||
return timetabledPassingTime.getLatestArrivalTime(); | ||
} | ||
|
||
protected BigInteger latestArrivalDayOffset() { | ||
return timetabledPassingTime.getLatestArrivalDayOffset(); | ||
} | ||
|
||
protected LocalTime departureTime() { | ||
return timetabledPassingTime.getDepartureTime(); | ||
} | ||
|
||
protected BigInteger departureDayOffset() { | ||
return timetabledPassingTime.getDepartureDayOffset(); | ||
} | ||
|
||
protected LocalTime earliestDepartureTime() { | ||
return timetabledPassingTime.getEarliestDepartureTime(); | ||
} | ||
|
||
protected BigInteger earliestDepartureDayOffset() { | ||
return timetabledPassingTime.getEarliestDepartureDayOffset(); | ||
} | ||
|
||
protected boolean isRegularStopFollowedByAreaStopValid( | ||
FlexibleStopTime next | ||
) { | ||
return ( | ||
normalizedDepartureTimeOrElseArrivalTime() <= | ||
next.normalizedEarliestDepartureTime() | ||
); | ||
} | ||
|
||
protected boolean isAreaStopFollowedByRegularStopValid(RegularStopTime next) { | ||
return ( | ||
normalizedLatestArrivalTime() <= | ||
next.normalizedArrivalTimeOrElseDepartureTime() | ||
); | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
src/main/java/org/entur/netex/validation/validator/jaxb/model/stoptime/FlexibleStopTime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package org.entur.netex.validation.validator.jaxb.model.stoptime; | ||
|
||
import org.entur.netex.validation.validator.model.ScheduledStopPointId; | ||
import org.rutebanken.netex.model.TimetabledPassingTime; | ||
|
||
/** | ||
* Wrapper around {@link TimetabledPassingTime} that provides a simpler interface | ||
* for passing times comparison. | ||
* Passing times are exposed as seconds since midnight, taking into account the day offset. | ||
*/ | ||
final class FlexibleStopTime extends AbstractStopTime { | ||
|
||
FlexibleStopTime( | ||
ScheduledStopPointId scheduledStopPointId, | ||
TimetabledPassingTime timetabledPassingTime | ||
) { | ||
super(scheduledStopPointId, timetabledPassingTime); | ||
} | ||
|
||
@Override | ||
public boolean isComplete() { | ||
return hasLatestArrivalTime() && hasEarliestDepartureTime(); | ||
} | ||
|
||
@Override | ||
public boolean isConsistent() { | ||
return ( | ||
!isComplete() || | ||
normalizedLatestArrivalTime() >= normalizedEarliestDepartureTime() | ||
); | ||
} | ||
|
||
@Override | ||
public boolean isStopTimesIncreasing(StopTime next) { | ||
if (next instanceof RegularStopTime regularStopTime) { | ||
return isAreaStopFollowedByRegularStopValid(regularStopTime); | ||
} | ||
return isAreaStopFollowedByAreaStopValid((FlexibleStopTime) next); | ||
} | ||
|
||
@Override | ||
public int getStopTimeDiff(StopTime given) { | ||
// TODO: This should be fixed. We need to take into account the type of given. | ||
// Is it the same type as this, or not. See how we have done in | ||
// isRegularStopFollowedByRegularStopValid, isAreaStopFollowedByAreaStopValid, | ||
// isRegularStopFollowedByAreaStopValid, isAreaStopFollowedByRegularStopValid | ||
|
||
if (given instanceof FlexibleStopTime) { | ||
return isComplete() | ||
? normalizedEarliestDepartureTime() - normalizedLatestArrivalTime() | ||
: 0; | ||
} | ||
return ( | ||
given.normalizedEarliestDepartureTime() - | ||
normalizedArrivalTimeOrElseDepartureTime() | ||
); | ||
} | ||
|
||
@Override | ||
public int normalizedEarliestDepartureTime() { | ||
return elapsedTimeSinceMidnight( | ||
earliestDepartureTime(), | ||
earliestDepartureDayOffset() | ||
); | ||
} | ||
|
||
@Override | ||
public int normalizedLatestArrivalTime() { | ||
return elapsedTimeSinceMidnight( | ||
latestArrivalTime(), | ||
latestArrivalDayOffset() | ||
); | ||
} | ||
|
||
@Override | ||
public int normalizedDepartureTimeOrElseArrivalTime() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public int normalizedArrivalTimeOrElseDepartureTime() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
private boolean hasLatestArrivalTime() { | ||
return latestArrivalTime() != null; | ||
} | ||
|
||
private boolean hasEarliestDepartureTime() { | ||
return earliestDepartureTime() != null; | ||
} | ||
|
||
private boolean isAreaStopFollowedByAreaStopValid(FlexibleStopTime next) { | ||
int earliestDepartureTime = normalizedEarliestDepartureTime(); | ||
int nextEarliestDepartureTime = next.normalizedEarliestDepartureTime(); | ||
int latestArrivalTime = normalizedLatestArrivalTime(); | ||
int nextLatestArrivalTime = next.normalizedLatestArrivalTime(); | ||
|
||
return ( | ||
earliestDepartureTime <= nextEarliestDepartureTime && | ||
latestArrivalTime <= nextLatestArrivalTime | ||
); | ||
} | ||
|
||
@Override | ||
public boolean isArrivalInMinutesResolution() { | ||
return hasLatestArrivalTime() | ||
? latestArrivalTime().getSecond() == 0 | ||
: earliestDepartureTime().getSecond() == 0; | ||
} | ||
|
||
@Override | ||
public boolean isDepartureInMinutesResolution() { | ||
return hasEarliestDepartureTime() | ||
? earliestDepartureTime().getSecond() == 0 | ||
: latestArrivalTime().getSecond() == 0; | ||
} | ||
} |
Oops, something went wrong.