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
66 public static Gender fromChar (final char c) {
71 for (final Gender gender : GenderUtils.selectableGenders()) {
72 // Does the char match?
73 if (c == gender.getAccessChar()) {
82 // Didn't found a valid one
83 throw new IllegalArgumentException(MessageFormat.format("Gender {0} is invalid.", c)); //NOI18N
87 //* NOISY-DEBUG: */ System.out.println("gender=" + g.getClass().getName());
92 * Valid chars (mostly for console client)
96 public static char[] validChars () {
98 if (validChars != null) {
103 // Init array, only 3 are valid as 'U' is UNKNOWN and is not valid.
104 char[] valid = new char[3];
108 for (final Gender gender : GenderUtils.selectableGenders()) {
110 //* NOISY-DEBUG: */ System.out.println("gender=" + gender);
113 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("gender={0} - adding at pos {1} ...", gender, i));
114 // Get access key as this is also the access
115 valid[i] = gender.getAccessChar();
124 // Return finialized array
131 * @param accessChar Value being entered by ConsoleClient
132 * @param messageKey Message key for resource file
134 private Gender (final char accessChar, final String messageKey) {
136 this.accessChar = accessChar;
137 this.messageKey = messageKey;
141 * Acces key (console client mostly)
143 * @return the accessChar
145 public char getAccessChar () {
146 return this.accessChar;
150 * Output value (for messages)
152 * @return the messageKey
154 public String getMessageKey () {
155 return this.messageKey;