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
32 UNKNOWN('U', "BaseContact.gender.unknown.text"),
36 MALE('M', "BaseContact.gender.male.text"),
40 FEMALE('F', "BaseContact.gender.female.text"),
44 COMPANY('C', "BaseContact.gender.company.text");
47 * Cache for valid chars
49 private static char[] validChars;
52 * Getter for Gender enum from given character
54 * @param c Gender character
57 public static Gender fromChar (final char c) {
62 for (final Gender gender : Gender.values()) {
63 // Does the char match?
64 if (c == gender.getAccessChar()) {
73 // Didn't found a valid one
74 throw new IllegalArgumentException(MessageFormat.format("Gender {0} is invalid.", c));
78 //* NOISY-DEBUG: */ System.out.println("gender=" + g.getClass().getName());
87 public static char[] validChars () {
89 if (validChars != null) {
95 char[] valid = new char[3];
99 for (Gender gender : values()) {
101 //* NOISY-DEBUG: */ System.out.println("gender=" + gender);
104 if (gender.equals(Gender.UNKNOWN)) {
110 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("gender={0} - adding at pos {1} ...", gender, i));
112 // Get access key as this is also the access
113 valid[i] = gender.getAccessChar();
122 // Return finialized array
127 * Value being entered by ConsoleClient
129 private final char accessChar;
132 * Output value (for messages)
134 private final String messageKey;
139 * @param accessChar Value being entered by ConsoleClient
140 * @param messageKey Message key for resource file
142 private Gender (final char accessChar, final String messageKey) {
144 this.accessChar = accessChar;
145 this.messageKey = messageKey;
151 * @return the accessChar
153 public char getAccessChar () {
154 return this.accessChar;
158 * Output value (for messages)
160 * @return the messageKey
162 public String getMessageKey () {
163 return this.messageKey;
167 * Overwritten to return human-readable strings
169 * @return Human-readable strings
172 public String toString () {
173 // Get key from bundle and return it
174 return BaseFrameworkSystem.getInstance().getMessageStringFromKey(this.getMessageKey());