Skip to content

Commit 175a3f1

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 175a3f1

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Objects;
3131
import java.util.Vector;
3232
import java.util.stream.Collectors;
33+
import java.util.stream.Stream;
3334

3435
public class WeaponMounted extends Mounted<WeaponType> {
3536

@@ -207,12 +208,19 @@ public void clearBayWeapons() {
207208
}
208209

209210
/**
210-
* @return All the weapon mounts in the bay.
211+
* @return A stream containing the weapon mounts in the bay.
211212
*/
212-
public List<WeaponMounted> getBayWeapons() {
213+
public Stream<WeaponMounted> streamBayWeapons() {
213214
return bayWeapons.stream()
214215
.map(i -> getEntity().getWeapon(i))
215-
.filter(Objects::nonNull)
216+
.filter(Objects::nonNull);
217+
}
218+
219+
/**
220+
* @return All the weapon mounts in the bay.
221+
*/
222+
public List<WeaponMounted> getBayWeapons() {
223+
return streamBayWeapons()
216224
.collect(Collectors.toList());
217225
}
218226

0 commit comments

Comments
 (0)