Skip to content

Commit

Permalink
Apply review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed May 31, 2024
1 parent ab5ec25 commit 6a73f01
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,19 @@ Iterable<LuceneStopCluster> 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(),
Expand All @@ -90,11 +86,19 @@ LuceneStopCluster map(StopLocationsGroup g) {
);
}

Optional<LuceneStopCluster> map(List<StopLocation> stopLocations) {
private static List<String> getCodes(Collection<StopLocation> childStops) {
return childStops.stream().map(StopLocation::getCode).filter(Objects::nonNull).toList();
}

private static List<I18NString> getNames(Collection<StopLocation> childStops) {
return childStops.stream().map(StopLocation::getName).filter(Objects::nonNull).toList();
}

private static Optional<LuceneStopCluster> map(List<StopLocation> 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())
Expand Down

0 comments on commit 6a73f01

Please sign in to comment.