return join(parts, " ");
}
+ /**
+ * Converts an UPPER_CASE_STRING to a human friendly format (Upper Case
+ * String).
+ * <p>
+ * Splits words on {@code _}. Examples:
+ * <p>
+ * {@literal MY_BEAN_CONTAINER} becomes {@literal My Bean Container}
+ * {@literal AWESOME_URL_FACTORY} becomes {@literal Awesome Url Factory}
+ * {@literal SOMETHING} becomes {@literal Something}
+ *
+ * @since
+ * @param upperCaseUnderscoreString
+ * The input string in UPPER_CASE_UNDERSCORE format
+ * @return A human friendly version of the input
+ */
+ public static String upperCaseUnderscoreToHumanFriendly(
+ String upperCaseUnderscoreString) {
+ String[] parts = upperCaseUnderscoreString.replaceFirst("^_*", "")
+ .split("_");
+ for (int i = 0; i < parts.length; i++) {
+ parts[i] = capitalize(parts[i].toLowerCase(Locale.ENGLISH));
+ }
+ return join(parts, " ");
+ }
+
private static boolean isAllUpperCase(String string) {
for (int i = 0; i < string.length(); i++) {
char c = string.charAt(i);
string = string.substring(dotLocation + 1);
}
+ if (string.matches("^[0-9A-Z_]+$")) {
+ // Deal with UPPER_CASE_PROPERTY_IDS
+ return upperCaseUnderscoreToHumanFriendly(string);
+ }
+
return camelCaseToHumanFriendly(string);
}
SharedUtil.getDuplicates(new Object[] { 1.2, "a", 1.2 }));
}
+ @Test
+ public void propertyIdToHumanFriendly() {
+ Assert.assertEquals("", SharedUtil.propertyIdToHumanFriendly(""));
+ Assert.assertEquals("First Name",
+ SharedUtil.propertyIdToHumanFriendly("firstName"));
+ Assert.assertEquals("First Name",
+ SharedUtil.propertyIdToHumanFriendly("FirstName"));
+ Assert.assertEquals("First Name",
+ SharedUtil.propertyIdToHumanFriendly("FIRST_NAME"));
+ Assert.assertEquals("Firstname",
+ SharedUtil.propertyIdToHumanFriendly("FIRSTNAME"));
+
+ Assert.assertEquals("2015 Q3",
+ SharedUtil.propertyIdToHumanFriendly("2015_Q3"));
+ Assert.assertEquals("Column X",
+ SharedUtil.propertyIdToHumanFriendly("_COLUMN_X"));
+ Assert.assertEquals("Column X",
+ SharedUtil.propertyIdToHumanFriendly("__COLUMN_X"));
+ Assert.assertEquals("1column Foobar",
+ SharedUtil.propertyIdToHumanFriendly("1COLUMN_FOOBAR"));
+ Assert.assertEquals("Result 2015",
+ SharedUtil.propertyIdToHumanFriendly("RESULT_2015"));
+ Assert.assertEquals("2015result",
+ SharedUtil.propertyIdToHumanFriendly("2015RESULT"));
+ Assert.assertEquals("Result2015",
+ SharedUtil.propertyIdToHumanFriendly("RESULT2015"));
+
+ }
}