Skip to content

Commit e3ead6d

Browse files
committed
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.
1 parent 4858c16 commit e3ead6d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

megamek/src/megamek/common/equipment/WeaponMounted.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,20 @@ public void clearBayWeapons() {
206206
bayWeapons.clear();
207207
}
208208

209+
/**
210+
* @return A stream containing the weapon mounts in the bay.
211+
*/
212+
public Stream<WeaponMounted> streamBayWeapons() {
213+
return bayWeapons.stream()
214+
.map(getEntity().getWeapon)
215+
.filter(Objects::nonNull);
216+
}
217+
209218
/**
210219
* @return All the weapon mounts in the bay.
211220
*/
212221
public List<WeaponMounted> getBayWeapons() {
213-
return bayWeapons.stream()
214-
.map(i -> getEntity().getWeapon(i))
215-
.filter(Objects::nonNull)
222+
return streamBayWeapons()
216223
.collect(Collectors.toList());
217224
}
218225

0 commit comments

Comments
 (0)