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

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

package org.opentripplanner.ext.legacygraphqlapi.datafetchers;

import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLDataFetchers;
import org.opentripplanner.model.plan.Itinerary;
import org.opentripplanner.model.plan.Leg;
import org.opentripplanner.routing.core.Fare;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class LegacyGraphQLItineraryImpl
    implements LegacyGraphQLDataFetchers.LegacyGraphQLItinerary {

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

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

  @Override
  public DataFetcher duration() {
    return environment -> (long) getSource(environment).durationSeconds;
  }

  @Override
  public DataFetcher waitingTime() {
    return environment -> (long) getSource(environment).waitingTimeSeconds;
  }

  @Override
  public DataFetcher walkTime() {
    return environment -> (long) getSource(environment).nonTransitTimeSeconds;
  }

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

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

  @Override
  public DataFetcher>> fares() {
    return environment -> {
      Fare fare = getSource(environment).fare;
      if (fare == null) {
        return null;
      }
      List> results = fare.fare.keySet().stream().map(fareKey -> {
        Map result = new HashMap<>();
        result.put("name", fareKey.name());
        result.put("fare", fare.getFare(fareKey));
        result.put("details", fare.getDetails(fareKey));
        return result;
      }).collect(Collectors.toList());
      return results;
    };
  }

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

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy