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

org.opentripplanner.ext.legacygraphqlapi.datafetchers.LegacyGraphQLStoptimeImpl Maven / Gradle / Ivy

There is a newer version: 2.6.0
Show newest version
package org.opentripplanner.ext.legacygraphqlapi.datafetchers;

import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import org.opentripplanner.ext.legacygraphqlapi.LegacyGraphQLRequestContext;
import org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLDataFetchers;
import org.opentripplanner.model.Trip;
import org.opentripplanner.model.TripTimeShort;
import org.opentripplanner.routing.RoutingService;

public class LegacyGraphQLStoptimeImpl implements LegacyGraphQLDataFetchers.LegacyGraphQLStoptime {

  @Override
  public DataFetcher stop() {
    return environment -> getRoutingService(environment).getStopForId(getSource(environment).stopId);
  }

  @Override
  public DataFetcher scheduledArrival() {
    return environment -> getSource(environment).scheduledArrival;
  }

  @Override
  public DataFetcher realtimeArrival() {
    return environment -> getSource(environment).realtimeArrival;
  }

  @Override
  public DataFetcher arrivalDelay() {
    return environment -> getSource(environment).arrivalDelay;
  }

  @Override
  public DataFetcher scheduledDeparture() {
    return environment -> getSource(environment).scheduledDeparture;
  }

  @Override
  public DataFetcher realtimeDeparture() {
    return environment -> getSource(environment).realtimeDeparture;
  }

  @Override
  public DataFetcher departureDelay() {
    return environment -> getSource(environment).departureDelay;
  }

  @Override
  public DataFetcher timepoint() {
    return environment -> getSource(environment).timepoint;
  }

  @Override
  public DataFetcher realtime() {
    return environment -> getSource(environment).realtime;
  }

  @Override
  public DataFetcher realtimeState() {
    return environment -> getSource(environment).realtimeState.name();
  }

  @Override
  public DataFetcher pickupType() {
    return environment -> {
      switch (getSource(environment).pickupType) {
        case 0: return "SCHEDULED";
        case 1: return "NONE";
        case 2: return "CALL_AGENCY";
        case 3: return "COORDINATE_WITH_DRIVER";
        default: return null;
      }
    };
  }

  @Override
  public DataFetcher dropoffType() {
    return environment -> {
      switch (getSource(environment).dropoffType) {
        case 0: return "SCHEDULED";
        case 1: return "NONE";
        case 2: return "CALL_AGENCY";
        case 3: return "COORDINATE_WITH_DRIVER";
        default: return null;
      }
    };
  }

  @Override
  public DataFetcher serviceDay() {
    return environment -> getSource(environment).serviceDay;
  }

  @Override
  public DataFetcher trip() {
    return environment -> getRoutingService(environment).getTripForId().get(getSource(environment).tripId);
  }

  @Override
  public DataFetcher headsign() {
    return environment -> getSource(environment).headsign;
  }

  private RoutingService getRoutingService(DataFetchingEnvironment environment) {
    return environment.getContext().getRoutingService();
  }

  private TripTimeShort getSource(DataFetchingEnvironment environment) {
    return environment.getSource();
  }
}