Skip to content

Commit

Permalink
Invert semantics of boolean variables that were only tested in invert…
Browse files Browse the repository at this point in the history
…ed form.
  • Loading branch information
kingjon3377 committed Apr 12, 2024
1 parent 8d43f24 commit 5650311
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package changesets.operations.entity;

import changesets.Changeset;
import changesets.ChangesetFailureException;
import changesets.PreconditionFailureException;
import common.entity.IEntity;
import common.map.IMap;
Expand All @@ -28,15 +27,15 @@ public ReplaceEntityChangeset(final @NotNull IEntity toRemove, final @NotNull IE
}

private void checkPrecondition(final @NotNull IMap map) throws PreconditionFailureException {
boolean met = false;
boolean neverMet = true;
for (final IEntity item : map.getAllEntities()) {
if (item.equals(toRemove)) {
met = true;
neverMet = false;
} else if (Objects.equals(item.getId(), toAdd.getId())) {
throw new PreconditionFailureException("Cannot add entity with non-unique ID");
}
}
if (!met) {
if (neverMet) {
throw new PreconditionFailureException("Cannot remove entity if not present in the map");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package changesets.operations.player;

import changesets.Changeset;
import changesets.ChangesetFailureException;
import changesets.PreconditionFailureException;
import common.map.IMap;
import common.map.IMutableMap;
Expand All @@ -28,15 +27,15 @@ public ReplacePlayerChangeset(final @NotNull Player toRemove, final @NotNull Pla

private void checkPrecondition(final @NotNull IMap map) throws PreconditionFailureException {
final IPlayerCollection players = map.getPlayers();
boolean met = false;
boolean neverMet = true;
for (final Player item : players) {
if (item.equals(toRemove)) {
met = true;
neverMet = false;
} else if (item.playerId() == toAdd.playerId()) {
throw new PreconditionFailureException("Cannot add player with non-unique ID");
}
}
if (!met) {
if (neverMet) {
throw new PreconditionFailureException("Cannot remove player if not present in the map");
}
}
Expand Down

0 comments on commit 5650311

Please sign in to comment.