Skip to content

Commit

Permalink
Swapping Personnel Role to use streams
Browse files Browse the repository at this point in the history
  • Loading branch information
Windchild292 committed May 31, 2021
1 parent c443cab commit b329457
Showing 1 changed file with 5 additions and 36 deletions.
41 changes: 5 additions & 36 deletions MekHQ/src/mekhq/campaign/personnel/enums/PersonnelRole.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import mekhq.MekHQ;

import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -311,13 +310,7 @@ public boolean isDependentOrNone() {
* @return a list of roles that can be included in the personnel market
*/
public static List<PersonnelRole> getMarketableRoles() {
final List<PersonnelRole> marketableRoles = new ArrayList<>();
for (final PersonnelRole role : values()) {
if (role.isMarketable()) {
marketableRoles.add(role);
}
}
return marketableRoles;
return Stream.of(values()).filter(PersonnelRole::isMarketable).collect(Collectors.toList());
}

/**
Expand All @@ -331,52 +324,28 @@ public static List<PersonnelRole> getPrimaryRoles() {
* @return a list of roles that are considered to be vessel (as in spacecraft) crewmembers
*/
public static List<PersonnelRole> getVesselRoles() {
final List<PersonnelRole> vesselRoles = new ArrayList<>();
for (final PersonnelRole role : values()) {
if (role.isVesselCrewmember()) {
vesselRoles.add(role);
}
}
return vesselRoles;
return Stream.of(values()).filter(PersonnelRole::isVesselCrewmember).collect(Collectors.toList());
}

/**
* @return a list of roles that are considered to be techs
*/
public static List<PersonnelRole> getTechRoles() {
final List<PersonnelRole> techRoles = new ArrayList<>();
for (final PersonnelRole role : values()) {
if (role.isTech()) {
techRoles.add(role);
}
}
return techRoles;
return Stream.of(values()).filter(PersonnelRole::isTech).collect(Collectors.toList());
}

/**
* @return a list of all roles that are considered to be administrators
*/
public static List<PersonnelRole> getAdministratorRoles() {
final List<PersonnelRole> administratorRoles = new ArrayList<>();
for (final PersonnelRole role : values()) {
if (role.isAdministrator()) {
administratorRoles.add(role);
}
}
return administratorRoles;
return Stream.of(values()).filter(PersonnelRole::isAdministrator).collect(Collectors.toList());
}

/**
* @return the number of roles that are not tagged as marketable
*/
public static int getUnmarketableCount() {
int unmarketable = 0;
for (final PersonnelRole role : values()) {
if (!role.isMarketable()) {
unmarketable++;
}
}
return unmarketable;
return Math.toIntExact(Stream.of(values()).filter(role -> !role.isMarketable()).count());
}
//endregion Static Methods

Expand Down

0 comments on commit b329457

Please sign in to comment.