2 * Copyright (C) 2015 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jcontacts.contact.gender;
19 import java.io.Serializable;
20 import java.text.MessageFormat;
25 * @author Roland Haeder<roland@mxchange.org>
27 public enum Gender implements Serializable {
32 UNKNOWN('U', "GENDER_UNKNOWN"), //NOI18N
37 MALE('M', "GENDER_MALE"), //NOI18N
42 FEMALE('F', "GENDER_FEMALE"); //NOI18N
45 * Cache for valid chars
47 private static char[] validChars;
50 * Access key being entered by ConsoleClient
52 private final char accessChar;
55 * Output value (for messages)
57 private final String messageKey;
60 * Getter for Gender enum from given character
62 * @param c Gender character
65 public static Gender fromChar (final char c) {
70 for (final Gender gender : GenderUtils.selectableGenders()) {
71 // Does the char match?
72 if (c == gender.getAccessChar()) {
81 // Didn't found a valid one
82 throw new IllegalArgumentException(MessageFormat.format("Gender {0} is invalid.", c)); //NOI18N
86 //* NOISY-DEBUG: */ System.out.println("gender=" + g.getClass().getName());
91 * Valid chars (mostly for console client)
95 public static char[] validChars () {
97 if (validChars != null) {
102 // Init array, only 3 are valid as 'U' is UNKNOWN and is not valid.
103 char[] valid = new char[3];
107 for (final Gender gender : GenderUtils.selectableGenders()) {
109 //* NOISY-DEBUG: */ System.out.println("gender=" + gender);
112 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("gender={0} - adding at pos {1} ...", gender, i));
113 // Get access key as this is also the access
114 valid[i] = gender.getAccessChar();
123 // Return finialized array
130 * @param accessChar Value being entered by ConsoleClient
131 * @param messageKey Message key for resource file
133 private Gender (final char accessChar, final String messageKey) {
135 this.accessChar = accessChar;
136 this.messageKey = messageKey;
140 * Acces key (console client mostly)
142 * @return the accessChar
144 public char getAccessChar () {
145 return this.accessChar;
149 * Output value (for messages)
151 * @return the messageKey
153 public String getMessageKey () {
154 return this.messageKey;