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.jcore.contact;
19 import java.text.MessageFormat;
20 import org.mxchange.jcore.BaseFrameworkSystem;
25 * @author Roland Haeder
31 UNKNOWN('U', "BaseContact.gender.unknown.text"),
36 MALE('M', "BaseContact.gender.male.text"),
41 FEMALE('F', "BaseContact.gender.female.text"),
46 COMPANY('C', "BaseContact.gender.company.text");
49 * Cache for valid chars
51 private static char[] validChars;
54 * Value being entered by ConsoleClient
56 private final char accessChar;
59 * Output value (for messages)
61 private final String messageKey;
64 * Getter for Gender enum from given character
66 * @param c Gender character
69 public static Gender fromChar (final char c) {
74 for (final Gender gender : Gender.values()) {
75 // Does the char match?
76 if (c == gender.getAccessChar()) {
85 // Didn't found a valid one
86 throw new IllegalArgumentException(MessageFormat.format("Gender {0} is invalid.", c));
90 //* NOISY-DEBUG: */ System.out.println("gender=" + g.getClass().getName());
99 public static char[] validChars () {
101 if (validChars != null) {
106 // Init array, only 3 are valid as 'U' is UNKNOWN and is not valid.
107 char[] valid = new char[3];
111 for (Gender gender : values()) {
113 //* NOISY-DEBUG: */ System.out.println("gender=" + gender);
116 if (gender.equals(Gender.UNKNOWN)) {
122 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("gender={0} - adding at pos {1} ...", gender, i));
124 // Get access key as this is also the access
125 valid[i] = gender.getAccessChar();
134 // Return finialized array
141 * @param accessChar Value being entered by ConsoleClient
142 * @param messageKey Message key for resource file
144 private Gender (final char accessChar, final String messageKey) {
146 this.accessChar = accessChar;
147 this.messageKey = messageKey;
153 * @return the accessChar
155 public char getAccessChar () {
156 return this.accessChar;
160 * Output value (for messages)
162 * @return the messageKey
164 public String getMessageKey () {
165 return this.messageKey;
169 * Overwritten to return human-readable strings
171 * @return Human-readable strings
174 public String toString () {
175 // Get key from bundle and return it
176 return BaseFrameworkSystem.getInstance().getMessageStringFromKey(this.getMessageKey());