From 2db87957d8e0150882026c42d7b6a04389765a2e Mon Sep 17 00:00:00 2001 From: Jeremy Saklad Date: Sun, 18 Aug 2024 13:39:05 -0500 Subject: [PATCH] refactor: Use stream composition for finding TAG spotters --- .../megamek/common/actions/WeaponAttackAction.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/megamek/src/megamek/common/actions/WeaponAttackAction.java b/megamek/src/megamek/common/actions/WeaponAttackAction.java index 19a137259b1..1414fc441e0 100644 --- a/megamek/src/megamek/common/actions/WeaponAttackAction.java +++ b/megamek/src/megamek/common/actions/WeaponAttackAction.java @@ -555,11 +555,12 @@ private static ToHitData toHitCalc(Game game, int attackerId, Targetable target, || (atype.getAmmoType() == AmmoType.T_NLRM) || (atype.getAmmoType() == AmmoType.T_MEK_MORTAR)) && (munition.contains(AmmoType.Munitions.M_SEMIGUIDED))) { - for (TagInfo ti : game.getTagInfo()) { - if (target.getId() == ti.target.getId()) { - spotter = game.getEntity(ti.attackerId); - } - } + final Targetable currentTarget = target; // Required for concurrency reasons + spotter = game.getTagInfo().stream() + .filter(ti -> currentTarget.getId() == ti.target.getId()) + .findAny() + .map(ti -> game.getEntity(ti.attackerId)) + .orElse(null); } }