Skip to content

Commit

Permalink
Fix a bug where I return instead of continue after having converted a…
Browse files Browse the repository at this point in the history
… forEach() call to a regular for-each loop. Also minor fluff and cleanup.
  • Loading branch information
ra4king committed Aug 30, 2022
1 parent b4124dd commit 66a1844
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main/java/com/ra4king/circuitsim/simulator/Simulator.java
Expand Up @@ -17,7 +17,7 @@
*/
public class Simulator {
private final Set<Circuit> circuits;
private Collection<Pair<CircuitState, Link>> linksToUpdate, temp;
private Set<Pair<CircuitState, Link>> linksToUpdate, temp;
private final Set<Collection<Pair<CircuitState, Link>>> history;

// Create a Lock with a fair policy
Expand Down Expand Up @@ -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;
Expand All @@ -150,11 +152,11 @@ public void step() {
try {
stepping = true;

Collection<Pair<CircuitState, Link>> tmp = linksToUpdate;
Set<Pair<CircuitState, Link>> tmp = linksToUpdate;
linksToUpdate = temp;
linksToUpdate.clear();
temp = tmp;

linksToUpdate.clear();
RuntimeException lastException = null;
ShortCircuitException lastShortCircuit = null;

Expand All @@ -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 {
Expand Down

0 comments on commit 66a1844

Please sign in to comment.