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.contact.title;
19 import java.io.Serializable;
20 import java.text.MessageFormat;
21 import java.util.LinkedList;
22 import java.util.List;
25 * Title utilities class
27 * @author Roland Häder<roland@mxchange.org>
29 public class TitleUtils implements Serializable {
34 private static final long serialVersionUID = 185_683_479_107L;
37 * Cache for valid chars
39 private static char[] validChars;
42 * All available personal titles as a list
44 * @return Selectable personal titles
45 * @deprecated Arrays.asList() is there
48 public static List<PersonalTitle> allPersonalTitlesAsList () {
50 List<PersonalTitle> list = new LinkedList<>();
52 // Walk through all genders
53 for (final PersonalTitle title : PersonalTitle.values()) {
54 // Add it and check if it has been added
63 * Getter for personal title enumeration from given character
65 * @param c PersonalTitle character
67 * @return PersonalTitle enumeration
69 public static PersonalTitle getPersonalTitleFromChar (final char c) {
71 PersonalTitle found = null;
74 for (final PersonalTitle title : PersonalTitle.values()) {
75 // Does the char match?
76 if (c == title.getAccessChar()) {
85 // Didn't found a valid one
86 throw new IllegalArgumentException(MessageFormat.format("Gender {0} is invalid.", c)); //NOI18N
94 * Valid chars (mostly for console client)
98 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
99 public static char[] validChars () {
101 if (validChars != null) {
106 // Init array, only 2 are valid.
107 char[] valid = new char[2];
111 for (final PersonalTitle title : PersonalTitle.values()) {
112 // Get access key as this is also the access
113 valid[i] = title.getAccessChar();
122 // Return finialized array
127 * Private constructor as this is an utility class
129 private TitleUtils () {