Skip to content

Commit c073b1e

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 b104014 commit c073b1e

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
@@ -207,12 +207,19 @@ public void clearBayWeapons() {
207207
}
208208

209209
/**
210-
* @return All the weapon mounts in the bay.
210+
* @return A stream containing the weapon mounts in the bay.
211211
*/
212-
public List<WeaponMounted> getBayWeapons() {
212+
public Stream<WeaponMounted> streamBayWeapons() {
213213
return bayWeapons.stream()
214-
.map(i -> getEntity().getWeapon(i))
214+
.map(getEntity().getWeapon)
215215
.filter(Objects::nonNull)
216+
}
217+
218+
/**
219+
* @return All the weapon mounts in the bay.
220+
*/
221+
public List<WeaponMounted> getBayWeapons() {
222+
return streamBayWeapons()
216223
.collect(Collectors.toList());
217224
}
218225

0 commit comments

Comments
 (0)