From a3bbba8e9cfd03fc34a5c1bd21a48b5878ce68cd Mon Sep 17 00:00:00 2001 From: Jeremy Saklad Date: Sun, 18 Aug 2024 11:33:52 -0500 Subject: [PATCH] refactor: Add function for streaming bay weapons WeaponMounted.getBayWeapons() iterates through the entire bay before returning, which isn't always necessary. It has been refactored to allow for the stream to be used directly. --- .../src/megamek/common/equipment/WeaponMounted.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/megamek/src/megamek/common/equipment/WeaponMounted.java b/megamek/src/megamek/common/equipment/WeaponMounted.java index 48b39f59bd1..7e931a3d7b4 100644 --- a/megamek/src/megamek/common/equipment/WeaponMounted.java +++ b/megamek/src/megamek/common/equipment/WeaponMounted.java @@ -207,12 +207,19 @@ public void clearBayWeapons() { } /** - * @return All the weapon mounts in the bay. + * @return A stream containing the weapon mounts in the bay. */ - public List getBayWeapons() { + public Stream streamBayWeapons() { return bayWeapons.stream() - .map(i -> getEntity().getWeapon(i)) + .map(getEntity().getWeapon) .filter(Objects::nonNull) + } + + /** + * @return All the weapon mounts in the bay. + */ + public List getBayWeapons() { + return streamBayWeapons() .collect(Collectors.toList()); }