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
47 COMPANY('C', "GENDER_COMPANY"); //NOI18N
50 * Cache for valid chars
52 private static char[] validChars;
55 * Access key being entered by ConsoleClient
57 private final char accessChar;
60 * Output value (for messages)
62 private final String messageKey;
65 * Getter for Gender enum from given character
67 * @param c Gender character
70 public static Gender fromChar (final char c) {
75 for (final Gender gender : GenderUtils.selectableGenders()) {
76 // Does the char match?
77 if (c == gender.getAccessChar()) {
86 // Didn't found a valid one
87 throw new IllegalArgumentException(MessageFormat.format("Gender {0} is invalid.", c)); //NOI18N
91 //* NOISY-DEBUG: */ System.out.println("gender=" + g.getClass().getName());
96 * Valid chars (mostly for console client)
100 public static char[] validChars () {
102 if (validChars != null) {
107 // Init array, only 3 are valid as 'U' is UNKNOWN and is not valid.
108 char[] valid = new char[3];
112 for (final Gender gender : GenderUtils.selectableGenders()) {
114 //* NOISY-DEBUG: */ System.out.println("gender=" + gender);
117 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("gender={0} - adding at pos {1} ...", gender, i));
118 // Get access key as this is also the access
119 valid[i] = gender.getAccessChar();
128 // Return finialized array
135 * @param accessChar Value being entered by ConsoleClient
136 * @param messageKey Message key for resource file
138 private Gender (final char accessChar, final String messageKey) {
140 this.accessChar = accessChar;
141 this.messageKey = messageKey;
145 * Acces key (console client mostly)
147 * @return the accessChar
149 public char getAccessChar () {
150 return this.accessChar;
154 * Output value (for messages)
156 * @return the messageKey
158 public String getMessageKey () {
159 return this.messageKey;