class PortableRoutingPlanFactory {

    static PortableRoutingPlan fromRoutingPlan(RoutingPlan routingPlan) {
        PortableDistance distance = PortableDistance.fromDistance(routingPlan.distance());
        List<PortableVehicle> vehicles = portableVehicles(routingPlan.vehicles());
        PortableLocation depot = routingPlan.depot().map(PortableLocation::fromLocation).orElse(null);
        List<PortableLocation> visits = portableVisits(routingPlan.visits());
        List<PortableRoute> routes = routingPlan.routes().stream()
                .map(routeWithTrack -> new PortableRoute(
                        PortableVehicle.fromVehicle(routeWithTrack.vehicle()),
                        depot,
                        portableVisits(routeWithTrack.visits()),
                        portableTrack(routeWithTrack.track())))
                .collect(toList());
        return new PortableRoutingPlan(distance, vehicles, depot, visits, routes);
    }

    private  PortableRoutingPlanFactory();

}