Skip to content

Commit

Permalink
ENH: NAV-53 - Add direct walk type to the walk
Browse files Browse the repository at this point in the history
- A walk from a location to a stop, the first leg of a connection.
- A walk from a stop to a location, the last leg of a connection.
- A walk between two locations, the only leg of a connection.
  • Loading branch information
munterfi committed May 31, 2024
1 parent 681d6f5 commit f52005e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/main/java/ch/naviqore/service/Transfer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

import java.time.LocalDateTime;

/**
* A transfer is a walk between two stops.
* <p>
* 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();
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/ch/naviqore/service/Walk.java
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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<Stop> getStop();

}
16 changes: 15 additions & 1 deletion src/main/java/ch/naviqore/service/WalkType.java
Original file line number Diff line number Diff line change
@@ -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

}
23 changes: 22 additions & 1 deletion src/main/java/ch/naviqore/service/impl/WalkImpl.java
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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;
Expand All @@ -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> T accept(LegVisitor<T> visitor) {
return visitor.visit(this);
}

@Override
public Optional<Stop> getStop() {
return Optional.ofNullable(stop);
}

}

0 comments on commit f52005e

Please sign in to comment.