class RerouteUtil {

  public List<Step> getFutureSteps(Vehicle vehicle) {
    TCSObjectReference<TransportOrder> orderRef = vehicle.getTransportOrder();
    if (orderRef == null) {
      LOG.debug("Vehicle {} isn't processing any order. Can't determine future steps.",
                vehicle.getName());
      return new ArrayList<>();
    }

    TransportOrder order = transportOrderService.fetchObject(TransportOrder.class, orderRef);
    VehicleController controller = vehicleControllerPool.getVehicleController(vehicle.getName());

    // Get the steps for the drive order the vehicle is currently processing
    // The transport order's drive orders and their routes can't be null at this point
    List<Step> currentSteps = order.getCurrentDriveOrder().getRoute().getSteps();

    // If movement commands have been sent to the comm adapter, trim the current steps by these.
    // Movement commands may have not been sent to the comm adapter yet, i.e. if needed resources
    // are already allocated by another vehicle.
    if (!controller.getCommandsSent().isEmpty()) {
      List<MovementCommand> commandsSent = new ArrayList<>(controller.getCommandsSent());
      MovementCommand lastCommandSent = commandsSent.get(commandsSent.size() - 1);

      // Trim the current steps / Get the steps that haven't been sent to the comm adapter yet
      currentSteps = currentSteps.subList(
          currentSteps.indexOf(lastCommandSent.getStep()) + 1, currentSteps.size());
    }

    List<Step> futureSteps = new ArrayList<>();
    futureSteps.addAll(currentSteps);

    // Add the steps from all future drive orders
    order.getFutureDriveOrders().stream()
        .map(driveOrder -> driveOrder.getRoute())
        .map(route -> route.getSteps())
        .forEach(steps -> futureSteps.addAll(steps));

    return futureSteps;
  }

  @Inject public  RerouteUtil(Router router,
                     VehicleControllerPool vehicleControllerPool,
                     InternalTransportOrderService transportOrderService,
                     DefaultDispatcherConfiguration configuration);

}