
org.opentripplanner.gtfs.mapping.StopTimeMapper Maven / Gradle / Ivy
package org.opentripplanner.gtfs.mapping;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.onebusaway.gtfs.model.Location;
import org.onebusaway.gtfs.model.LocationGroup;
import org.onebusaway.gtfs.model.Stop;
import org.opentripplanner.model.StopTime;
import org.opentripplanner.transit.model.basic.I18NString;
import org.opentripplanner.transit.model.basic.NonLocalizedString;
import org.opentripplanner.util.MapUtils;
/**
* Responsible for mapping GTFS StopTime into the OTP Transit model.
*/
class StopTimeMapper {
private final StopMapper stopMapper;
private final LocationMapper locationMapper;
private final LocationGroupMapper locationGroupMapper;
private final TripMapper tripMapper;
private final BookingRuleMapper bookingRuleMapper;
private final Map mappedStopTimes = new HashMap<>();
private final TranslationHelper translationHelper;
StopTimeMapper(
StopMapper stopMapper,
LocationMapper locationMapper,
LocationGroupMapper locationGroupMapper,
TripMapper tripMapper,
BookingRuleMapper bookingRuleMapper,
TranslationHelper translationHelper
) {
this.stopMapper = stopMapper;
this.locationMapper = locationMapper;
this.locationGroupMapper = locationGroupMapper;
this.tripMapper = tripMapper;
this.bookingRuleMapper = bookingRuleMapper;
this.translationHelper = translationHelper;
}
Collection map(Collection times) {
return MapUtils.mapToList(times, this::map);
}
/** Map from GTFS to OTP model, {@code null} safe. */
StopTime map(org.onebusaway.gtfs.model.StopTime orginal) {
return orginal == null ? null : mappedStopTimes.computeIfAbsent(orginal, this::doMap);
}
private StopTime doMap(org.onebusaway.gtfs.model.StopTime rhs) {
StopTime lhs = new StopTime();
lhs.setTrip(tripMapper.map(rhs.getTrip()));
if (rhs.getStop() instanceof Stop) {
lhs.setStop(stopMapper.map((Stop) rhs.getStop()));
} else if (rhs.getStop() instanceof Location) {
lhs.setStop(locationMapper.map((Location) rhs.getStop()));
} else if (rhs.getStop() instanceof LocationGroup) {
lhs.setStop(locationGroupMapper.map((LocationGroup) rhs.getStop()));
}
I18NString stopHeadsign = null;
if (rhs.getStopHeadsign() != null) {
stopHeadsign =
translationHelper.getTranslation(
org.onebusaway.gtfs.model.StopTime.class,
"stopHeadsign",
rhs.getTrip().getId().toString(),
Integer.toString(rhs.getStopSequence()),
rhs.getStopHeadsign()
);
}
lhs.setArrivalTime(rhs.getArrivalTime());
lhs.setDepartureTime(rhs.getDepartureTime());
lhs.setTimepoint(rhs.getTimepoint());
lhs.setStopSequence(rhs.getStopSequence());
lhs.setStopHeadsign(stopHeadsign);
lhs.setRouteShortName(rhs.getRouteShortName());
lhs.setPickupType(PickDropMapper.map(rhs.getPickupType()));
lhs.setDropOffType(PickDropMapper.map(rhs.getDropOffType()));
lhs.setShapeDistTraveled(rhs.getShapeDistTraveled());
lhs.setFarePeriodId(rhs.getFarePeriodId());
lhs.setFlexWindowStart(rhs.getStartPickupDropOffWindow());
lhs.setFlexWindowEnd(rhs.getEndPickupDropOffWindow());
lhs.setFlexContinuousPickup(
PickDropMapper.mapFlexContinuousPickDrop(rhs.getContinuousPickup())
);
lhs.setFlexContinuousDropOff(
PickDropMapper.mapFlexContinuousPickDrop(rhs.getContinuousDropOff())
);
lhs.setPickupBookingInfo(bookingRuleMapper.map(rhs.getPickupBookingRule()));
lhs.setDropOffBookingInfo(bookingRuleMapper.map(rhs.getDropOffBookingRule()));
// Skip mapping of proxy
// private transient StopTimeProxy proxy;
if (rhs.getProxy() != null) {
throw new IllegalStateException("Did not expect proxy to be set!");
}
return lhs;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy