Skip to content

Commit

Permalink
fix(ev): unqueuing a vehicle
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhoerl committed Dec 7, 2024
1 parent bee9a70 commit 4c02429
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,19 @@ public void removeVehicle(ElectricVehicle ev, double now) {
}
}
} else {
// make sure ev was in the queue
Preconditions.checkState(queuedVehicles.remove(ev), "Vehicle (%s) is neither queued nor plugged at charger (%s)", ev.getId(),
charger.getId());
eventsManager.processEvent(new QuitQueueAtChargerEvent(now, charger.getId(), ev.getId()));
var queuedVehiclesIter = queuedVehicles.iterator();
while (queuedVehiclesIter.hasNext()) {
var queuedVehicle = queuedVehiclesIter.next();

if (queuedVehicle.ev() == ev) {
queuedVehiclesIter.remove();
eventsManager.processEvent(new QuitQueueAtChargerEvent(now, charger.getId(), ev.getId()));
return; // found the vehicle
}
}

throw new IllegalStateException(String.format("Vehicle (%s) is neither queued nor plugged at charger (%s)", ev.getId(),
charger.getId()));
}
}

Expand Down

0 comments on commit 4c02429

Please sign in to comment.