Solvers { static GlobalStateObject convert( PDPRoadModel rm, PDPModel pm, Collection<Vehicle> vehicles, Set<Parcel> availableParcels, Measure<Long, Duration> time, Optional<ImmutableList<ImmutableList<Parcel>>> currentRoutes, boolean fixRoutes) { final ImmutableMap.Builder<VehicleStateObject, Vehicle> vbuilder = ImmutableMap.builder(); @Nullable Iterator<ImmutableList<Parcel>> routeIterator = null; if (currentRoutes.isPresent()) { checkArgument(currentRoutes.get().size() == vehicles.size(), "The number of routes (%s) must equal the number of vehicles (%s).", currentRoutes.get().size(), vehicles.size()); routeIterator = currentRoutes.get().iterator(); } final ImmutableSet.Builder<Parcel> availableDestParcels = ImmutableSet.builder(); final RoadModelSnapshot snapshot = rm.getSnapshot(); for (final Vehicle v : vehicles) { final ImmutableSet<Parcel> contentsMap = ImmutableSet.copyOf(pm.getContents(v)); @Nullable ImmutableList<Parcel> route = null; if (routeIterator != null) { route = routeIterator.next(); } final VehicleStateObject vehicleState = convertToVehicleState(rm, pm, v, contentsMap, route, availableDestParcels); vbuilder.put(vehicleState, v); } final ImmutableSet<Parcel> availableDestMap = availableDestParcels.build(); final Set<Parcel> toAdd = Sets.difference(availableParcels, availableDestMap); final ImmutableSet<Parcel> availableParcelsKeys = ImmutableSet.<Parcel>builder() .addAll(availableParcels) .addAll(toAdd) .build(); final ImmutableMap<VehicleStateObject, Vehicle> vehicleMap = vbuilder.build(); GlobalStateObject gso = GlobalStateObject.create(availableParcelsKeys, vehicleMap.keySet().asList(), time.getValue().longValue(), time.getUnit(), rm.getSpeedUnit(), rm.getDistanceUnit(), snapshot); if (fixRoutes) { gso = fixRoutes(gso); } return gso; } private  Solvers(); static AdapterBuilder<SimSolver> solverBuilder(Solver sol); static AdapterBuilder<SimulationConverter> converterBuilder(); static ExtendedStats computeStats(GlobalStateObject state,
      @Nullable ImmutableList<ImmutableList<Parcel>> routes); static ExtendedStats computeStats(GlobalStateObject state,
      @Nullable ImmutableList<ImmutableList<Parcel>> routes,
      GeomHeuristic heuristic); static Callable<ImmutableList<ImmutableList<Parcel>>> createSolverCallable(
      Solver solver, GlobalStateObject state); static MeasureableSolver timeMeasurementDecorator(Solver s);  }
@Test public void convertTest() { PDPTWTestUtil.register(rm, pm, v1, p1); final Clock clock = mock(Clock.class); when(clock.getCurrentTime()).thenReturn(0L); when(clock.getTickLength()).thenReturn(1L); when(clock.getTimeUnit()).thenReturn(NonSI.MINUTE); final SimulationConverter handle = Solvers.converterBuilder() .with(mp) .with(clock) .build(); final GlobalStateObject state = handle.convert(SolveArgs.create() .useAllParcels() .noCurrentRoutes()); assertEquals(ImmutableSet.of(p1), state.getAvailableParcels()); checkVehicles(asList(v1), state.getVehicles()); rm.moveTo(v1, p1, create(NonSI.HOUR, 0L, 1L)); checkVehicles( asList(v1), handle.convert(SolveArgs.create().useAllParcels().noCurrentRoutes()) .getVehicles()); rm.moveTo(v1, p1, create(NonSI.HOUR, 0, 40)); assertTrue(rm.equalPosition(v1, p1)); pm.service(v1, p1, create(NonSI.HOUR, 0, 1)); assertEquals(VehicleState.PICKING_UP, pm.getVehicleState(v1)); final GlobalStateObject state2 = handle.convert(SolveArgs.create().useAllParcels() .noCurrentRoutes()); assertTrue(state2.getAvailableParcels().contains(p1)); assertFalse(state2.getVehicles().get(0).getContents().contains(p1)); assertSame(p1, state2.getVehicles().get(0).getDestination().get()); assertEquals(29, state2.getVehicles().get(0).getRemainingServiceTime()); assertFalse(state2.getVehicles().get(0).getRoute().isPresent()); }