2 * Copyright (C) 2016 - 2022 Free Software Foundation
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.jcontacts.model.utils;
19 import java.io.Serializable;
20 import java.text.MessageFormat;
21 import org.mxchange.jcontacts.model.contact.gender.Gender;
24 * Gender utilities class
26 * @author Roland Häder<roland@mxchange.org>
28 public class GenderUtils implements Serializable {
33 private static final long serialVersionUID = 185_683_479_107L;
36 * Cache for valid chars
38 private static char[] validChars;
41 * Getter for Gender enumeration from given character
43 * @param c Gender character
45 * @return Gender enumeration
47 public static Gender fromChar (final char c) {
52 for (final Gender gender : Gender.values()) {
53 // Does the char match?
54 if (c == gender.getAccessChar()) {
63 // Didn't found a valid one
64 throw new IllegalArgumentException(MessageFormat.format("Gender {0} is invalid.", c)); //NOI18N
72 * Valid chars (mostly for console client)
76 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
77 public static char[] validChars () {
79 if (validChars != null) {
84 // Init array, only 2 are valid.
85 char[] valid = new char[2];
89 for (final Gender gender : Gender.values()) {
90 // Get access key as this is also the access
91 valid[i] = gender.getAccessChar();
100 // Return finialized array
105 * Private constructor as this is an utility class
107 private GenderUtils () {