org.opentripplanner.gtfs.mapping.FareRuleMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of otp Show documentation
Show all versions of otp Show documentation
The OpenTripPlanner multimodal journey planning system
package org.opentripplanner.gtfs.mapping;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.opentripplanner.ext.fares.model.FareRule;
import org.opentripplanner.util.MapUtils;
/** Responsible for mapping GTFS FareRule into the OTP model. */
class FareRuleMapper {
private final RouteMapper routeMapper;
private final FareAttributeMapper fareAttributeMapper;
private final Map mappedFareRules = new HashMap<>();
FareRuleMapper(RouteMapper routeMapper, FareAttributeMapper fareAttributeMapper) {
this.routeMapper = routeMapper;
this.fareAttributeMapper = fareAttributeMapper;
}
Collection map(Collection allFareRules) {
return MapUtils.mapToList(allFareRules, this::map);
}
/** Map from GTFS to OTP model, {@code null} safe. */
FareRule map(org.onebusaway.gtfs.model.FareRule orginal) {
return orginal == null ? null : mappedFareRules.computeIfAbsent(orginal, this::doMap);
}
private FareRule doMap(org.onebusaway.gtfs.model.FareRule rhs) {
FareRule lhs = new FareRule();
lhs.setFare(fareAttributeMapper.map(rhs.getFare()));
lhs.setRoute(routeMapper.map(rhs.getRoute()));
lhs.setOriginId(rhs.getOriginId());
lhs.setDestinationId(rhs.getDestinationId());
lhs.setContainsId(rhs.getContainsId());
return lhs;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy