
org.opentripplanner.ext.restapi.mapping.ItineraryMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of otp Show documentation
Show all versions of otp Show documentation
The OpenTripPlanner multimodal journey planning system
The newest version!
package org.opentripplanner.ext.restapi.mapping;
import java.util.Collection;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import org.opentripplanner.ext.restapi.model.ApiItinerary;
import org.opentripplanner.model.plan.Itinerary;
public class ItineraryMapper {
private final LegMapper legMapper;
private final FareMapper fareMapper;
public ItineraryMapper(Locale locale, boolean addIntermediateStops) {
this.legMapper = new LegMapper(locale, addIntermediateStops);
this.fareMapper = new FareMapper(locale);
}
public List mapItineraries(Collection domain) {
if (domain == null) {
return null;
}
return domain.stream().map(this::mapItinerary).collect(Collectors.toList());
}
public ApiItinerary mapItinerary(Itinerary domain) {
if (domain == null) {
return null;
}
ApiItinerary api = new ApiItinerary();
api.duration = domain.getDuration().toSeconds();
api.startTime = GregorianCalendar.from(domain.startTime());
api.endTime = GregorianCalendar.from(domain.endTime());
api.walkTime = domain.getNonTransitDuration().toSeconds();
api.transitTime = domain.getTransitDuration().toSeconds();
api.waitingTime = domain.getWaitingDuration().toSeconds();
api.walkDistance = domain.getNonTransitDistanceMeters();
// We list only the generalizedCostIncludingPenalty, this is the least confusing. We intend to
// delete this endpoint soon, so we will not make the proper change and add the
// generalizedCostIncludingPenalty to the response and update the debug client to show it.
api.generalizedCost = domain.getGeneralizedCostIncludingPenalty();
api.elevationLost = domain.getElevationLost();
api.elevationGained = domain.getElevationGained();
api.transfers = domain.getNumberOfTransfers();
api.tooSloped = domain.isTooSloped();
api.arrivedAtDestinationWithRentedBicycle = domain.isArrivedAtDestinationWithRentedVehicle();
api.fare = fareMapper.mapFare(domain);
api.legs = legMapper.mapLegs(domain.getLegs());
api.systemNotices = SystemNoticeMapper.mapSystemNotices(domain.getSystemNotices());
api.accessibilityScore = domain.getAccessibilityScore();
return api;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy