private List<TripStructureUtils.Trip> getDriverTrip(
      final JointTrip toRemove, final Plan driverPlan) {
    final TripStructureUtils.Trip driverTrip =
        getTripWithLeg(driverPlan, toRemove.getDriverLegs().get(0), stagesWithJointTypes);
    assert driverTrip.getTripElements().containsAll(toRemove.getDriverLegs());

    final List<PlanElement> elements = new ArrayList<PlanElement>();
    elements.add(driverTrip.getOriginActivity());
    elements.addAll(driverTrip.getTripElements());
    elements.add(driverTrip.getDestinationActivity());
    return TripStructureUtils.getTrips(elements, stages);
  }
  private void repareDriverTrips(final JointTrip toRemove, final JointPlan plan) {
    final List<TripStructureUtils.Trip> subtrips =
        getDriverTrip(toRemove, plan.getIndividualPlan(toRemove.getDriverId()));
    final List<PlanElement> newTrip = new ArrayList<PlanElement>();
    newTrip.add(PopulationUtils.createLeg(TransportMode.car));

    // "state" variables, changed in the loop:
    // - keeps track of the passengers currently in the vehicle.
    //   Pick-up or drop-offs are created at each change
    Set<Id> currentPassengers = Collections.<Id>emptySet();
    for (TripStructureUtils.Trip subtrip : subtrips) {
      final Leg leg = getDriverLegIfItIs(subtrip);
      final Route route = leg == null ? null : leg.getRoute();

      final Set<Id> newPassengers =
          route != null
              ? new HashSet<Id>(((DriverRoute) route).getPassengersIds())
              : Collections.<Id>emptySet();
      // note that no check of the mode is done...
      if (!newPassengers.equals(currentPassengers)) {
        newTrip.add(
            PopulationUtils.createActivityFromLinkId(
                JointActingTypes.INTERACTION,
                route != null ? route.getStartLinkId() : subtrip.getOriginActivity().getLinkId()));

        // as the spatial structure of the trip is modified, it is possible
        // that some pre-existing subtours are removed. Thus, a driver that may
        // have walked to a pick up (because at the same location as its departure)
        // may then have to drive to pick up the second passenger directly if
        // the first passenger was removed. Setting all non-driver legs
        // to car ensures to have a consistent mode chain.
        // XXX It could be done in a smarter way, so that if no subtour is removed, no modification
        // is done
        // For instance, when removing an "intern" trip, first PU and last DO are
        // left untouched, and thus access and egress leg need not be touched.
        newTrip.add(leg != null ? leg : PopulationUtils.createLeg(TransportMode.car));
        currentPassengers = newPassengers;
      }
    }

    TripRouter.insertTrip(
        plan.getIndividualPlan(toRemove.getDriverId()),
        subtrips.get(0).getOriginActivity(),
        newTrip,
        subtrips.get(subtrips.size() - 1).getDestinationActivity());
  }