From 6a73f0140556c0a4c99a731ec0f2c438028062fe Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Fri, 31 May 2024 23:52:15 +0200 Subject: [PATCH] Apply review feedback --- .../ext/geocoder/LuceneIndexTest.java | 14 +++++----- .../ext/geocoder/StopClusterMapper.java | 28 +++++++++++-------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/ext-test/java/org/opentripplanner/ext/geocoder/LuceneIndexTest.java b/src/ext-test/java/org/opentripplanner/ext/geocoder/LuceneIndexTest.java index 15f205ad802..cee6cf3a2d8 100644 --- a/src/ext-test/java/org/opentripplanner/ext/geocoder/LuceneIndexTest.java +++ b/src/ext-test/java/org/opentripplanner/ext/geocoder/LuceneIndexTest.java @@ -277,17 +277,17 @@ void fuzzyStopCode(String query) { void modes() { var result = index.queryStopClusters("westh").toList(); assertEquals(1, result.size()); - var stop = result.getFirst(); - assertEquals(WESTHAFEN.getName().toString(), stop.primary().name()); - assertEquals(List.of(FERRY.name(), BUS.name()), stop.primary().modes()); + var cluster = result.getFirst(); + assertEquals(WESTHAFEN.getName().toString(), cluster.primary().name()); + assertEquals(List.of(FERRY.name(), BUS.name()), cluster.primary().modes()); } @Test void agenciesAndFeedPublisher() { - var result = index.queryStopClusters("alexanderplatz").toList().getFirst(); - assertEquals(ALEXANDERPLATZ_STATION.getName().toString(), result.primary().name()); - assertEquals(List.of(StopClusterMapper.toAgency(BVG)), result.primary().agencies()); - assertEquals("A Publisher", result.primary().feedPublisher().name()); + var cluster = index.queryStopClusters("alexanderplatz").toList().getFirst(); + assertEquals(ALEXANDERPLATZ_STATION.getName().toString(), cluster.primary().name()); + assertEquals(List.of(StopClusterMapper.toAgency(BVG)), cluster.primary().agencies()); + assertEquals("A Publisher", cluster.primary().feedPublisher().name()); } } diff --git a/src/ext/java/org/opentripplanner/ext/geocoder/StopClusterMapper.java b/src/ext/java/org/opentripplanner/ext/geocoder/StopClusterMapper.java index fbb9941c59c..d9f388ea0e8 100644 --- a/src/ext/java/org/opentripplanner/ext/geocoder/StopClusterMapper.java +++ b/src/ext/java/org/opentripplanner/ext/geocoder/StopClusterMapper.java @@ -63,23 +63,19 @@ Iterable generateStopClusters( ) .values() .stream() - .map(group -> this.map(group).orElse(null)) + .map(group -> map(group).orElse(null)) .filter(Objects::nonNull) .toList(); - var stations = stopLocationsGroups.stream().map(this::map).toList(); + var stations = stopLocationsGroups.stream().map(StopClusterMapper::map).toList(); return Iterables.concat(deduplicatedStops, stations); } - LuceneStopCluster map(StopLocationsGroup g) { + private static LuceneStopCluster map(StopLocationsGroup g) { var childStops = g.getChildStops(); var ids = childStops.stream().map(s -> s.getId().toString()).toList(); - var childNames = childStops - .stream() - .map(StopLocation::getName) - .filter(Objects::nonNull) - .toList(); - var codes = childStops.stream().map(StopLocation::getCode).filter(Objects::nonNull).toList(); + var childNames = getNames(childStops); + var codes = getCodes(childStops); return new LuceneStopCluster( g.getId().toString(), @@ -90,11 +86,19 @@ LuceneStopCluster map(StopLocationsGroup g) { ); } - Optional map(List stopLocations) { + private static List getCodes(Collection childStops) { + return childStops.stream().map(StopLocation::getCode).filter(Objects::nonNull).toList(); + } + + private static List getNames(Collection childStops) { + return childStops.stream().map(StopLocation::getName).filter(Objects::nonNull).toList(); + } + + private static Optional map(List stopLocations) { var primary = stopLocations.getFirst(); var secondaryIds = stopLocations.stream().skip(1).map(sl -> sl.getId().toString()).toList(); - var names = stopLocations.stream().map(StopLocation::getName).toList(); - var codes = stopLocations.stream().map(StopLocation::getCode).filter(Objects::nonNull).toList(); + var names = getNames(stopLocations); + var codes = getCodes(stopLocations); return Optional .ofNullable(primary.getName())