Skip to content

Commit

Permalink
Rename back to LocationMapper
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Jun 19, 2024
1 parent 98588b8 commit 3ba6c8c
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class GTFSToOtpTransitServiceMapper {

private final BoardingAreaMapper boardingAreaMapper;

private final AreaStopMapper areaStopMapper;
private final LocationMapper locationMapper;

private final LocationGroupMapper locationGroupMapper;

Expand Down Expand Up @@ -110,11 +110,11 @@ public GTFSToOtpTransitServiceMapper(
entranceMapper = new EntranceMapper(translationHelper, stationLookup);
pathwayNodeMapper = new PathwayNodeMapper(translationHelper, stationLookup);
boardingAreaMapper = new BoardingAreaMapper(translationHelper, stopLookup);
areaStopMapper = new AreaStopMapper(builder.stopModel(), issueStore);
locationGroupMapper = new LocationGroupMapper(stopMapper, areaStopMapper, builder.stopModel());
locationMapper = new LocationMapper(builder.stopModel(), issueStore);
locationGroupMapper = new LocationGroupMapper(stopMapper, locationMapper, builder.stopModel());
// the use of stop areas were reverted in the spec
// this code will go away, please migrate now!
stopAreaMapper = new StopAreaMapper(stopMapper, areaStopMapper, builder.stopModel());
stopAreaMapper = new StopAreaMapper(stopMapper, locationMapper, builder.stopModel());
pathwayMapper =
new PathwayMapper(stopMapper, entranceMapper, pathwayNodeMapper, boardingAreaMapper);
routeMapper = new RouteMapper(agencyMapper, issueStore, translationHelper);
Expand All @@ -124,7 +124,7 @@ public GTFSToOtpTransitServiceMapper(
stopTimeMapper =
new StopTimeMapper(
stopMapper,
areaStopMapper,
locationMapper,
locationGroupMapper,
stopAreaMapper,
tripMapper,
Expand Down Expand Up @@ -164,7 +164,7 @@ public void mapStopTripAndRouteDataIntoBuilder() {

if (OTPFeature.FlexRouting.isOn()) {
// Stop areas and Stop groups are only used in FLEX routes
builder.stopModel().withAreaStops(areaStopMapper.map(data.getAllLocations()));
builder.stopModel().withAreaStops(locationMapper.map(data.getAllLocations()));
builder.stopModel().withGroupStops(locationGroupMapper.map(data.getAllLocationGroups()));
builder.stopModel().withGroupStops(stopAreaMapper.map(data.getAllStopAreas()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
public class LocationGroupMapper {

private final StopMapper stopMapper;
private final AreaStopMapper areaStopMapper;
private final LocationMapper locationMapper;
private final StopModelBuilder stopModelBuilder;

private final Map<LocationGroup, GroupStop> mappedLocationGroups = new HashMap<>();

public LocationGroupMapper(
StopMapper stopMapper,
AreaStopMapper areaStopMapper,
LocationMapper locationMapper,
StopModelBuilder stopModelBuilder
) {
this.stopMapper = stopMapper;
this.areaStopMapper = areaStopMapper;
this.locationMapper = locationMapper;
this.stopModelBuilder = stopModelBuilder;
}

Expand All @@ -54,7 +54,7 @@ private GroupStop doMap(LocationGroup element) {
);
switch (location) {
case Stop stop -> groupStopBuilder.addLocation(stopMapper.map(stop));
case Location loc -> groupStopBuilder.addLocation(areaStopMapper.map(loc));
case Location loc -> groupStopBuilder.addLocation(locationMapper.map(loc));
case LocationGroup ignored -> throw new RuntimeException(
"Nested GroupStops are not allowed"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import org.opentripplanner.transit.service.StopModelBuilder;

/** Responsible for mapping GTFS Location into the OTP model. */
public class AreaStopMapper {
public class LocationMapper {

private final Map<Location, AreaStop> mappedLocations = new HashMap<>();
private final StopModelBuilder stopModelBuilder;
private final DataImportIssueStore issueStore;

public AreaStopMapper(StopModelBuilder stopModelBuilder, DataImportIssueStore issueStore) {
public LocationMapper(StopModelBuilder stopModelBuilder, DataImportIssueStore issueStore) {
this.stopModelBuilder = stopModelBuilder;
this.issueStore = issueStore;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ public class StopAreaMapper {

private final StopMapper stopMapper;

private final AreaStopMapper areaStopMapper;
private final LocationMapper locationMapper;

private final Map<org.onebusaway.gtfs.model.StopArea, GroupStop> mappedStopAreas = new HashMap<>();
private final StopModelBuilder stopModel;

public StopAreaMapper(
StopMapper stopMapper,
AreaStopMapper areaStopMapper,
LocationMapper locationMapper,
StopModelBuilder stopModel
) {
this.stopMapper = stopMapper;
this.areaStopMapper = areaStopMapper;
this.locationMapper = locationMapper;
this.stopModel = stopModel;
}

Expand All @@ -57,7 +57,7 @@ private GroupStop doMap(org.onebusaway.gtfs.model.StopArea element) {
for (org.onebusaway.gtfs.model.StopLocation location : element.getLocations()) {
switch (location) {
case Stop stop -> groupStopBuilder.addLocation(stopMapper.map(stop));
case Location loc -> groupStopBuilder.addLocation(areaStopMapper.map(loc));
case Location loc -> groupStopBuilder.addLocation(locationMapper.map(loc));
case org.onebusaway.gtfs.model.StopArea ignored -> throw new RuntimeException(
"Nested GroupStops are not allowed"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class StopTimeMapper {

private final StopMapper stopMapper;

private final AreaStopMapper areaStopMapper;
private final LocationMapper locationMapper;

private final LocationGroupMapper locationGroupMapper;
private final StopAreaMapper stopAreaMapper;
Expand All @@ -33,15 +33,15 @@ class StopTimeMapper {

StopTimeMapper(
StopMapper stopMapper,
AreaStopMapper areaStopMapper,
LocationMapper locationMapper,
LocationGroupMapper locationGroupMapper,
StopAreaMapper stopAreaMapper,
TripMapper tripMapper,
BookingRuleMapper bookingRuleMapper,
TranslationHelper translationHelper
) {
this.stopMapper = stopMapper;
this.areaStopMapper = areaStopMapper;
this.locationMapper = locationMapper;
this.locationGroupMapper = locationGroupMapper;
this.stopAreaMapper = stopAreaMapper;
this.tripMapper = tripMapper;
Expand Down Expand Up @@ -69,7 +69,7 @@ private StopTime doMap(org.onebusaway.gtfs.model.StopTime rhs) {
);
switch (stopLocation) {
case Stop stop -> lhs.setStop(stopMapper.map(stop));
case Location location -> lhs.setStop(areaStopMapper.map(location));
case Location location -> lhs.setStop(locationMapper.map(location));
case LocationGroup locGroup -> lhs.setStop(locationGroupMapper.map(locGroup));
// TODO: only here for backwards compatibility, this will be removed in the future
case StopArea area -> lhs.setStop(stopAreaMapper.map(area));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public class AreaStop
this.url = builder.url();
this.zoneId = builder.zoneId();
this.geometry = builder.geometry();

this.centroid = Objects.requireNonNull(builder.centroid());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void map() {
var builder = StopModel.of();
var mapper = new LocationGroupMapper(
new StopMapper(new TranslationHelper(), id -> null, builder),
new AreaStopMapper(builder, DataImportIssueStore.NOOP),
new LocationMapper(builder, DataImportIssueStore.NOOP),
builder
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.opentripplanner.graph_builder.issue.service.DefaultDataImportIssueStore;
import org.opentripplanner.transit.service.StopModel;

class AreaStopMapperTest {
class LocationMapperTest {

static Stream<Arguments> testCases() {
return Stream.of(Arguments.of(null, true), Arguments.of("a name", false));
Expand All @@ -29,7 +29,7 @@ static Stream<Arguments> testCases() {
void testMapping(String name, boolean isBogusName) {
var gtfsLocation = getLocation(name, Polygons.OSLO);

var mapper = new AreaStopMapper(StopModel.of(), DataImportIssueStore.NOOP);
var mapper = new LocationMapper(StopModel.of(), DataImportIssueStore.NOOP);
var flexLocation = mapper.map(gtfsLocation);

assertEquals(isBogusName, flexLocation.hasFallbackName());
Expand All @@ -43,7 +43,7 @@ void invalidPolygon() {
var gtfsLocation = getLocation("invalid", selfIntersecting);

var issueStore = new DefaultDataImportIssueStore();
var mapper = new AreaStopMapper(StopModel.of(), issueStore);
var mapper = new LocationMapper(StopModel.of(), issueStore);

mapper.map(gtfsLocation);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class StopAreaMapperTest {
void map() {
var stopModel = StopModel.of();
var stopMapper = new StopMapper(new TranslationHelper(), ignored -> null, stopModel);
var locationMapper = new AreaStopMapper(stopModel, NOOP);
var locationMapper = new LocationMapper(stopModel, NOOP);
var mapper = new StopAreaMapper(stopMapper, locationMapper, stopModel);

var area = new Area();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,24 @@ public class StopTimeMapperTest {
stopModelBuilder
);
private final BookingRuleMapper bookingRuleMapper = new BookingRuleMapper();
private final AreaStopMapper areaStopMapper = new AreaStopMapper(
private final LocationMapper locationMapper = new LocationMapper(
stopModelBuilder,
DataImportIssueStore.NOOP
);
private final LocationGroupMapper locationGroupMapper = new LocationGroupMapper(
stopMapper,
areaStopMapper,
locationMapper,
stopModelBuilder
);
private final StopAreaMapper stopAreaMapper = new StopAreaMapper(
stopMapper,
areaStopMapper,
locationMapper,
stopModelBuilder
);
private final TranslationHelper translationHelper = new TranslationHelper();
private final StopTimeMapper subject = new StopTimeMapper(
stopMapper,
areaStopMapper,
locationMapper,
locationGroupMapper,
stopAreaMapper,
new TripMapper(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class TransferMapperTest {
);
private static final BookingRuleMapper BOOKING_RULE_MAPPER = new BookingRuleMapper();

private static final AreaStopMapper LOCATION_MAPPER = new AreaStopMapper(
private static final LocationMapper LOCATION_MAPPER = new LocationMapper(
STOP_MODEL_BUILDER,
ISSUE_STORE
);
Expand Down

0 comments on commit 3ba6c8c

Please sign in to comment.