List of usage examples for java.lang Character toLowerCase
public static int toLowerCase(int codePoint)
From source file:TextUtils.java
/** * See {@link String#compareToIgnoreCase(String)} * /* w w w. j a va 2 s . c om*/ * @param s * @param t * @return See {@link String#compareToIgnoreCase(String)} */ public static int compareToIgnoreCase(CharSequence s, CharSequence t) { int i = 0; while (i < s.length() && i < t.length()) { char a = Character.toLowerCase(s.charAt(i)); char b = Character.toLowerCase(t.charAt(i)); int diff = a - b; if (diff != 0) { return diff; } i++; } return s.length() - t.length(); }
From source file:Main.java
public static Map<String, Object> getProperties(Object object, boolean includeSuperClasses, boolean deepCopy) { HashMap<String, Object> map = new HashMap<String, Object>(); if (object == null) { return map; }// w w w. ja v a2 s . co m Class<?> objectClass = object.getClass(); Method[] methods = includeSuperClasses ? objectClass.getMethods() : objectClass.getDeclaredMethods(); for (Method method : methods) { if (method.getParameterTypes().length == 0 && !method.getReturnType().equals(Void.TYPE)) { String methodName = method.getName(); String propertyName = ""; if (methodName.startsWith("get")) { propertyName = methodName.substring(3); } else if (methodName.startsWith("is")) { propertyName = methodName.substring(2); } if (propertyName.length() > 0 && Character.isUpperCase(propertyName.charAt(0))) { propertyName = Character.toLowerCase(propertyName.charAt(0)) + propertyName.substring(1); Object value = null; try { value = method.invoke(object); } catch (Exception e) { } Object value2 = value; if (!deepCopy) { map.put(propertyName, value); } else { if (isSimpleObject(value)) { map.put(propertyName, value); } else if (value instanceof Map) { Map<String, Object> submap = new HashMap<String, Object>(); for (Map.Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) { submap.put(String.valueOf(entry.getKey()), convertObject(entry.getValue(), includeSuperClasses)); } map.put(propertyName, submap); } else if (value instanceof Iterable) { List<Object> sublist = new ArrayList<Object>(); for (Object v : (Iterable<?>) object) { sublist.add(convertObject(v, includeSuperClasses)); } map.put(propertyName, sublist); } else if (value.getClass().isArray()) { List<Object> sublist = new ArrayList<Object>(); int length = Array.getLength(value); for (int i = 0; i < length; i++) { sublist.add(convertObject(Array.get(value, i), includeSuperClasses)); } map.put(propertyName, sublist); } else { map.put(propertyName, getProperties(value, includeSuperClasses, deepCopy)); } } } } } return map; }
From source file:com.nortal.petit.beanmapper.BeanMappingStringUtils.java
/** * Transforms the given camel case string into it's underscore * representation. Example: someString -> some_string. * //from www . j a va2s . co m * @param camelCase * string in camel case. * @return string in underscore representation. */ public static String camelCaseToUnderscore(String camelCase) { if (StringUtils.isBlank(camelCase)) { return camelCase; } StringBuilder sb = new StringBuilder(); for (Character c : camelCase.toCharArray()) { if (Character.isUpperCase(c)) { c = Character.toLowerCase(c); if (sb.length() > 0) { sb.append("_"); } } sb.append(c); } return sb.toString(); }
From source file:Main.java
/** * <p>/*from w w w . j ava2s. c o m*/ * Uncapitalise a String. * </p> * <p/> * <p> * That is, convert the first character into lower-case. <code>null</code> is returned as <code>null</code>. * </p> * * @param str the String to uncapitalise * @return uncapitalised String */ public static String uncapitalise(String str) { if (str == null) { return null; } else if (str.length() == 0) { return ""; } else { return new StringBuilder(str.length()).append(Character.toLowerCase(str.charAt(0))) .append(str.substring(1)).toString(); } }
From source file:Main.java
/** * Convert the first character of the given String to lowercase. This method will <i>not</i> trim of spaces! * <p>// w w w.j a v a 2 s .c o m * <b>Attention:</b> this method will currently throw a <code>IndexOutOfBoundsException</code> for empty strings! * </p> * * @param data the String to get it's first character lower-cased. * @return data string with the first character transformed to lowercase * @throws NullPointerException if data is <code>null</code> */ public static String lowercaseFirstLetter(String data) { char firstLetter = Character.toLowerCase(data.substring(0, 1).charAt(0)); String restLetters = data.substring(1); return firstLetter + restLetters; }
From source file:nl.strohalm.cyclos.utils.EnumHelper.java
/** * Capitalizes an enum item name//from ww w.java2 s . c o m */ public static String capitalizeName(final Enum<?> item) { final String capitalized = StringUtils.replace(WordUtils.capitalizeFully(item.name(), new char[] { '_' }), "_", ""); return Character.toLowerCase(capitalized.charAt(0)) + capitalized.substring(1); }
From source file:Main.java
/** * A deliberately very inflexible camel case to underscored converter; it must not convert improper camel case * names to a proper underscored name./*w w w .ja va 2 s . co m*/ */ public static String camelCaseToUnderscored(String camelCaseName) { int i = 0; while (i < camelCaseName.length() && Character.isLowerCase(camelCaseName.charAt(i))) { i++; } if (i == camelCaseName.length()) { // No conversion needed return camelCaseName; } StringBuffer sb = new StringBuffer(); sb.append(camelCaseName.substring(0, i)); while (i < camelCaseName.length()) { final char c = camelCaseName.charAt(i); if (isUpperUSASCII(c)) { sb.append('_'); sb.append(Character.toLowerCase(c)); } else { sb.append(c); } i++; } return sb.toString(); }
From source file:Main.java
/** * Translates a Java file name to a XML file name according * to Android naming convention.//from w w w. j av a2s .c o m * * Doesn't append .xml extension * * @return XML file name associated with Java file name */ public static String getXmlFileNameFromJavaFileName(String javaFileName) { if (javaFileName.endsWith(".java")) { // cut off ".java" javaFileName = javaFileName.substring(0, javaFileName.length() - 5); } char[] charsJava = javaFileName.toCharArray(); StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < charsJava.length; i++) { char currentChar = charsJava[i]; if (Character.isUpperCase(currentChar) && i != 0) { stringBuilder.append('_'); } stringBuilder.append(Character.toLowerCase(currentChar)); } return stringBuilder.toString(); }
From source file:LowerCaseReader.java
@Override public int read(char[] cbuf, int off, int len) throws IOException { int count = super.read(cbuf, off, len); if (count != -1) { // Convert all read characters to lowercase int limit = off + count; for (int i = off; i < limit; i++) { cbuf[i] = Character.toLowerCase(cbuf[i]); }/*from ww w .ja va 2 s. c o m*/ } return count; }
From source file:Main.java
/** * Utility method to take a string and convert it to normal Java variable name capitalization. This normally means converting the first character from upper case to lower case, but in the (unusual) special case when there is more than one character and both the first and second characters are upper case, we leave it alone. * <p>//from ww w .java 2s . c o m * Thus "FooBah" becomes "fooBah" and "X" becomes "x", but "URL" stays as "URL". * * @param name * The string to be decapitalized. * @return The decapitalized version of the string. */ public static String decapitalize(String name) { if (name == null || name.length() == 0) { return name; } if (name.length() > 1 && Character.isUpperCase(name.charAt(1)) && Character.isUpperCase(name.charAt(0))) { return name; } char chars[] = name.toCharArray(); chars[0] = Character.toLowerCase(chars[0]); return new String(chars); }