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 org.mxchange.jcore.BaseFrameworkSystem;
24 * @author Roland Haeder
31 UNKNOWN("U", "BaseContact.gender.unknown.text"),
35 MALE("M", "BaseContact.gender.male.text"),
39 FEMALE("F", "BaseContact.gender.female.text"),
43 COMPANY("C", "BaseContact.gender.company.text");
46 * Cache for valid chars
48 private static char[] validChars;
51 * Getter for Gender enum from given character
53 * @param gender Gender character
56 public static Gender fromChar (final char gender) {
75 default: // Unsupported
76 throw new IllegalArgumentException("gender " + gender + " is invalid.");
80 //* NOISY-DEBUG: */ System.out.println("gender=" + g.getClass().getName());
89 public static char[] validChars () {
91 if (validChars != null) {
97 char[] valid = new char[3];
101 for (Object value : values()) {
103 Gender gender = (Gender) value;
106 //* NOISY-DEBUG: */ System.out.println("gender=" + gender);
108 if (gender.equals(Gender.UNKNOWN)) {
114 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("gender={0} - adding at pos {1} ...", gender, i));
115 // Get database value as this is also the access
116 valid[i] = gender.getDatabaseValue().charAt(0);
125 // Return finialized array
132 private final String databaseValue;
135 * Output value (for messages)
137 private final String messageKey;
142 * @param databaseValue Value being stored in database
143 * @param messageKey Message key for resource file
145 private Gender (final String databaseValue, final String messageKey) {
147 this.databaseValue = databaseValue;
148 this.messageKey = messageKey;
154 * @return the databaseValue
156 public String getDatabaseValue () {
157 return this.databaseValue;
161 * Output value (for messages)
163 * @return the messageKey
165 public String getMessageKey () {
166 return this.messageKey;
170 * Overwritten to return human-readable strings
172 * @return Human-readable strings
175 public String toString () {
176 // Get key from bundle and return it
177 return BaseFrameworkSystem.getInstance().getMessageStringFromKey(this.getMessageKey());