Skip to content

Commit

Permalink
#23 SearchWindow as Duration
Browse files Browse the repository at this point in the history
  • Loading branch information
jspetrak committed Mar 12, 2024
1 parent 455b97f commit 0484bdd
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/opentripplanner/client/OtpApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public TripPlan plan(TripPlanParameters req) throws IOException {
req.time().toLocalDate().toString(),
req.time().toLocalTime().truncatedTo(ChronoUnit.SECONDS).toString(),
req.searchDirection().isArriveBy(),
req.searchWindow() == null
? ""
: String.format("searchWindow : %d", req.searchWindow()),
req.getSearchWindow().isPresent()
? String.format("searchWindow : %d", req.getSearchWindow().get().toMinutes())
: "",
req.walkReluctance(),
req.wheelchair());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.opentripplanner.client.parameters;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import org.opentripplanner.client.model.PlaceParameter;
import org.opentripplanner.client.model.RequestMode;
Expand All @@ -14,7 +16,7 @@ public record TripPlanParameters(
int numItineraries,
Set<RequestMode> modes,
SearchDirection searchDirection,
Long searchWindow,
Duration searchWindow,
float walkReluctance,
boolean wheelchair) {

Expand All @@ -27,6 +29,10 @@ public record TripPlanParameters(
Objects.requireNonNull(searchDirection);
}

public Optional<Duration> getSearchWindow() {
return Optional.ofNullable(searchWindow());
}

public enum SearchDirection {
DEPART_AT,
ARRIVE_BY;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.opentripplanner.client.parameters;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Set;
Expand All @@ -14,7 +15,7 @@ public class TripPlanParametersBuilder {
private LocalDateTime time;
private Set<RequestMode> modes;
private SearchDirection searchDirection = SearchDirection.DEPART_AT;
private Long searchWindow;
private Duration searchWindow;
private float walkReluctance = 1.4f;
private int numItineraries = 5;
private boolean wheelchair = false;
Expand Down Expand Up @@ -49,7 +50,7 @@ public TripPlanParametersBuilder withSearchDirection(SearchDirection searchDirec
return this;
}

public TripPlanParametersBuilder withSearchWindow(Long searchWindow) {
public TripPlanParametersBuilder withSearchWindow(Duration searchWindow) {
this.searchWindow = searchWindow;
return this;
}
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/org/opentripplanner/IntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,34 @@ public void planPlaceToPlace() throws IOException {
assertEquals(List.of(), leg.fareProducts());
}

@Test
public void planPlaceToPlaceWithSearchWindow() throws IOException {
var result =
client.plan(
TripPlanParameters.builder()
.withFrom(OSLO_LUFTHAVN_ID)
.withTo(OSLO_S_ID)
.withTime(LocalDateTime.now())
.withModes(RequestMode.TRANSIT)
.withNumberOfItineraries(1)
.withSearchWindow(java.time.Duration.ofDays(1))
.build());

LOG.info("Received {} itineraries", result.itineraries().size());
assertEquals(1, result.itineraries().size());

assertNotNull(result.itineraries().get(0).legs().get(0).startTime());

var leg = result.itineraries().get(0).legs().get(0);

var transitLeg = result.transitItineraries().get(0).transitLegs().get(0);
assertFalse(transitLeg.from().stop().isEmpty());
assertFalse(transitLeg.to().stop().isEmpty());
assertNotNull(transitLeg.from().stop().get().id());

assertEquals(List.of(), leg.fareProducts());
}

@Test
public void arriveByPlan() throws IOException {

Expand Down

0 comments on commit 0484bdd

Please sign in to comment.