Skip to content

Commit

Permalink
refactor: Add function for streaming bay weapons
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Saklad5 committed Aug 18, 2024
1 parent 364759a commit a3bbba8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions megamek/src/megamek/common/equipment/WeaponMounted.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<WeaponMounted> getBayWeapons() {
public Stream<WeaponMounted> 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<WeaponMounted> getBayWeapons() {
return streamBayWeapons()
.collect(Collectors.toList());
}

Expand Down

0 comments on commit a3bbba8

Please sign in to comment.