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.addressbook.contact;
19 import org.mxchange.addressbook.application.AddressbookApplication;
23 * @author Roland Haeder
29 UNKNOWN("U", "BaseContact.gender.unknown.text"),
34 MALE("M", "BaseContact.gender.male.text"),
39 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 gender Gender character
57 public static Gender fromChar (final char gender) {
76 default: // Unsupported
77 throw new IllegalArgumentException("gender " + gender + " is invalid.");
81 //* NOISY-DEBUG: */ System.out.println("gender=" + g.getClass().getName());
90 public static char[] validChars () {
92 if (validChars != null) {
98 char[] valid = new char[3];
102 for (Object value : values()) {
104 Gender gender = (Gender) value;
107 //* NOISY-DEBUG: */ System.out.println("gender=" + gender);
110 if (gender.equals(Gender.UNKNOWN)) {
116 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("gender={0} - adding at pos {1} ...", gender, i));
118 // Get database value as this is also the access
119 valid[i] = gender.getDatabaseValue().charAt(0);
128 // Return finialized array
135 private final String databaseValue;
138 * Output value (for messages)
140 private final String messageKey;
145 * @param databaseValue Value being stored in database
146 * @param messageKey Message key for resource file
148 private Gender (final String databaseValue, final String messageKey) {
150 this.databaseValue = databaseValue;
151 this.messageKey = messageKey;
157 * @return the databaseValue
159 protected String getDatabaseValue () {
160 return this.databaseValue;
164 * Output value (for messages)
166 * @return the messageKey
168 protected String getMessageKey () {
169 return this.messageKey;
173 * Overwritten to return human-readable strings
175 * @return Human-readable strings
178 public String toString () {
179 // Get key from bundle and return it
180 return AddressbookApplication.getInstance().getMessageStringFromKey(this.getMessageKey());