diff --git a/src/main/java/com/ra4king/circuitsim/simulator/Simulator.java b/src/main/java/com/ra4king/circuitsim/simulator/Simulator.java index dba71b35..1a5b0d08 100644 --- a/src/main/java/com/ra4king/circuitsim/simulator/Simulator.java +++ b/src/main/java/com/ra4king/circuitsim/simulator/Simulator.java @@ -17,7 +17,7 @@ */ public class Simulator { private final Set circuits; - private Collection> linksToUpdate, temp; + private Set> linksToUpdate, temp; private final Set>> history; // Create a Lock with a fair policy @@ -132,8 +132,10 @@ public void valueChanged(CircuitState state, Link link) { * Removes the Link from the processing queue. */ void linkRemoved(Link link) { - runSync(() -> linksToUpdate.removeAll( - linksToUpdate.stream().filter(pair -> pair.getValue() == link).collect(Collectors.toList()))); + runSync(() -> linksToUpdate.stream() + .filter(pair -> pair.getValue() == link) + .collect(Collectors.toList()) + .forEach(linksToUpdate::remove)); } private boolean stepping = false; @@ -150,11 +152,11 @@ public void step() { try { stepping = true; - Collection> tmp = linksToUpdate; + Set> tmp = linksToUpdate; linksToUpdate = temp; + linksToUpdate.clear(); temp = tmp; - linksToUpdate.clear(); RuntimeException lastException = null; ShortCircuitException lastShortCircuit = null; @@ -164,7 +166,7 @@ public void step() { // The Link or CircuitState may have been removed if (link.getCircuit() == null || !state.getCircuit().containsState(state)) { - return; + continue; } try {