Skip to content

Commit

Permalink
Merge pull request #5863 from IllianiCBT/gender_other
Browse files Browse the repository at this point in the history
Refactored Gender Enum to Include 'Other' Genders
  • Loading branch information
IllianiCBT authored Aug 7, 2024
2 parents ab85ae0 + 4ef8fe7 commit 5d2f648
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions megamek/src/megamek/common/enums/Gender.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 - The MegaMek Team. All Rights Reserved
* Copyright (C) 2020-2024 - The MegaMek Team. All Rights Reserved
*
* MegaMek is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -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 5d2f648

Please sign in to comment.