diff --git a/src/main/java/ch/naviqore/service/Transfer.java b/src/main/java/ch/naviqore/service/Transfer.java index ee4f2541..9a8dc068 100644 --- a/src/main/java/ch/naviqore/service/Transfer.java +++ b/src/main/java/ch/naviqore/service/Transfer.java @@ -2,6 +2,12 @@ import java.time.LocalDateTime; +/** + * A transfer is a walk between two stops. + *

+ * Typically, a transfer occurs between two public transit legs within a connection. However, a connection might consist + * solely of a transfer if it directly links two stops via walking. + */ public interface Transfer extends Leg { LocalDateTime getArrivalTime(); diff --git a/src/main/java/ch/naviqore/service/Walk.java b/src/main/java/ch/naviqore/service/Walk.java index 63ba2b83..e3b3665e 100644 --- a/src/main/java/ch/naviqore/service/Walk.java +++ b/src/main/java/ch/naviqore/service/Walk.java @@ -1,12 +1,10 @@ package ch.naviqore.service; import java.time.LocalDateTime; +import java.util.Optional; public interface Walk extends Leg { - /** - * Determines if this is first or a last mile walk. - */ WalkType getWalkType(); LocalDateTime getArrivalTime(); @@ -18,8 +16,8 @@ public interface Walk extends Leg { Location getTargetLocation(); /** - * The source or target stop of this first or last mile walk. + * The source or target stop of a first or last mile walk or none if it is a direct walk. */ - Stop getStop(); + Optional getStop(); } diff --git a/src/main/java/ch/naviqore/service/WalkType.java b/src/main/java/ch/naviqore/service/WalkType.java index 4b5a795c..7db29c28 100644 --- a/src/main/java/ch/naviqore/service/WalkType.java +++ b/src/main/java/ch/naviqore/service/WalkType.java @@ -1,6 +1,20 @@ package ch.naviqore.service; public enum WalkType { + + /** + * A walk from a location to a stop, the first leg of a connection. + */ FIRST_MILE, - LAST_MILE + + /** + * A walk from a stop to a location, the last leg of a connection. + */ + LAST_MILE, + + /** + * A walk between two locations, the only leg of a connection. + */ + DIRECT + } diff --git a/src/main/java/ch/naviqore/service/impl/WalkImpl.java b/src/main/java/ch/naviqore/service/impl/WalkImpl.java index a3df3b56..86e767fb 100644 --- a/src/main/java/ch/naviqore/service/impl/WalkImpl.java +++ b/src/main/java/ch/naviqore/service/impl/WalkImpl.java @@ -1,10 +1,13 @@ package ch.naviqore.service.impl; import ch.naviqore.service.*; +import lombok.AccessLevel; import lombok.Getter; import lombok.ToString; +import org.jetbrains.annotations.Nullable; import java.time.LocalDateTime; +import java.util.Optional; @Getter @ToString(callSuper = true) @@ -15,10 +18,15 @@ public class WalkImpl extends LegImpl implements Walk { private final LocalDateTime arrivalTime; private final Location sourceLocation; private final Location targetLocation; + @Getter(AccessLevel.NONE) + @Nullable private final Stop stop; + /** + * Create a first or last mile walk between a station and a location. + */ WalkImpl(int distance, int duration, WalkType walkType, LocalDateTime departureTime, LocalDateTime arrivalTime, - Location sourceLocation, Location targetLocation, Stop stop) { + Location sourceLocation, Location targetLocation, @Nullable Stop stop) { super(LegType.WALK, distance, duration); this.walkType = walkType; this.departureTime = departureTime; @@ -28,9 +36,22 @@ public class WalkImpl extends LegImpl implements Walk { this.stop = stop; } + /** + * Create a direct walk between two locations. + */ + WalkImpl(int distance, int duration, LocalDateTime departureTime, LocalDateTime arrivalTime, + Location sourceLocation, Location targetLocation) { + this(distance, duration, WalkType.DIRECT, departureTime, arrivalTime, sourceLocation, targetLocation, null); + } + @Override public T accept(LegVisitor visitor) { return visitor.visit(this); } + @Override + public Optional getStop() { + return Optional.ofNullable(stop); + } + }