MiscUtil { public static String toReadableLabel(String value) { StringBuilder ret = new StringBuilder(); char lastChar = 'x'; for (int i = 0; i < value.length(); i++) { char currentChar = value.charAt(i); if ((i == 0 || lastChar == ' ') && !(isSeparator(currentChar))) { currentChar = Character.toUpperCase(currentChar); } else if (Character.isLowerCase(lastChar) && Character.isUpperCase(currentChar)) { ret.append(' '); } else if (isSeparator(currentChar)) { currentChar = ' '; } if (!(lastChar == ' ' && currentChar == ' ')) { ret.append(currentChar); lastChar = currentChar; } } if (ret.toString().startsWith("Is ") || ret.toString().startsWith("Has ")) { ret.append('?'); } return ret.toString(); }  static String toVar(String name); static String toName(String name); static String toReadablePluralLabel(String value); static String toReadableLabel(String value); static boolean endsWithIgnoreCase(String name, Iterable<String> patterns); static boolean startsWithIgnoreCase(String name, Iterable<String> patterns); static boolean contains(String name, Iterable<String> patterns); static boolean equalsIgnoreCase(String name, Iterable<String> patterns); static boolean isUniCase(String value); static boolean isWithinAnUnderscorePatternButIsNotJavaBeanSpecificCase(String value, int position);  }
@Test public void readableLabel() { assertThat(toReadableLabel("a")).isEqualTo("A"); assertThat(toReadableLabel("OneOrTwo")).isEqualTo("One Or Two"); assertThat(toReadableLabel("one_or_two")).isEqualTo("One Or Two"); assertThat(toReadableLabel("one-or-two")).isEqualTo("One Or Two"); assertThat(toReadableLabel("one-or_two")).isEqualTo("One Or Two"); assertThat(toReadableLabel("one or two")).isEqualTo("One Or Two"); }
@Test public void readableLabelWithIs() { assertThat(toReadableLabel("is ok")).isEqualTo("Is Ok?"); assertThat(toReadableLabel("has salt")).isEqualTo("Has Salt?"); }