Skip to content

Commit fee18b6

Browse files
committed
Pass firstItineraryResultDeparture as parameter to withOriginalSearch instead of itinerary list.
1 parent a0b9880 commit fee18b6

3 files changed

Lines changed: 29 additions & 43 deletions

File tree

application/src/main/java/org/opentripplanner/model/plan/paging/cursor/PageCursorFactory.java

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
import java.time.Duration;
77
import java.time.Instant;
8-
import java.util.List;
98
import javax.annotation.Nullable;
10-
import org.opentripplanner.model.plan.Itinerary;
119
import org.opentripplanner.model.plan.ItinerarySortKey;
1210
import org.opentripplanner.model.plan.SortOrder;
1311
import org.opentripplanner.utils.tostring.ToStringBuilder;
@@ -46,27 +44,28 @@ public PageCursorFactory(SortOrder sortOrder, Duration newSearchWindow) {
4644

4745
/**
4846
* Set the original search earliest-departure-time({@code edt}), latest-arrival-time ({@code lat},
49-
* optional) and the search-window used.
47+
* optional) and the search-window used. Also resolve the page-type and
48+
* first-search-latest-itinerary-departure.
5049
*/
5150
public PageCursorFactory withOriginalSearch(
5251
@Nullable PageType pageType,
52+
@Nullable Instant firstItineraryResultDeparture,
5353
Instant edt,
5454
Instant lat,
55-
Duration searchWindow,
56-
List<Itinerary> itineraries
55+
Duration searchWindow
5756
) {
5857
this.currentPageType = pageType == null
5958
? resolvePageTypeForTheFirstSearch(sortOrder)
6059
: pageType;
61-
62-
this.currentEdt = edt;
63-
this.currentLat = lat;
64-
this.currentSearchWindow = searchWindow;
6560
this.firstSearchLatestItineraryDeparture = resolveFirstSearchLatestItineraryDeparture(
6661
pageType,
67-
itineraries,
62+
firstItineraryResultDeparture,
6863
edt
6964
);
65+
66+
this.currentEdt = edt;
67+
this.currentLat = lat;
68+
this.currentSearchWindow = searchWindow;
7069
return this;
7170
}
7271

@@ -86,20 +85,6 @@ public PageCursorFactory withRemovedItineraries(PageCursorInput pageCursorFactor
8685
return this;
8786
}
8887

89-
/**
90-
* If the initial request is of the PREVIOUS_PAGE type, the current search window is misleading.
91-
* Instead of using the current search window to set the page cursor of the next page,
92-
* the departure time of the latest itinerary result is used.
93-
*
94-
* @param firstSearchLatestItineraryDeparture the time of the latest departure of the itinerary results from the first search
95-
*/
96-
public PageCursorFactory withFirstSearchLatestItineraryDeparture(
97-
Instant firstSearchLatestItineraryDeparture
98-
) {
99-
this.firstSearchLatestItineraryDeparture = firstSearchLatestItineraryDeparture;
100-
return this;
101-
}
102-
10388
@Nullable
10489
public PageCursor previousPageCursor() {
10590
createPageCursors();
@@ -138,17 +123,18 @@ private static PageType resolvePageTypeForTheFirstSearch(SortOrder sortOrder) {
138123
}
139124

140125
/**
141-
* If the first search is an arrive by search, store the latest itinerary's start time
142-
* to allow setting cursor information correctly for the page cursor of the next page.
126+
* If the first search is an arrive by search (PREVIOUS_PAGE type), the current search window is
127+
* misleading. Instead of using the current search window to set the page cursor of the next
128+
* page, the departure time of the latest itinerary result is used to avoid missing itineraries.
143129
*/
144130
private Instant resolveFirstSearchLatestItineraryDeparture(
145131
@Nullable PageType pageType,
146-
List<Itinerary> itineraries,
132+
@Nullable Instant firstItineraryResultDeparture,
147133
Instant edt
148134
) {
149135
if (pageType == null && resolvePageTypeForTheFirstSearch(sortOrder) == PREVIOUS_PAGE) {
150-
if (itineraries.size() > 0) {
151-
return itineraries.get(0).startTimeAsInstant();
136+
if (firstItineraryResultDeparture != null) {
137+
return firstItineraryResultDeparture;
152138
} else {
153139
return edt;
154140
}

application/src/main/java/org/opentripplanner/service/paging/PagingService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ private PageCursorFactory mapIntoPageCursorFactory(@Nullable PageType currentPag
179179

180180
factory = factory.withOriginalSearch(
181181
currentPageType,
182+
itineraries.size() > 0 ? itineraries.get(0).startTimeAsInstant() : null,
182183
earliestDepartureTime,
183184
latestArrivalTime,
184-
searchWindowUsed,
185-
itineraries
185+
searchWindowUsed
186186
);
187187

188188
if (pageCursorInput != null) {

application/src/test/java/org/opentripplanner/model/plan/paging/cursor/PageCursorFactoryTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ class PageCursorFactoryTest implements PlanTestConstants {
3636
@Test
3737
public void sortArrivalAscending() {
3838
var factory = new PageCursorFactory(STREET_AND_ARRIVAL_TIME, D90M).withOriginalSearch(
39+
null,
3940
null,
4041
T12_00,
4142
null,
42-
D1H,
43-
List.of()
43+
D1H
4444
);
4545

4646
var nextPage = factory.nextPageCursor();
@@ -53,7 +53,7 @@ public void sortArrivalAscending() {
5353
@Test
5454
public void sortArrivalAscendingCropSearchWindow() {
5555
var factory = new PageCursorFactory(STREET_AND_ARRIVAL_TIME, D90M)
56-
.withOriginalSearch(NEXT_PAGE, T12_00, null, D1H, List.of())
56+
.withOriginalSearch(NEXT_PAGE, null, T12_00, null, D1H)
5757
.withRemovedItineraries(
5858
new TestPageCursorInput(
5959
newItinerary(A).bus(55, timeAsSeconds(T12_00), timeAsSeconds(T12_10), B).build(),
@@ -72,10 +72,10 @@ public void sortArrivalAscendingCropSearchWindow() {
7272
public void sortArrivalAscendingPreviousPage() {
7373
var factory = new PageCursorFactory(STREET_AND_ARRIVAL_TIME, D90M).withOriginalSearch(
7474
PREVIOUS_PAGE,
75+
null,
7576
T12_00,
7677
null,
77-
D1H,
78-
List.of()
78+
D1H
7979
);
8080

8181
var nextPage = factory.nextPageCursor();
@@ -88,7 +88,7 @@ public void sortArrivalAscendingPreviousPage() {
8888
@Test
8989
public void sortArrivalAscendingCropSearchWindowPreviousPage() {
9090
var factory = new PageCursorFactory(STREET_AND_ARRIVAL_TIME, D90M)
91-
.withOriginalSearch(PREVIOUS_PAGE, T12_00, null, D1H, List.of())
91+
.withOriginalSearch(PREVIOUS_PAGE, null, T12_00, null, D1H)
9292
.withRemovedItineraries(
9393
new TestPageCursorInput(
9494
newItinerary(A).bus(55, timeAsSeconds(T12_00), timeAsSeconds(T12_10), B).build(),
@@ -106,11 +106,11 @@ public void sortArrivalAscendingCropSearchWindowPreviousPage() {
106106
@Test
107107
public void sortDepartureDescending() {
108108
var factory = new PageCursorFactory(STREET_AND_DEPARTURE_TIME, D90M).withOriginalSearch(
109+
null,
109110
null,
110111
T12_00,
111112
T13_30,
112-
D1H,
113-
List.of()
113+
D1H
114114
);
115115

116116
var nextPage = factory.nextPageCursor();
@@ -123,7 +123,7 @@ public void sortDepartureDescending() {
123123
@Test
124124
public void sortDepartureDescendingCropSearchWindow() {
125125
var factory = new PageCursorFactory(STREET_AND_DEPARTURE_TIME, D90M)
126-
.withOriginalSearch(PREVIOUS_PAGE, T12_00, T13_30, D1H, List.of())
126+
.withOriginalSearch(PREVIOUS_PAGE, null, T12_00, T13_30, D1H)
127127
.withRemovedItineraries(
128128
new TestPageCursorInput(
129129
newItinerary(A).bus(55, timeAsSeconds(T12_00), timeAsSeconds(T12_30), B).build(),
@@ -142,10 +142,10 @@ public void sortDepartureDescendingCropSearchWindow() {
142142
public void sortDepartureDescendingNextPage() {
143143
var factory = new PageCursorFactory(STREET_AND_DEPARTURE_TIME, D90M).withOriginalSearch(
144144
NEXT_PAGE,
145+
null,
145146
T12_00,
146147
T13_30,
147-
D1H,
148-
List.of()
148+
D1H
149149
);
150150

151151
var nextPage = factory.nextPageCursor();
@@ -158,7 +158,7 @@ public void sortDepartureDescendingNextPage() {
158158
@Test
159159
public void sortDepartureDescendingCropSearchWindowNextPage() {
160160
var factory = new PageCursorFactory(STREET_AND_DEPARTURE_TIME, D90M)
161-
.withOriginalSearch(NEXT_PAGE, T12_00, T13_30, D1H, List.of())
161+
.withOriginalSearch(NEXT_PAGE, null, T12_00, T13_30, D1H)
162162
.withRemovedItineraries(
163163
new TestPageCursorInput(
164164
newItinerary(A).bus(55, timeAsSeconds(T12_00), timeAsSeconds(T12_30), B).build(),

0 commit comments

Comments
 (0)