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

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

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

import org.opentripplanner.graph_builder.DataImportIssueStore;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.opentripplanner.transit.model.timetable.Direction;

public class DirectionMapper {

  private final DataImportIssueStore issueStore;

  public DirectionMapper(DataImportIssueStore issueStore) {
    this.issueStore = issueStore;
  }

  Direction map(String gtfsCode, FeedScopedId id) {
    try {
      if (gtfsCode == null || gtfsCode.isBlank()) {
        return Direction.UNKNOWN;
      }
      return map(Integer.parseInt(gtfsCode));
    } catch (NumberFormatException e) {
      issueStore.add(
        "InvalidGTFSDirectionId",
        "Trip %s does not have direction id, defaults to -1",
        id
      );
    }
    return Direction.UNKNOWN;
  }

  public Direction map(int gtfsCode) {
    return switch (gtfsCode) {
      case 0 -> Direction.OUTBOUND;
      case 1 -> Direction.INBOUND;
      default -> Direction.UNKNOWN;
    };
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy