org.opentripplanner.ext.legacygraphqlapi.datafetchers.LegacyGraphQLItineraryImpl Maven / Gradle / Ivy
package org.opentripplanner.ext.legacygraphqlapi.datafetchers;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLDataFetchers;
import org.opentripplanner.model.SystemNotice;
import org.opentripplanner.model.plan.Itinerary;
import org.opentripplanner.model.plan.Leg;
import org.opentripplanner.routing.core.ItineraryFares;
public class LegacyGraphQLItineraryImpl
implements LegacyGraphQLDataFetchers.LegacyGraphQLItinerary {
@Override
public DataFetcher arrivedAtDestinationWithRentedBicycle() {
return environment -> getSource(environment).isArrivedAtDestinationWithRentedVehicle();
}
@Override
public DataFetcher duration() {
return environment -> (long) getSource(environment).getDuration().toSeconds();
}
@Override
public DataFetcher elevationGained() {
return environment -> getSource(environment).getElevationGained();
}
@Override
public DataFetcher elevationLost() {
return environment -> getSource(environment).getElevationLost();
}
@Override
public DataFetcher endTime() {
return environment -> getSource(environment).endTime().toInstant().toEpochMilli();
}
@Override
public DataFetcher>> fares() {
return environment -> {
ItineraryFares fare = getSource(environment).getFares();
if (fare == null) {
return null;
}
return fare
.getTypes()
.stream()
.map(fareKey -> {
Map result = new HashMap<>();
result.put("name", fareKey);
result.put("fare", fare.getFare(fareKey));
result.put("details", fare.getDetails(fareKey));
return result;
})
.collect(Collectors.toList());
};
}
@Override
public DataFetcher generalizedCost() {
return environment -> getSource(environment).getGeneralizedCost();
}
@Override
public DataFetcher> legs() {
return environment -> getSource(environment).getLegs();
}
@Override
public DataFetcher startTime() {
return environment -> getSource(environment).startTime().toInstant().toEpochMilli();
}
@Override
public DataFetcher> systemNotices() {
return environment -> getSource(environment).getSystemNotices();
}
@Override
public DataFetcher waitingTime() {
return environment -> (long) getSource(environment).getWaitingDuration().toSeconds();
}
@Override
public DataFetcher walkDistance() {
return environment -> getSource(environment).getNonTransitDistanceMeters();
}
@Override
public DataFetcher walkTime() {
return environment -> (long) getSource(environment).getNonTransitDuration().toSeconds();
}
private Itinerary getSource(DataFetchingEnvironment environment) {
return environment.getSource();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy