Skip to content

Commit 514f5f9

Browse files
author
Max Gosau
committed
Extend deduplication of OsmBoardingLocationVertex to all platform types
1 parent bd2ed16 commit 514f5f9

File tree

1 file changed

+39
-34
lines changed

1 file changed

+39
-34
lines changed

application/src/main/java/org/opentripplanner/graph_builder/module/OsmBoardingLocationsModule.java

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public class OsmBoardingLocationsModule implements GraphBuilderModule {
7474
private final VertexFactory vertexFactory;
7575
private final VertexLinker linker;
7676

77-
private final Map<Area, OsmBoardingLocationVertex> existingBoardingLocationsAtAreas;
77+
private final Map<Platform, OsmBoardingLocationVertex> existingBoardingLocationsAtAreas;
7878

7979
/**
8080
* @param timetableRepository This module requires the timetable repository because at the time
@@ -172,7 +172,11 @@ private boolean connectVertexToArea(TransitStopVertex ts, Graph graph) {
172172
if (platOpt.isPresent()) {
173173
var platform = platOpt.get();
174174
if (matchesReference(stop, platform.references())) {
175-
var boardingLocation = makeBoardingLocationForArea(stop, area, platform);
175+
var boardingLocation = getOrMakeBoardingLocationForPlatform(
176+
stop,
177+
platform,
178+
area.getName()
179+
);
176180
linker.addPermanentAreaVertex(boardingLocation, areaGroup);
177181
linkBoardingLocationToStop(ts, stop.getCode(), boardingLocation);
178182
return true;
@@ -203,26 +207,32 @@ private boolean connectVertexToWay(TransitStopVertex ts, RegularStop stop, Graph
203207
});
204208
}
205209

206-
for (var platformEdgeList : nearbyEdges.entrySet()) {
207-
Platform platform = platformEdgeList.getKey();
208-
var name = platform.name();
209-
var boardingLocation = makeBoardingLocation(
210-
stop,
211-
platform.geometry().getCentroid(),
212-
platform.references(),
213-
name
214-
);
215-
for (var vertex : linker.linkToSpecificStreetEdgesPermanently(
216-
boardingLocation,
217-
new TraverseModeSet(TraverseMode.WALK),
218-
LinkingDirection.BIDIRECTIONAL,
219-
platformEdgeList.getValue().stream().map(StreetEdge.class::cast).collect(Collectors.toSet())
220-
)) {
221-
linkBoardingLocationToStop(ts, stop.getCode(), vertex);
222-
}
223-
return true;
224-
}
225-
return false;
210+
return nearbyEdges
211+
.entrySet()
212+
.stream()
213+
.findFirst()
214+
.map(platformEdgeList -> {
215+
Platform platform = platformEdgeList.getKey();
216+
var boardingLocation = getOrMakeBoardingLocationForPlatform(
217+
stop,
218+
platform,
219+
platform.name()
220+
);
221+
for (var vertex : linker.linkToSpecificStreetEdgesPermanently(
222+
boardingLocation,
223+
new TraverseModeSet(TraverseMode.WALK),
224+
LinkingDirection.BIDIRECTIONAL,
225+
platformEdgeList
226+
.getValue()
227+
.stream()
228+
.map(StreetEdge.class::cast)
229+
.collect(Collectors.toSet())
230+
)) {
231+
linkBoardingLocationToStop(ts, stop.getCode(), vertex);
232+
}
233+
return true;
234+
})
235+
.orElse(false);
226236
}
227237

228238
/**
@@ -259,21 +269,16 @@ private boolean connectVertexToNode(TransitStopVertex ts, RegularStop stop, Grap
259269
}
260270

261271
/*
262-
* when two stops reference the same OSM platform area, only one
263-
* OsmBoardingLocationVertex centroid is created for that area and both stops are linked to it.
272+
* when two or more stops reference the same OSM platform, only one
273+
* OsmBoardingLocationVertex is created for that platform and both stops are linked to it.
264274
*/
265-
private OsmBoardingLocationVertex makeBoardingLocationForArea(
275+
private OsmBoardingLocationVertex getOrMakeBoardingLocationForPlatform(
266276
RegularStop stop,
267-
Area area,
268-
Platform platform
277+
Platform platform,
278+
I18NString name
269279
) {
270-
return existingBoardingLocationsAtAreas.computeIfAbsent(area, _ ->
271-
makeBoardingLocation(
272-
stop,
273-
platform.geometry().getCentroid(),
274-
platform.references(),
275-
area.getName()
276-
)
280+
return existingBoardingLocationsAtAreas.computeIfAbsent(platform, _ ->
281+
makeBoardingLocation(stop, platform.geometry().getCentroid(), platform.references(), name)
277282
);
278283
}
279284

0 commit comments

Comments
 (0)