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

org.opentripplanner.api.mapping.TripPlanMapper Maven / Gradle / Ivy

package org.opentripplanner.api.mapping;

import org.opentripplanner.api.model.ApiTripPlan;
import org.opentripplanner.model.plan.TripPlan;

import java.util.Locale;

public class TripPlanMapper {
    private final ItineraryMapper itineraryMapper;
    private final PlaceMapper placeMapper;

    public TripPlanMapper(Locale locale, boolean addIntermediateStops) {
        this.itineraryMapper = new ItineraryMapper(locale, addIntermediateStops);
        this.placeMapper = new PlaceMapper(locale);
    }

    public ApiTripPlan mapTripPlan(TripPlan domain) {
        if(domain == null) { return null; }
        ApiTripPlan api = new ApiTripPlan();
        api.date = domain.date;
        // The origin/destination do not have arrival/depature times; Hence {@code null} is used.
        api.from = placeMapper.mapPlace(domain.from, null, null, null, null);
        api.to = placeMapper.mapPlace(domain.to, null, null, null, null);
        api.itineraries = itineraryMapper.mapItineraries(domain.itineraries);
        return api;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy