Skip to content

Commit

Permalink
Enforce non-null coordinates on multimodal station
Browse files Browse the repository at this point in the history
  • Loading branch information
vpaturet committed Jul 16, 2024
1 parent 6d9ff33 commit 0d638f8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.opentripplanner.netex.mapping;

import java.util.Collection;
import javax.annotation.Nullable;
import org.opentripplanner.framework.geometry.WgsCoordinate;
import org.opentripplanner.framework.i18n.NonLocalizedString;
import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore;
Expand All @@ -21,6 +22,7 @@ public MultiModalStationMapper(DataImportIssueStore issueStore, FeedScopedIdFact
this.idFactory = idFactory;
}

@Nullable
MultiModalStation map(StopPlace stopPlace, Collection<Station> childStations) {
MultiModalStationBuilder multiModalStation = MultiModalStation
.of(idFactory.createId(stopPlace.getId()))
Expand All @@ -34,13 +36,13 @@ MultiModalStation map(StopPlace stopPlace, Collection<Station> childStations) {
if (coordinate == null) {
issueStore.add(
"MultiModalStationWithoutCoordinates",
"MultiModal station {} does not contain any coordinates.",
"MultiModal station %s does not contain any coordinates.",
multiModalStation.getId()
);
return null;
} else {
multiModalStation.withCoordinate(coordinate);
return multiModalStation.build();
}

return multiModalStation.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,9 @@ private void mapMultiModalStopPlaces() {
.getStationsByMultiModalStationRfs()
.get(multiModalStopPlace.getId());
var multiModalStation = mapper.map(multiModalStopPlace, stations);

transitBuilder.stopModel().withMultiModalStation(multiModalStation);
if (multiModalStation != null) {
transitBuilder.stopModel().withMultiModalStation(multiModalStation);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public class MultiModalStation
super(builder.getId());
// Required fields
this.childStations = Objects.requireNonNull(builder.childStations());
this.coordinate = Objects.requireNonNull(builder.coordinate());
this.name = I18NString.assertHasValue(builder.name());

// Optional fields
// TODO Make required
this.coordinate = builder.coordinate();
this.code = builder.code();
this.description = builder.description();
this.url = builder.url();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.util.Set;
import org.junit.jupiter.api.Test;
import org.opentripplanner.framework.geometry.WgsCoordinate;
import org.opentripplanner.framework.i18n.I18NString;
import org.opentripplanner.framework.i18n.NonLocalizedString;
import org.opentripplanner.transit.model._data.TransitModelForTest;
Expand All @@ -26,6 +27,7 @@ class MultiModalStationTest {
.of(TransitModelForTest.id(ID))
.withName(NAME)
.withChildStations(CHILD_STATIONS)
.withCoordinate(new WgsCoordinate(1, 1))
.build();

@Test
Expand Down

0 comments on commit 0d638f8

Please sign in to comment.