*/
package org.mxchange.jcore.contact;
+import java.text.MessageFormat;
import org.mxchange.jcore.BaseFrameworkSystem;
/**
/**
* Getter for Gender enum from given character
*
- * @param gender Gender character
+ * @param c Gender character
* @return Gender enum
*/
- public static Gender fromChar (final char gender) {
+ public static Gender fromChar (final char c) {
+ // Init variable
Gender g = null;
- switch (gender) {
- case 'U': // Unknown
- g = UNKNOWN;
- break;
-
- case 'M': // Male
- g = MALE;
- break;
-
- case 'F': // Female
- g = FEMALE;
- break;
- case 'C': // Company
- g = COMPANY;
+ // Loop through all
+ for (final Gender gender : Gender.values()) {
+ // Does the char match?
+ if (c == gender.getAccessChar()) {
+ // Found it
+ g = gender;
break;
+ }
+ }
- default: // Unsupported
- throw new IllegalArgumentException("gender " + gender + " is invalid.");
+ // Still null?
+ if (g == null) {
+ // Didn't found a valid one
+ throw new IllegalArgumentException(MessageFormat.format("Gender {0} is invalid.", c));
}
// Return it
// Get values
int i = 0;
- for (Object value : values()) {
- // First cast
- Gender gender = (Gender) value;
-
+ for (Gender gender : values()) {
// Debug message
//* NOISY-DEBUG: */ System.out.println("gender=" + gender);
+
// Is it UNKNOWN?
if (gender.equals(Gender.UNKNOWN)) {
// Skip this
// Debug message
//* NOISY-DEBUG: */ System.out.println(MessageFormat.format("gender={0} - adding at pos {1} ...", gender, i));
- // Get database value as this is also the access
+
+ // Get access key as this is also the access
valid[i] = gender.getAccessChar();
// Increment index