@Test public void capitalizeテスト() { final String[] suspects = Arrays.gen( "", "a", "A", "ab", "Ab", "aB", "AB", "abc", "Abc", "aBc", "abC", "ABc", "AbC", "aBC", "a_b", "a_b_c", "A_b_c", "A_BC", "AB_C"); final String[] expected = Arrays.gen( "", "A", "A", "Ab", "Ab", "aB", "AB", "Abc", "Abc", "aBc", "AbC", "ABc", "AbC", "aBC", "A_b", "A_b_c", "A_b_c", "A_BC", "AB_C"); Arrays.each(suspects, new EachCall<String>() { public void each(String element, int index, int total) { String result = Beans.capitalize(element); assertEquals(expected[index], result); } }); }
public static String capitalize(String capitalizee) { if (Strings.isEmpty(capitalizee)) return capitalizee; if (capitalizee.length() > 1) { if (Character.isUpperCase(capitalizee.charAt(1))) { return capitalizee; } else { return new StringBuilder() .append(capitalizee.substring(0, 1).toUpperCase()) .append(capitalizee.substring(1, capitalizee.length())) .toString(); } } else { return capitalizee.toUpperCase(); } }
Beans { public static String capitalize(String capitalizee) { if (Strings.isEmpty(capitalizee)) return capitalizee; if (capitalizee.length() > 1) { if (Character.isUpperCase(capitalizee.charAt(1))) { return capitalizee; } else { return new StringBuilder() .append(capitalizee.substring(0, 1).toUpperCase()) .append(capitalizee.substring(1, capitalizee.length())) .toString(); } } else { return capitalizee.toUpperCase(); } } }
Beans { public static String capitalize(String capitalizee) { if (Strings.isEmpty(capitalizee)) return capitalizee; if (capitalizee.length() > 1) { if (Character.isUpperCase(capitalizee.charAt(1))) { return capitalizee; } else { return new StringBuilder() .append(capitalizee.substring(0, 1).toUpperCase()) .append(capitalizee.substring(1, capitalizee.length())) .toString(); } } else { return capitalizee.toUpperCase(); } } private  Beans(); }
Beans { public static String capitalize(String capitalizee) { if (Strings.isEmpty(capitalizee)) return capitalizee; if (capitalizee.length() > 1) { if (Character.isUpperCase(capitalizee.charAt(1))) { return capitalizee; } else { return new StringBuilder() .append(capitalizee.substring(0, 1).toUpperCase()) .append(capitalizee.substring(1, capitalizee.length())) .toString(); } } else { return capitalizee.toUpperCase(); } } private  Beans(); static String capitalize(String capitalizee); static String decapitalize(String decapitalizee); static String decapitalize(String decapitalizee, boolean doubleUppercaseEnable); static boolean isPropertyReader(String suspect); static boolean isPropertyWriter(String suspect); static boolean isPropertyAccessor(String suspect); static String generatePropertyNameFor(String accessorName); static T make(Class<T> clazz); static PropertyDescriptor[] findPropertyDescriptorsFor(Class<?> clazz); static PropertyDescriptor findPropertyDescriptorFor(Class<?> clazz, String propertyName); static Object readPropertyValueNamed(String propertyName, Object bean); static void writePropertyValueNamed(String propertyName, Object bean, Object newValue); static Object readPseudoPropertyValueNamed(String propertyName, Object bean); static void writePseudoPropertyValueNamed(String propertyName, Object bean, Object newValue); static String[] listPseudoPropertyNames(Class<?> clazz); static Class<?> detectDeclaredPropertyType(String propertyName, Class<?> target); }
Beans { public static String capitalize(String capitalizee) { if (Strings.isEmpty(capitalizee)) return capitalizee; if (capitalizee.length() > 1) { if (Character.isUpperCase(capitalizee.charAt(1))) { return capitalizee; } else { return new StringBuilder() .append(capitalizee.substring(0, 1).toUpperCase()) .append(capitalizee.substring(1, capitalizee.length())) .toString(); } } else { return capitalizee.toUpperCase(); } } private  Beans(); static String capitalize(String capitalizee); static String decapitalize(String decapitalizee); static String decapitalize(String decapitalizee, boolean doubleUppercaseEnable); static boolean isPropertyReader(String suspect); static boolean isPropertyWriter(String suspect); static boolean isPropertyAccessor(String suspect); static String generatePropertyNameFor(String accessorName); static T make(Class<T> clazz); static PropertyDescriptor[] findPropertyDescriptorsFor(Class<?> clazz); static PropertyDescriptor findPropertyDescriptorFor(Class<?> clazz, String propertyName); static Object readPropertyValueNamed(String propertyName, Object bean); static void writePropertyValueNamed(String propertyName, Object bean, Object newValue); static Object readPseudoPropertyValueNamed(String propertyName, Object bean); static void writePseudoPropertyValueNamed(String propertyName, Object bean, Object newValue); static String[] listPseudoPropertyNames(Class<?> clazz); static Class<?> detectDeclaredPropertyType(String propertyName, Class<?> target);  }