Skip to content

Commit

Permalink
Fix a cause of Duplicate key error from MustFightBattle. (#12571)
Browse files Browse the repository at this point in the history
* Fix a cause of Duplicate key error from MustFightBattle.

* Use a LinkedHashSet to preserve order, in case something depends on it.
  • Loading branch information
asvitkine authored May 8, 2024
1 parent ac2b794 commit 1e4f58a
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -571,8 +572,11 @@ public void removeUnits(
if (killedUnits.isEmpty()) {
return;
}
// Note: Ideally we wouldn't have duplicates already, but this should fix the error for now.
// See: https://github.com/triplea-game/triplea/issues/11597
final var uniqueKilledUnits = new LinkedHashSet<>(killedUnits);
final RemoveUnitsHistoryChange removeUnitsHistoryChange =
HistoryChangeFactory.removeUnitsFromTerritory(battleSite, killedUnits);
HistoryChangeFactory.removeUnitsFromTerritory(battleSite, uniqueKilledUnits);

final Collection<Unit> killedUnitsIncludingDependents = removeUnitsHistoryChange.getOldUnits();
final Collection<Unit> transformedUnits = removeUnitsHistoryChange.getNewUnits();
Expand Down

0 comments on commit 1e4f58a

Please sign in to comment.