NameUtil { public static String normalizeOrgNameCase(String companyName) { Matcher matcher = orgPrefixes.matcher(""); String[] words = companyName.trim().split("\\s+"); for (int i = 0; i < words.length; i++) { if (WordUtil.isMixedCase(words[i])){ continue; } if (words[i].length() < 5 && WordUtil.hasCharacter(words[i].replaceFirst("\\.$", ""), "&./")) { words[i] = words[i].toUpperCase(); } else if (words.length > 2 && LOWERCASE_WORDS.contains(words[i].toLowerCase())) { if (i == 0) { words[i] = capitalizeFirstLetter(words[i]); } else { words[i] = words[i].toLowerCase(); } } else if (matcher.reset(words[i]).matches()) { words[i] = capitalizeFirstLetter(matcher.group(1)) + capitalizeFirstLetter(matcher.group(2)); } else if (words[i].length() < 3) { words[i] = words[i].toUpperCase(); } else if (WordUtil.hasVowelAndConsonant(words[i])) { if (WordUtil.hasAllCapitals(words[i])) { words[i] = capitalizeFirstLetter(words[i]); words[i] = normHyphenWord(words[i]); } } else { words[i] = words[i].toUpperCase(); } } 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 orgName() { String companyName = "B&B TECHNOLOGIES L.P."; String actual = NameUtil.normalizeOrgNameCase(companyName); assertEquals("B&B Technologies L.P.", actual); String companyName2 = "BB TECHNOLOGIES L.P."; String actual2 = NameUtil.normalizeOrgNameCase(companyName2); assertEquals("BB Technologies L.P.", actual2); String companyName3 = "THE UNIVERSITY OF CALIFORNIA"; String actual3 = NameUtil.normalizeOrgNameCase(companyName3); assertEquals("The University of California", actual3); String companyName4 = "L'OREAL"; String actual4 = NameUtil.normalizeOrgNameCase(companyName4); assertEquals("L'Oreal", actual4); String companyName5 = "MCDONALD'S"; String actual5 = NameUtil.normalizeOrgNameCase(companyName5); assertEquals("McDonald's", actual5); String companyName6 = "VIA TECHNOLOGIES, INC."; String actual6 = NameUtil.normalizeOrgNameCase(companyName6); assertEquals("Via Technologies, Inc.", actual6); String companyName7 = "VIA OF THE LEHIGH VALLEY"; String actual7 = NameUtil.normalizeOrgNameCase(companyName7); assertEquals("Via of the Lehigh Valley", actual7); String companyName8 = "3SHAPE A/S"; String actual8 = NameUtil.normalizeOrgNameCase(companyName8); assertEquals("3Shape A/S", actual8); String companyName9 = "COLGATE-PALMOLIVE COMPANY"; String actual9 = NameUtil.normalizeOrgNameCase(companyName9); assertEquals("Colgate-Palmolive Company", actual9); String companyName10 = "SharkNinja Operating LLC"; String actual10 = NameUtil.normalizeOrgNameCase(companyName10); assertEquals("SharkNinja Operating LLC", actual10); String companyName11 = "Anton Paar GmbH"; String actual11 = NameUtil.normalizeOrgNameCase(companyName11); assertEquals("Anton Paar GmbH", actual11); }