Skip to content

Commit

Permalink
Refactored Gender Enum to Include 'Other' Genders
Browse files Browse the repository at this point in the history
Cleaned up the class and added handlers for personnel with one of two 'Other' genders
  • Loading branch information
IllianiCBT committed Aug 5, 2024
1 parent 0be9ce5 commit 15334e6
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions megamek/src/megamek/common/enums/Gender.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@
import java.util.List;

/**
* Author's Note: This is for Biological Gender (strictly speaking, the term is Sex) only,
* with the two OTHER-? flags being implemented here for MekHQ usage.
* In this context, sex relates to the character's capacity to incubate offspring.
* While this is a very limited view of the broad spectrum of human genders,
* the needs of programming dictate that we need to take a more binary view of things.
* To this end, males can't birth children, females can.
* 'Other' genders are used for characters that fall outside the gender binary,
* with the sex following 'other' determining their capacity to birth children.
*/
public enum Gender {
//region Enum Declarations
MALE(false, "Male"),
FEMALE(false, "Female"),
OTHER_MALE(true, "Male"),
OTHER_FEMALE(true, "Female"),
OTHER_MALE(true, "Other (M)"),
OTHER_FEMALE(true, "Other (F)"),
RANDOMIZE(true);
//endregion Enum Declarations

Expand All @@ -53,14 +57,14 @@ public enum Gender {

//region Boolean Checks
/**
* @return true is the person's biological gender is male, otherwise false
* @return true if the person's biological gender is male, otherwise false
*/
public boolean isMale() {
return (this == MALE) || (this == OTHER_MALE);
}

/**
* @return true is the person's biological gender is female, otherwise false
* @return true if the person's biological gender is female, otherwise false
*/
public boolean isFemale() {
return (this == FEMALE) || (this == OTHER_FEMALE);
Expand Down Expand Up @@ -123,21 +127,19 @@ public static Gender parseFromString(String input) {
}

try {
switch (Integer.parseInt(input)) {
case 0:
return MALE;
case 1:
return FEMALE;
case -1:
default:
return RandomGenderGenerator.generate();
}
return switch (Integer.parseInt(input)) {
case 0 -> MALE;
case 1 -> FEMALE;
case 2 -> OTHER_MALE;
case 3 -> OTHER_FEMALE;
default -> RandomGenderGenerator.generate();
};
} catch (Exception ignored) {

}

LogManager.getLogger().error("Failed to parse the gender value from input String " + input
+ ". Returning a newly generated gender.");
LogManager.getLogger().error("Failed to parse the gender value from input String {}. Returning a newly generated gender.",
input);
return RandomGenderGenerator.generate();
}

Expand Down

0 comments on commit 15334e6

Please sign in to comment.