Util { public static String camelCaseToLowerUnderscore(String s) { if (s.toUpperCase().equals(s) && isLettersAndDigits(s)) { return s.toLowerCase(); } StringBuilder b = new StringBuilder(); b.append(s.charAt(0)); boolean underscoreAdded = false; boolean lastCharacterUppercase = false; for (int i = 1; i < s.length(); i++) { char ch = s.charAt(i); if (!Character.isLetterOrDigit(ch)) { if (!underscoreAdded) b.append('_'); underscoreAdded = true; lastCharacterUppercase = false; } else if (Character.isUpperCase(ch)) { if (!underscoreAdded && !lastCharacterUppercase) { b.append("_"); } b.append(ch); underscoreAdded = false; lastCharacterUppercase = true; } else { b.append(ch); underscoreAdded = false; lastCharacterUppercase = false; } } return b.toString().toLowerCase(); }  static String getMultiplicityAbbreviation(Perspective p); static String lowerFirst(String s); static String upperFirst(String s); static String toClassSimpleName(String name); static String toJavaIdentifier(String name); static String toJavaConstantIdentifier(String name); static String camelCaseToLowerUnderscore(String s); static String toTableName(String className); static String toTableIdName(String className); static String toColumnName(String attributeName); static ModeledDomain getModeledDomain(Domains domains, String name); static ModeledDomain getModeledDomain(InputStream is, String domainName); static String getPackage(String className); static String getSimpleClassName(String className); static List<Class> getClasses(ModeledDomain domain);  }
@Test public void testToTableNameSequenceOfCapitals() { assertEquals("hello_there", camelCaseToLowerUnderscore("HelloTHERE")); }
@Test public void testToTableNameSequenceOfCapitalsFollowedByLowerCase() { assertEquals("hello_there", camelCaseToLowerUnderscore("HelloTHEre")); }
@Test public void testCamelCaseToUnderscoreForAllCapitalsJustConvertsLowerToUpper() { assertEquals("mmsi", Util.camelCaseToLowerUnderscore("MMSI")); assertEquals("id", Util.camelCaseToLowerUnderscore("ID")); assertEquals("i_d", Util.camelCaseToLowerUnderscore("I D")); }