Skip to content

Commit 7692ef1

Browse files
Apply review feedback
1 parent 85d762a commit 7692ef1

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

src/ext/java/org/opentripplanner/ext/stopconsolidation/DecorateConsolidatedStopNames.java

+25-9
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import org.opentripplanner.routing.algorithm.filterchain.framework.spi.ItineraryDecorator;
88

99
/**
10-
* A decorating filter that checks if a transit leg contains any primary stops and if it does,
11-
* then replaces it with the secondary, agency-specific stop name. This is so that the in-vehicle
12-
* display matches what OTP returns as a board/alight stop name.
10+
* A decorating filter that checks if a transit leg contains any consolidated stops and if it does,
11+
* then replaces it with the appropriate, agency-specific stop name. This is so that the physical
12+
* signage and in-vehicle display matches what OTP returns as a board/alight stop name.
1313
*/
1414
public class DecorateConsolidatedStopNames implements ItineraryDecorator {
1515

@@ -21,20 +21,28 @@ public DecorateConsolidatedStopNames(StopConsolidationService service) {
2121

2222
@Override
2323
public void decorate(Itinerary itinerary) {
24-
replacePrimaryNamesWithSecondary(itinerary);
24+
replaceConsolidatedStops(itinerary);
2525
}
2626

2727
/**
28-
* If the itinerary has a from/to that is the primary stop of a {@link org.opentripplanner.ext.stopconsolidation.model.ConsolidatedStopGroup}
29-
* then we replace its name with the secondary name of the agency that is
30-
* operating the route, so that the name in the result matches the name in the in-vehicle
31-
* display.
28+
* If the itinerary has a "from" stop that is the secondary stop of a
29+
* {@link org.opentripplanner.ext.stopconsolidation.model.ConsolidatedStopGroup}
30+
* then we replace its name with the primary name of the agency that is
31+
* operating the route, so that the name in the result matches the physical signage on the stop.
32+
* <p>
33+
* If the leg has a "to" stop that is a primary stop, then we don't want to show the stop that's on
34+
* the signage but what is shown _inside_ the vehicle. That's why we use the agency-specific (aka
35+
* secondary) stop.
36+
* <p>
37+
* This follows the somewhat idiosyncratic logic of the consolidated stops feature.
3238
*/
33-
private void replacePrimaryNamesWithSecondary(Itinerary i) {
39+
private void replaceConsolidatedStops(Itinerary i) {
3440
i.transformTransitLegs(leg -> {
3541
if (leg instanceof ScheduledTransitLeg stl && needsToRenameStops(stl)) {
3642
var agency = leg.getAgency();
43+
// to show the name on the stop signage we use the primary stop's name
3744
var from = service.primaryStop(stl.getFrom().stop.getId());
45+
// to show the name that's on the display inside the vehicle we use the agency-specific name
3846
var to = service.agencySpecificStop(stl.getTo().stop, agency);
3947
return new ConsolidatedStopLeg(stl, from, to);
4048
} else {
@@ -43,6 +51,14 @@ private void replacePrimaryNamesWithSecondary(Itinerary i) {
4351
});
4452
}
4553

54+
/**
55+
* Figures out if the from/to stops are part of a consolidated stop group and therefore
56+
* some stops need to be replaced.
57+
* <p>
58+
* Please consult the Javadoc of {@link DecorateConsolidatedStopNames#replaceConsolidatedStops(Itinerary)}
59+
* for details of this idiosyncratic business logic and in particular why the logic is not the same
60+
* for the from/to stops.
61+
*/
4662
private boolean needsToRenameStops(ScheduledTransitLeg stl) {
4763
return (service.isSecondaryStop(stl.getFrom().stop) || service.isPrimaryStop(stl.getTo().stop));
4864
}

src/ext/java/org/opentripplanner/ext/stopconsolidation/internal/DefaultStopConsolidationService.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ public StopLocation agencySpecificStop(StopLocation stop, Agency agency) {
7777
if (agency.getId().getFeedId().equals(stop.getId().getFeedId())) {
7878
return stop;
7979
} else {
80-
return agencySpecificStopOpt(stop, agency).orElse(stop);
80+
return findAgencySpecificStop(stop, agency).orElse(stop);
8181
}
8282
}
8383

8484
@Nonnull
85-
private Optional<StopLocation> agencySpecificStopOpt(StopLocation stop, Agency agency) {
85+
private Optional<StopLocation> findAgencySpecificStop(StopLocation stop, Agency agency) {
8686
return repo
8787
.groups()
8888
.stream()

0 commit comments

Comments
 (0)