Skip to content

Commit

Permalink
Add ID to mapper error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Sep 18, 2023
1 parent 72dcf51 commit 0f4588a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 32 deletions.
39 changes: 13 additions & 26 deletions src/main/java/org/opentripplanner/gtfs/mapping/StationMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.time.ZoneId;
import java.util.HashMap;
import java.util.Map;
import org.onebusaway.gtfs.model.Stop;
import org.opentripplanner.transit.model.site.Station;
import org.opentripplanner.transit.model.site.StationBuilder;
import org.opentripplanner.transit.model.site.StopTransferPriority;
Expand All @@ -21,7 +22,7 @@
class StationMapper {

/** @see StationMapper (this class JavaDoc) for way we need this. */
private final Map<org.onebusaway.gtfs.model.Stop, Station> mappedStops = new HashMap<>();
private final Map<Stop, Station> mappedStops = new HashMap<>();

private final TranslationHelper translationHelper;
private final StopTransferPriority stationTransferPreference;
Expand All @@ -35,17 +36,18 @@ class StationMapper {
}

/** Map from GTFS to OTP model, {@code null} safe. */
Station map(org.onebusaway.gtfs.model.Stop orginal) {
Station map(Stop orginal) {
return orginal == null ? null : mappedStops.computeIfAbsent(orginal, this::doMap);
}

private Station doMap(org.onebusaway.gtfs.model.Stop rhs) {
if (rhs.getLocationType() != org.onebusaway.gtfs.model.Stop.LOCATION_TYPE_STATION) {
private Station doMap(Stop rhs) {
if (rhs.getLocationType() != Stop.LOCATION_TYPE_STATION) {
throw new IllegalArgumentException(
"Expected type " +
org.onebusaway.gtfs.model.Stop.LOCATION_TYPE_STATION +
", but got " +
rhs.getLocationType()
"Expected location_type %s, but got %s for stops.txt entry %s".formatted(
Stop.LOCATION_TYPE_STATION,
rhs.getLocationType(),
rhs
)
);
}
StationBuilder builder = Station
Expand All @@ -54,30 +56,15 @@ private Station doMap(org.onebusaway.gtfs.model.Stop rhs) {
.withCode(rhs.getCode());

builder.withName(
translationHelper.getTranslation(
org.onebusaway.gtfs.model.Stop.class,
"name",
rhs.getId().getId(),
rhs.getName()
)
translationHelper.getTranslation(Stop.class, "name", rhs.getId().getId(), rhs.getName())
);

builder.withDescription(
translationHelper.getTranslation(
org.onebusaway.gtfs.model.Stop.class,
"desc",
rhs.getId().getId(),
rhs.getDesc()
)
translationHelper.getTranslation(Stop.class, "desc", rhs.getId().getId(), rhs.getDesc())
);

builder.withUrl(
translationHelper.getTranslation(
org.onebusaway.gtfs.model.Stop.class,
"url",
rhs.getId().getId(),
rhs.getUrl()
)
translationHelper.getTranslation(Stop.class, "url", rhs.getId().getId(), rhs.getUrl())
);

builder.withPriority(stationTransferPreference);
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/opentripplanner/gtfs/mapping/StopMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import org.onebusaway.gtfs.model.Stop;
import org.opentripplanner.framework.collection.MapUtils;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.opentripplanner.transit.model.site.FareZone;
Expand Down Expand Up @@ -37,12 +38,11 @@ RegularStop map(org.onebusaway.gtfs.model.Stop orginal) {
private RegularStop doMap(org.onebusaway.gtfs.model.Stop gtfsStop) {
if (gtfsStop.getLocationType() != org.onebusaway.gtfs.model.Stop.LOCATION_TYPE_STOP) {
throw new IllegalArgumentException(
"Expected type " +
org.onebusaway.gtfs.model.Stop.LOCATION_TYPE_STOP +
", but got " +
gtfsStop.getLocationType() +
" from stop " +
gtfsStop
"Expected location_type %s, but got %s for stops.txt entry %s".formatted(
Stop.LOCATION_TYPE_STOP,
gtfsStop.getLocationType(),
gtfsStop
)
);
}

Expand Down

0 comments on commit 0f4588a

Please sign in to comment.