NameUtil { public static String normalizeCase(String text) { if (text == null) { return null; } else if (text.isEmpty()) { return text; } else if (text.trim().isEmpty()) { return text.trim(); } String[] words = text.trim().split("\\s+"); Matcher matcher = surnamePrefixes.matcher(""); for (int i = 0; i < words.length; i++) { if (lowerCaseLeadSurname.contains(words[i].toLowerCase())) { if (i == 0) { words[i] = capitalizeFirstLetter(words[i]); } else { words[i] = words[i].toLowerCase(); } } else if (isPersonSuffix(words[i])) { continue; } else if (matcher.reset(words[i]).matches()) { words[i] = capitalizeFirstLetter(matcher.group(1)) + capitalizeFirstLetter(matcher.group(2)); } else { words[i] = capitalizeFirstLetter(words[i]); words[i] = normHyphenWord(words[i]); } } return (Joiner.on(" ").join(words)); }  static String normalizeCase(String text); static String capitalizeFirstLetter(String word); static String[] lastnameSuffix(String surname); static boolean isPersonSuffix(String word); static String normalizeOrgNameCase(String companyName);  }
@Test public void normalizeCase_Hyphen() { String name = "JO-ANN BRICE"; String actual = NameUtil.normalizeCase(name); assertEquals("Jo-Ann Brice", actual); }
@Test public void normalizeCase_deLa() { String name = "DE LA BORBOLLA, Ian Rubin"; String actual = NameUtil.normalizeCase(name); assertEquals("De la Borbolla, Ian Rubin", actual); String name2 = "REYES DE LA BARRERA"; String actual2 = NameUtil.normalizeCase(name2); assertEquals("Reyes de la Barrera", actual2); }
@Test public void normalizeCase_van() { String name = "VAN DEN HAAK"; String actual = NameUtil.normalizeCase(name); assertEquals("Van den Haak", actual); String name2 = "PAUL VAN ITTERZON"; String actual2 = NameUtil.normalizeCase(name2); assertEquals("Paul van Itterzon", actual2); String name3 = "VAN DER BEEK"; String actual3 = NameUtil.normalizeCase(name3); assertEquals("Van der Beek", actual3); }
@Test public void normalizeCase_McMac() { String name = "MCDONALD, Ronald"; String actual = NameUtil.normalizeCase(name); assertEquals("McDonald, Ronald", actual); String name2 = "MACDONALD, Ronald"; String actual2 = NameUtil.normalizeCase(name2); assertEquals("MacDonald, Ronald", actual2); }
@Test public void normalizeCase_letterApostrophe() { String name = "O\u2019NEAL, shaquille"; String actual = NameUtil.normalizeCase(name); assertEquals("O\u2019Neal, Shaquille", actual); String name2 = "DINESH D'SOUZA"; String actual2 = NameUtil.normalizeCase(name2); assertEquals("Dinesh D'Souza", actual2); String name3 = "REMEI DE CA L'ELVIRA"; String actual3 = NameUtil.normalizeCase(name3); assertEquals("Remei de Ca L'Elvira", actual3); String name4 = "L'OREAL"; String actual4 = NameUtil.normalizeCase(name4); assertEquals("L'Oreal", actual4); }
@Test public void normalizeCase_suffix() { String name = "SWAN, III, Ronald"; String actual = NameUtil.normalizeCase(name); assertEquals("Swan, III, Ronald", actual); }