Skip to content

Commit

Permalink
Merge pull request #6147 from Skanetrafiken/nullability-leg-and-trip
Browse files Browse the repository at this point in the history
Add @nullable annotations to Trip and Leg
  • Loading branch information
habrahamsson-skanetrafiken authored Oct 21, 2024
2 parents 30216e9 + eb0c0ee commit db240e9
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;
import org.locationtech.jts.geom.LineString;
import org.opentripplanner.framework.collection.ListUtils;
import org.opentripplanner.model.fare.FareProductUse;
Expand Down Expand Up @@ -94,6 +95,7 @@ public List<StopArrival> getIntermediateStops() {
}

@Override
@Nullable
public LineString getLegGeometry() {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;
import org.locationtech.jts.geom.LineString;
import org.opentripplanner.ext.flex.edgetype.FlexTripEdge;
import org.opentripplanner.framework.i18n.I18NString;
Expand Down Expand Up @@ -65,6 +66,7 @@ public Agency getAgency() {
}

@Override
@Nullable
public Operator getOperator() {
return getTrip().getOperator();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ default boolean overlapInTime(Leg other) {
/**
* For transit legs, the route agency. For non-transit legs {@code null}.
*/
@Nullable
default Agency getAgency() {
return null;
}
Expand All @@ -171,13 +172,15 @@ default Agency getAgency() {
*
* @see Trip#getOperator()
*/
@Nullable
default Operator getOperator() {
return null;
}

/**
* For transit legs, the route. For non-transit legs, null.
*/
@Nullable
default Route getRoute() {
return null;
}
Expand All @@ -198,6 +201,7 @@ default TripOnServiceDate getTripOnServiceDate() {
return null;
}

@Nullable
default Accessibility getTripWheelchairAccessibility() {
return null;
}
Expand Down Expand Up @@ -245,6 +249,7 @@ default boolean getRealTime() {
return false;
}

@Nullable
default RealTimeState getRealTimeState() {
return null;
}
Expand All @@ -261,6 +266,7 @@ default boolean isFlexibleTrip() {
/**
* Is this a frequency-based trip with non-strict departure times?
*/
@Nullable
default Boolean getNonExactFrequency() {
return null;
}
Expand All @@ -270,6 +276,7 @@ default Boolean getNonExactFrequency() {
* non-strict frequency trips, but could become important for real-time trips, strict frequency
* trips, and scheduled trips with empirical headways.
*/
@Nullable
default Integer getHeadway() {
return null;
}
Expand All @@ -293,13 +300,15 @@ default int getAgencyTimeZoneOffset() {
* using the Hierarchical Vehicle Type (HVT) codes from the European TPEG standard Also see
* http://groups.google.com/group/gtfs-changes/msg/ed917a69cf8c5bef
*/
@Nullable
default Integer getRouteType() {
return null;
}

/**
* For transit legs, the headsign of the bus or train being used. For non-transit legs, null.
*/
@Nullable
default I18NString getHeadsign() {
return null;
}
Expand All @@ -312,13 +321,15 @@ default I18NString getHeadsign() {
* for a given trip may happen at service date March 25th and service time 25:00, which in local
* time would be Mach 26th 01:00.
*/
@Nullable
default LocalDate getServiceDate() {
return null;
}

/**
* For transit leg, the route's branding URL (if one exists). For non-transit legs, null.
*/
@Nullable
default String getRouteBrandingUrl() {
return null;
}
Expand All @@ -337,13 +348,15 @@ default String getRouteBrandingUrl() {
* For transit legs, intermediate stops between the Place where the leg originates and the Place
* where the leg ends. For non-transit legs, {@code null}.
*/
@Nullable
default List<StopArrival> getIntermediateStops() {
return null;
}

/**
* The leg's geometry.
*/
@Nullable
LineString getLegGeometry();

/**
Expand All @@ -352,6 +365,7 @@ default List<StopArrival> getIntermediateStops() {
* The elevation profile as a comma-separated list of x,y values. x is the distance from the start
* of the leg, y is the elevation at this distance.
*/
@Nullable
default ElevationProfile getElevationProfile() {
return null;
}
Expand All @@ -364,56 +378,67 @@ default List<WalkStep> getWalkSteps() {
}

default Set<StreetNote> getStreetNotes() {
return null;
return Set.of();
}

default Set<TransitAlert> getTransitAlerts() {
return Set.of();
}

@Nullable
default PickDrop getBoardRule() {
return null;
}

@Nullable
default PickDrop getAlightRule() {
return null;
}

@Nullable
default BookingInfo getDropOffBookingInfo() {
return null;
}

@Nullable
default BookingInfo getPickupBookingInfo() {
return null;
}

@Nullable
default ConstrainedTransfer getTransferFromPrevLeg() {
return null;
}

@Nullable
default ConstrainedTransfer getTransferToNextLeg() {
return null;
}

@Nullable
default Integer getBoardStopPosInPattern() {
return null;
}

@Nullable
default Integer getAlightStopPosInPattern() {
return null;
}

@Nullable
default Integer getBoardingGtfsStopSequence() {
return null;
}

@Nullable
default Integer getAlightGtfsStopSequence() {
return null;
}

/**
* Is this leg walking with a bike?
*/
@Nullable
default Boolean getWalkingBike() {
return null;
}
Expand All @@ -435,10 +460,12 @@ default Float accessibilityScore() {
return null;
}

@Nullable
default Boolean getRentedVehicle() {
return null;
}

@Nullable
default String getVehicleRentalNetwork() {
return null;
}
Expand All @@ -453,6 +480,7 @@ default String getVehicleRentalNetwork() {
*/
int getGeneralizedCost();

@Nullable
default LegReference getLegReference() {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ protected ScheduledTransitLeg(ScheduledTransitLegBuilder<?> builder) {
setDistanceMeters(getDistanceFromCoordinates(transitLegCoordinates));
this.directDistanceMeters =
getDistanceFromCoordinates(
List.of(
transitLegCoordinates.get(0),
transitLegCoordinates.get(transitLegCoordinates.size() - 1)
)
List.of(transitLegCoordinates.getFirst(), transitLegCoordinates.getLast())
);
}

Expand Down Expand Up @@ -139,22 +136,23 @@ public Boolean isInterlinedWithPreviousLeg() {

@Override
public Agency getAgency() {
return getTrip().getRoute().getAgency();
return trip().getRoute().getAgency();
}

@Override
@Nullable
public Operator getOperator() {
return getTrip().getOperator();
return trip().getOperator();
}

@Override
public Route getRoute() {
return getTrip().getRoute();
return trip().getRoute();
}

@Override
public Trip getTrip() {
return tripTimes.getTrip();
return trip();
}

@Override
Expand Down Expand Up @@ -182,7 +180,7 @@ public LegTime end() {

@Override
public TransitMode getMode() {
return getTrip().getMode();
return trip().getMode();
}

@Override
Expand Down Expand Up @@ -247,7 +245,7 @@ public double getDirectDistanceMeters() {

@Override
public Integer getRouteType() {
return getTrip().getRoute().getGtfsType();
return trip().getRoute().getGtfsType();
}

@Override
Expand Down Expand Up @@ -300,6 +298,7 @@ public Set<TransitAlert> getTransitAlerts() {
}

@Override
@Nullable
public PickDrop getBoardRule() {
if (transferFromPrevLeg != null && transferFromPrevLeg.getTransferConstraint().isStaySeated()) {
return null;
Expand All @@ -308,6 +307,7 @@ public PickDrop getBoardRule() {
}

@Override
@Nullable
public PickDrop getAlightRule() {
if (transferToNextLeg != null && transferToNextLeg.getTransferConstraint().isStaySeated()) {
return null;
Expand Down Expand Up @@ -434,6 +434,13 @@ public String toString() {
.toString();
}

/**
* Non-null getter for trip
*/
private Trip trip() {
return tripTimes.getTrip();
}

private List<Coordinate> extractTransitLegCoordinates(
TripPattern tripPattern,
int boardStopIndexInPattern,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.time.ZonedDateTime;
import java.util.List;
import javax.annotation.Nullable;
import org.locationtech.jts.geom.LineString;
import org.opentripplanner.framework.time.DurationUtils;
import org.opentripplanner.framework.tostring.ToStringBuilder;
Expand Down Expand Up @@ -84,6 +85,7 @@ public double getDistanceMeters() {
}

@Override
@Nullable
public LineString getLegGeometry() {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import jakarta.xml.bind.JAXBElement;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nullable;
import net.opengis.gml._3.LineStringType;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.CoordinateSequence;
Expand Down Expand Up @@ -116,6 +117,7 @@ private LineString[] generateGeometriesFromServiceLinks(
return geometries;
}

@Nullable
private LineString mapServiceLink(
ServiceLink serviceLink,
StopPattern stopPattern,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ public Integer getGtfsSortOrder() {
return gtfsSortOrder;
}

/**
* Returns the NeTEx submode for the route. Will return UNKNOWN by default.
*/
public SubMode getNetexSubmode() {
return netexSubmode;
}
Expand Down
Loading

0 comments on commit db240e9

Please sign in to comment.