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

org.opentripplanner.apis.gtfs.mapping.routerequest.ArgumentUtils Maven / Gradle / Ivy

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

import graphql.schema.DataFetchingEnvironment;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes;

public class ArgumentUtils {

  /**
   * This methods returns list of modes and their costs from the argument structure:
   * modes.transit.transit. This methods circumvents a bug in graphql-codegen as getting a list of
   * input objects is not possible through using the generated types in {@link GraphQLTypes}.
   * 

* TODO this ugliness can be removed when the bug gets fixed */ @Nullable static List> getTransitModes(DataFetchingEnvironment environment) { if (environment.containsArgument("modes")) { Map modesArgs = environment.getArgument("modes"); if (modesArgs.containsKey("transit")) { Map transitArgs = (Map) modesArgs.get("transit"); if (transitArgs.containsKey("transit")) { return (List>) transitArgs.get("transit"); } } } return null; } /** * This methods returns parking preferences of the given type from argument structure: * preferences.street.type.parking. This methods circumvents a bug in graphql-codegen as getting a * list of input objects is not possible through using the generated types in * {@link GraphQLTypes}. *

* TODO this ugliness can be removed when the bug gets fixed */ @Nullable static Map getParking(DataFetchingEnvironment environment, String type) { return ( (Map) ( (Map) ( (Map) ((Map) environment.getArgument("preferences")).get( "street" ) ).get(type) ).get("parking") ); } /** * This methods returns required/banned parking tags of the given type from argument structure: * preferences.street.type.parking.filters. This methods circumvents a bug in graphql-codegen as * getting a list of input objects is not possible through using the generated types in * {@link GraphQLTypes}. *

* TODO this ugliness can be removed when the bug gets fixed */ @Nonnull static Collection> getParkingFilters( DataFetchingEnvironment environment, String type ) { var parking = getParking(environment, type); var filters = parking != null && parking.containsKey("filters") ? getParking(environment, type).get("filters") : null; return filters != null ? (Collection>) filters : List.of(); } /** * This methods returns preferred/unpreferred parking tags of the given type from argument * structure: preferences.street.type.parking.preferred. This methods circumvents a bug in * graphql-codegen as getting a list of input objects is not possible through using the generated * types in {@link GraphQLTypes}. *

* TODO this ugliness can be removed when the bug gets fixed */ @Nonnull static Collection> getParkingPreferred( DataFetchingEnvironment environment, String type ) { var parking = getParking(environment, type); var preferred = parking != null && parking.containsKey("preferred") ? getParking(environment, type).get("preferred") : null; return preferred != null ? (Collection>) preferred : List.of(); } static Set parseNotFilters(Collection> filters) { return parseFilters(filters, "not"); } static Set parseSelectFilters(Collection> filters) { return parseFilters(filters, "select"); } @Nonnull private static Set parseFilters(Collection> filters, String key) { return filters .stream() .flatMap(f -> parseOperation((Collection>>) f.getOrDefault(key, List.of())) ) .collect(Collectors.toSet()); } private static Stream parseOperation(Collection>> map) { return map .stream() .flatMap(f -> { var tags = f.getOrDefault("tags", List.of()); return tags.stream(); }); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy