All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentripplanner.gtfs.mapping.FareRuleMapper Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
package org.opentripplanner.gtfs.mapping;

import org.opentripplanner.model.FareRule;
import org.opentripplanner.util.MapUtils;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/** Responsible for mapping GTFS FareRule into the OTP model. */
class FareRuleMapper {

    private final RouteMapper routeMapper;

    private final FareAttributeMapper fareAttributeMapper;

    private 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 - 2024 Weber Informatics LLC | Privacy Policy