List of usage examples for java.lang Character toUpperCase
public static int toUpperCase(int codePoint)
From source file:Main.java
/** * Fix problems in the URIs (spaces for instance). * * @param uri/* www.j ava2s . c o m*/ * The original URI. * @return The corrected URI. */ private static String fixUri(String uri) { // handle platform dependent strings String path = uri.replace(java.io.File.separatorChar, '/'); // Windows fix if (path.length() >= 2) { final char ch1 = path.charAt(1); // change "C:blah" to "/C:blah" if (ch1 == ':') { final char ch0 = Character.toUpperCase(path.charAt(0)); if (ch0 >= 'A' && ch0 <= 'Z') { path = "/" + path; } } // change "//blah" to "file://blah" else if (ch1 == '/' && path.charAt(0) == '/') { path = "file:" + path; } } // replace spaces in file names with %20. // Original comment from JDK5: the following algorithm might not be // very performant, but people who want to use invalid URI's have to // pay the price. final int pos = path.indexOf(' '); if (pos >= 0) { final StringBuilder sb = new StringBuilder(path.length()); // put characters before ' ' into the string builder for (int i = 0; i < pos; i++) { sb.append(path.charAt(i)); } // and %20 for the space sb.append("%20"); // for the remaining part, also convert ' ' to "%20". for (int i = pos + 1; i < path.length(); i++) { if (path.charAt(i) == ' ') { sb.append("%20"); } else { sb.append(path.charAt(i)); } } return sb.toString(); } return path; }
From source file:Main.java
public static String capitial(String str) { if (str == "" || str.length() == 0) return ""; char first = str.charAt(0); if (Character.isUpperCase(first)) return str; else// w w w . j av a2 s. c om return Character.toUpperCase(first) + str.substring(1); }
From source file:Main.java
public static String capitalize(final String line) { return Character.toUpperCase(line.charAt(0)) + line.substring(1); }
From source file:Main.java
public static String capitalize(String propertyName) { return Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1); }
From source file:Main.java
public static void setProperties(Object object, Map<String, ? extends Object> properties, boolean includeSuperClasses) { if (object == null || properties == null) { return;/*w w w . j ava 2 s. c o m*/ } Class<?> objectClass = object.getClass(); for (Map.Entry<String, ? extends Object> entry : properties.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if (key != null && key.length() > 0) { String setterName = "set" + Character.toUpperCase(key.charAt(0)) + key.substring(1); Method setter = null; // Try to use the exact setter if (value != null) { try { if (includeSuperClasses) { setter = objectClass.getMethod(setterName, value.getClass()); } else { setter = objectClass.getDeclaredMethod(setterName, value.getClass()); } } catch (Exception ex) { } } // Find a more generic setter if (setter == null) { Method[] methods = includeSuperClasses ? objectClass.getMethods() : objectClass.getDeclaredMethods(); for (Method method : methods) { if (method.getName().equals(setterName)) { Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length == 1 && isAssignableFrom(parameterTypes[0], value)) { setter = method; break; } } } } // Invoke if (setter != null) { try { setter.invoke(object, value); } catch (Exception e) { } } } } }
From source file:Main.java
public static String toJavaCasing(final String pName) { final char[] name = pName.toLowerCase().toCharArray(); name[0] = Character.toUpperCase(name[0]); return new String(name); }
From source file:Main.java
/** * capitalize first letter/*www.jav a 2 s . c o m*/ * * <pre> * capitalizeFirstLetter(null) = null; * capitalizeFirstLetter("") = ""; * capitalizeFirstLetter("2ab") = "2ab" * capitalizeFirstLetter("a") = "A" * capitalizeFirstLetter("ab") = "Ab" * capitalizeFirstLetter("Abc") = "Abc" * </pre> * * @param str * @return */ public static String capitalizeFirstLetter(String str) { if (isEmpty(str)) { return str; } char c = str.charAt(0); return (!Character.isLetter(c) || Character.isUpperCase(c)) ? str : new StringBuilder(str.length()).append(Character.toUpperCase(c)).append(str.substring(1)) .toString(); }
From source file:Main.java
public static void putInHashMapByGivenAttribute(HashMap map, Object obj, String attribName) { try {/*from www .j a va 2 s .c o m*/ Class class1 = obj.getClass(); String methodName = "get" + Character.toUpperCase(attribName.charAt(0)) + attribName.substring(1); Method method = class1.getMethod(methodName, new Class[0]); Object attributeValue = method.invoke(obj, new Object[0]); map.put(attributeValue, obj); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
private static String capitalize(String str) { if (TextUtils.isEmpty(str)) { return str; }/*from w ww . j ava2s.com*/ char[] arr = str.toCharArray(); boolean capitalizeNext = true; String phrase = ""; for (char c : arr) { if (capitalizeNext && Character.isLetter(c)) { phrase += Character.toUpperCase(c); capitalizeNext = false; continue; } else if (Character.isWhitespace(c)) { capitalizeNext = true; } phrase += c; } return phrase; }
From source file:Main.java
public static String capWords(String givenString) { String[] arr = givenString.split(" "); StringBuffer sb = new StringBuffer(); for (int i = 0; i < arr.length; i++) { sb.append(Character.toUpperCase(arr[i].charAt(0))).append(arr[i].substring(1)).append(" "); }// w w w.j a v a 2s . com return sb.toString().trim(); }