| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| DataUtils |
|
| 2.5;2.5 |
| 1 | package org.jtheque.utils.bean; | |
| 2 | ||
| 3 | import org.jtheque.utils.StringUtils; | |
| 4 | ||
| 5 | import java.util.regex.Pattern; | |
| 6 | ||
| 7 | /* | |
| 8 | * This file is part of JTheque. | |
| 9 | * | |
| 10 | * JTheque is free software: you can redistribute it and/or modify | |
| 11 | * it under the terms of the GNU General Public License as published by | |
| 12 | * the Free Software Foundation, either version 3 of the License. | |
| 13 | * | |
| 14 | * JTheque is distributed in the hope that it will be useful, | |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 17 | * GNU General Public License for more details. | |
| 18 | * | |
| 19 | * You should have received a copy of the GNU General Public License | |
| 20 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
| 21 | */ | |
| 22 | ||
| 23 | /** | |
| 24 | * An utility class for specific data. | |
| 25 | * | |
| 26 | * @author Baptiste Wicht | |
| 27 | */ | |
| 28 | public final class DataUtils { | |
| 29 | 0 | private static final Pattern SPACE_PATTERN = Pattern.compile(" "); |
| 30 | ||
| 31 | /** | |
| 32 | * Utility class, not instanciable. | |
| 33 | */ | |
| 34 | private DataUtils() { | |
| 35 | 0 | super(); |
| 36 | 0 | } |
| 37 | ||
| 38 | /** | |
| 39 | * Return the name and the first name of the complete name of a person. | |
| 40 | * | |
| 41 | * @param name The name of a person. | |
| 42 | * @return An array containing at his index 0 the name of the person and at his index 1 the first name of the person. | |
| 43 | */ | |
| 44 | public static String[] getNameAndFirstName(CharSequence name) { | |
| 45 | 0 | if (StringUtils.isEmpty(name)) { |
| 46 | 0 | return new String[]{"", ""}; |
| 47 | } | |
| 48 | ||
| 49 | 0 | String[] nameFirstName = SPACE_PATTERN.split(name); |
| 50 | ||
| 51 | 0 | StringBuilder nom = new StringBuilder(25); |
| 52 | ||
| 53 | 0 | for (int i = 1; i < nameFirstName.length; ++i) { |
| 54 | 0 | nom.append(StringUtils.setFirstLetterOnlyUpper(nameFirstName[i])).append(' '); |
| 55 | } | |
| 56 | ||
| 57 | 0 | StringUtils.removeLastSpace(nom); |
| 58 | ||
| 59 | 0 | return new String[]{nom.toString(), StringUtils.setFirstLetterOnlyUpper(nameFirstName[0])}; |
| 60 | } | |
| 61 | } |