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

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

package org.opentripplanner.gtfs.mapping;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.opentripplanner.model.ShapePoint;
import org.opentripplanner.util.MapUtils;

/** Responsible for mapping GTFS ShapePoint into the OTP model. */
class ShapePointMapper {

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

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

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

  private ShapePoint doMap(org.onebusaway.gtfs.model.ShapePoint rhs) {
    ShapePoint lhs = new ShapePoint();

    lhs.setShapeId(AgencyAndIdMapper.mapAgencyAndId(rhs.getShapeId()));
    lhs.setSequence(rhs.getSequence());
    lhs.setLat(rhs.getLat());
    lhs.setLon(rhs.getLon());
    lhs.setDistTraveled(rhs.getDistTraveled());

    // Skip mapping of proxy
    // private transient StopTimeProxy proxy;
    if (rhs.getProxy() != null) {
      throw new IllegalStateException("Did not expect proxy to be set! Data: " + rhs);
    }

    return lhs;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy