From 5650311c8e0ab7b837fa97ea74de660ac13b6a77 Mon Sep 17 00:00:00 2001 From: Jonathan Lovelace Date: Thu, 11 Apr 2024 21:29:53 -0400 Subject: [PATCH] Invert semantics of boolean variables that were only tested in inverted form. --- .../operations/entity/ReplaceEntityChangeset.java | 7 +++---- .../operations/player/ReplacePlayerChangeset.java | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/model/src/main/java/changesets/operations/entity/ReplaceEntityChangeset.java b/model/src/main/java/changesets/operations/entity/ReplaceEntityChangeset.java index c2001a555..fbe2f6f1f 100644 --- a/model/src/main/java/changesets/operations/entity/ReplaceEntityChangeset.java +++ b/model/src/main/java/changesets/operations/entity/ReplaceEntityChangeset.java @@ -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; @@ -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"); } } diff --git a/model/src/main/java/changesets/operations/player/ReplacePlayerChangeset.java b/model/src/main/java/changesets/operations/player/ReplacePlayerChangeset.java index 14bc117e2..f7764b78c 100644 --- a/model/src/main/java/changesets/operations/player/ReplacePlayerChangeset.java +++ b/model/src/main/java/changesets/operations/player/ReplacePlayerChangeset.java @@ -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; @@ -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"); } }