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;
21 * @author Roland Haeder
27 UNKNOWN("U", "BaseContact.gender.unknown.text"),
32 MALE("M", "BaseContact.gender.male.text"),
37 FEMALE("F", "BaseContact.gender.female.text"),
42 COMPANY("C", "BaseContact.gender.company.text");
45 * Cache for valid chars
47 private static char[] validChars;
50 * Getter for Gender enum from given character
52 * @param gender Gender character
55 public static Gender fromChar (final char gender) {
74 default: // Unsupported
75 throw new IllegalArgumentException("gender " + gender + " is invalid.");
79 //* NOISY-DEBUG: */ System.out.println("gender=" + g.getClass().getName());
88 public static char[] validChars () {
90 if (validChars != null) {
96 char[] valid = new char[3];
100 for (Object value : values()) {
102 Gender gender = (Gender) value;
105 //* NOISY-DEBUG: */ System.out.println("gender=" + gender);
108 if (gender.getDatabaseValue().equals("U")) {
114 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("gender={0} - adding at pos {1} ...", gender, i));
116 // Get database value as this is also the access
117 valid[i] = gender.getDatabaseValue().charAt(0);
126 // Return finialized array
133 private final String databaseValue;
136 * Output value (for messages)
138 private final String messageKey;
143 * @param databaseValue Value being stored in database
144 * @param messageKey Message key for resource file
146 private Gender (final String databaseValue, final String messageKey) {
148 this.databaseValue = databaseValue;
149 this.messageKey = messageKey;
155 * @return the databaseValue
157 protected String getDatabaseValue () {
158 return this.databaseValue;
162 * Output value (for messages)
164 * @return the messageKey
166 protected String getMessageKey () {
167 return this.messageKey;