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

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

The newest version!
package org.opentripplanner.gtfs.mapping;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.opentripplanner.transit.model.organization.Agency;
import org.opentripplanner.utils.collection.MapUtils;

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

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

  private final 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) {
    return Agency.of(new FeedScopedId(feedId, rhs.getId()))
      .withName(rhs.getName())
      .withTimezone(rhs.getTimezone())
      .withUrl(rhs.getUrl())
      .withLang(rhs.getLang())
      .withPhone(rhs.getPhone())
      .withFareUrl(rhs.getFareUrl())
      .build();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy