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

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

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

import org.opentripplanner.model.Agency;
import org.opentripplanner.model.FeedScopedId;
import org.opentripplanner.util.MapUtils;

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

/** Responsible for mapping GTFS Agency into the OTP model. */
class AgencyMapper {

    private final Map mappedAgencies = new HashMap<>();

    private String feedId;

    public AgencyMapper(String feedId) {
        this.feedId = feedId;
    }

    Collection map(Collection agencies) {
        return MapUtils.mapToList(agencies, this::map);
    }

    /** Map from GTFS to OTP model, {@code null} safe.  */
    Agency map(org.onebusaway.gtfs.model.Agency orginal) {
        return orginal == null ? null : mappedAgencies.computeIfAbsent(orginal, this::doMap);
    }

    private Agency doMap(org.onebusaway.gtfs.model.Agency rhs) {
        Agency lhs = new Agency(
            new FeedScopedId(feedId, rhs.getId()),
            rhs.getName(),
            rhs.getTimezone()
        );

        lhs.setUrl(rhs.getUrl());
        lhs.setLang(rhs.getLang());
        lhs.setPhone(rhs.getPhone());
        lhs.setFareUrl(rhs.getFareUrl());
        lhs.setBrandingUrl(rhs.getBrandingUrl());

        return lhs;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy