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 4858c16 commit e3ead6d
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 @@ -206,13 +206,20 @@ public void clearBayWeapons() {
bayWeapons.clear();
}

/**
* @return A stream containing the weapon mounts in the bay.
*/
public Stream<WeaponMounted> streamBayWeapons() {
return bayWeapons.stream()
.map(getEntity().getWeapon)
.filter(Objects::nonNull);
}

/**
* @return All the weapon mounts in the bay.
*/
public List<WeaponMounted> getBayWeapons() {
return bayWeapons.stream()
.map(i -> getEntity().getWeapon(i))
.filter(Objects::nonNull)
return streamBayWeapons()
.collect(Collectors.toList());
}

Expand Down

0 comments on commit e3ead6d

Please sign in to comment.