From ab5ec25ca1b86995bd567b9d2ec1ab1f1d514fc4 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Fri, 31 May 2024 10:39:18 +0200 Subject: [PATCH] Use cast to extract code --- .../ext/geocoder/StopClusterMapper.java | 13 ++++++++++++- .../transit/model/site/GroupOfStations.java | 6 ------ .../transit/model/site/StopLocationsGroup.java | 4 ---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/ext/java/org/opentripplanner/ext/geocoder/StopClusterMapper.java b/src/ext/java/org/opentripplanner/ext/geocoder/StopClusterMapper.java index de8d2681fd9..fbb9941c59c 100644 --- a/src/ext/java/org/opentripplanner/ext/geocoder/StopClusterMapper.java +++ b/src/ext/java/org/opentripplanner/ext/geocoder/StopClusterMapper.java @@ -9,6 +9,7 @@ import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; +import javax.annotation.Nullable; import org.opentripplanner.framework.collection.ListUtils; import org.opentripplanner.framework.geometry.WgsCoordinate; import org.opentripplanner.framework.i18n.I18NString; @@ -16,6 +17,7 @@ import org.opentripplanner.transit.model.framework.FeedScopedId; import org.opentripplanner.transit.model.network.Route; import org.opentripplanner.transit.model.organization.Agency; +import org.opentripplanner.transit.model.site.Station; import org.opentripplanner.transit.model.site.StopLocation; import org.opentripplanner.transit.model.site.StopLocationsGroup; import org.opentripplanner.transit.service.TransitService; @@ -153,7 +155,7 @@ StopCluster.Location toLocation(FeedScopedId id) { .toList(); return new StopCluster.Location( group.getId(), - group.getCode(), + extractCode(group), STATION, group.getName().toString(), new StopCluster.Coordinate(group.getLat(), group.getLon()), @@ -164,6 +166,15 @@ StopCluster.Location toLocation(FeedScopedId id) { } } + @Nullable + private static String extractCode(StopLocationsGroup group) { + if (group instanceof Station station) { + return station.getCode(); + } else { + return null; + } + } + private static StopCluster.Coordinate toCoordinate(WgsCoordinate c) { return new StopCluster.Coordinate(c.latitude(), c.longitude()); } diff --git a/src/main/java/org/opentripplanner/transit/model/site/GroupOfStations.java b/src/main/java/org/opentripplanner/transit/model/site/GroupOfStations.java index 66b45317718..c62d6099c97 100644 --- a/src/main/java/org/opentripplanner/transit/model/site/GroupOfStations.java +++ b/src/main/java/org/opentripplanner/transit/model/site/GroupOfStations.java @@ -51,12 +51,6 @@ public WgsCoordinate getCoordinate() { return coordinate; } - @Nullable - @Override - public String getCode() { - return null; - } - @Nonnull public Collection getChildStops() { return this.childStations.stream().flatMap(s -> s.getChildStops().stream()).toList(); diff --git a/src/main/java/org/opentripplanner/transit/model/site/StopLocationsGroup.java b/src/main/java/org/opentripplanner/transit/model/site/StopLocationsGroup.java index 70b2ee45a81..3536f59e9b6 100644 --- a/src/main/java/org/opentripplanner/transit/model/site/StopLocationsGroup.java +++ b/src/main/java/org/opentripplanner/transit/model/site/StopLocationsGroup.java @@ -1,7 +1,6 @@ package org.opentripplanner.transit.model.site; import java.util.Collection; -import javax.annotation.Nullable; import org.opentripplanner.framework.geometry.WgsCoordinate; import org.opentripplanner.framework.i18n.I18NString; import org.opentripplanner.framework.lang.ObjectUtils; @@ -40,7 +39,4 @@ default double getLon() { default String logName() { return ObjectUtils.ifNotNull(getName(), Object::toString, null); } - - @Nullable - String getCode(); }