List of usage examples for java.lang Character isUpperCase
public static boolean isUpperCase(int codePoint)
From source file:org.primeframework.persistence.util.StringTools.java
/** * Converts a camel case string into a non-camel case string using the given separator. * * @param str The string./* w ww. j a va 2 s .co m*/ * @param lowercase If the string should be lowercased. * @param separator The separator to place between camel case pieces. * @return The string. */ public static String deCamelCase(String str, boolean lowercase, String separator) { if (str == null) { return null; } if (StringUtils.isBlank(str)) { return ""; } int length = str.length(); StringBuilder buf = new StringBuilder(); for (int i = 0; i < length; i++) { char c = str.charAt(i); if (i != 0 && Character.isUpperCase(c)) { buf.append(separator); } if (lowercase && Character.isUpperCase(c)) { buf.append(Character.toLowerCase(c)); } else { buf.append(c); } } return buf.toString(); }
From source file:Main.java
/** * Checks the password against a set of rules to determine whether it is * considered weak. The rules are://from ww w . ja v a 2 s .co m * </p><p> * <ul> * <li>It is at least <code>MIN_PASSWORD_LEN</code> characters long. * <li>At least one lowercase character. * <li>At least one uppercase character. * <li>At least one digit or symbol character. * </ul> * * @param password the password to check. * * @return <code>true</code> if the password is considered to be weak, * <code>false</code> otherwise. */ public static boolean isWeakPassword(String password) { boolean hasUC = false; boolean hasLC = false; boolean hasDigit = false; boolean hasSymbol = false; if (password.length() < MIN_PASSWORD_LEN) { return true; } for (int ii = 0; ii < password.length(); ++ii) { char c; c = password.charAt(ii); if (Character.isDigit(c)) hasDigit = true; else if (Character.isUpperCase(c)) hasUC = true; else if (Character.isLowerCase(c)) hasLC = true; else hasSymbol = true; } return !(hasUC && hasLC && (hasDigit || hasSymbol)); }
From source file:Main.java
/** * Returns whether the string supplied could be used as a valid XML name. * @param name The string to test for XML name validity. * @return true if the string can be used as a valid XML name, false otherwise. *//*from w w w . j ava 2s .co m*/ public static boolean isValidXMLName(String name) { String trimmedName = name.trim(); boolean currentCharacterValid; if (name == null || trimmedName.length() == 0) { return false; } // ensure that XML standard reserved names are not used if (trimmedName.toUpperCase().startsWith("XML")) { return false; } // test that name starts with a valid XML name-starting character if (!Character.isUpperCase(trimmedName.charAt(0)) && !Character.isLowerCase(trimmedName.charAt(0)) && trimmedName.charAt(0) != '_') { return false; } // test that remainder name chars are a valid XML name characters if (name.trim().length() > 0) { for (int i = 1; i < trimmedName.length(); i++) { currentCharacterValid = false; if (Character.isUpperCase(trimmedName.charAt(i)) || Character.isLowerCase(trimmedName.charAt(i)) || Character.isDigit(trimmedName.charAt(i))) { currentCharacterValid = true; } if (trimmedName.charAt(i) == '_' || trimmedName.charAt(i) == '-' || trimmedName.charAt(i) == '.') { currentCharacterValid = true; } if (!currentCharacterValid) { return false; } } } return true; }
From source file:org.adblockplus.android.Utils.java
public static String capitalizeString(final String s) { if (s == null || s.length() == 0) { return ""; }/*w w w .j a v a 2 s. c om*/ final char first = s.charAt(0); return Character.isUpperCase(first) ? s : Character.toUpperCase(first) + s.substring(1); }
From source file:org.dkpro.tc.features.window.CaseExtractor.java
public static String getCasing(String text) { if (StringUtils.isNumeric(text)) return "numeric"; if (StringUtils.isAllLowerCase(text)) return "allLower"; else if (StringUtils.isAllUpperCase(text)) return "allUpper"; else if (Character.isUpperCase(text.charAt(0))) return "initialUpper"; else/* w ww. j a va2 s . c om*/ return "other"; }
From source file:org.batoo.common.util.BatooUtils.java
/** * Returns the acronym of the name// w w w .ja v a 2 s.c om * * @param name * the name * @return the acronym * * @since 2.0.1 */ public static String acronym(String name) { final StringBuilder builder = new StringBuilder(); for (int i = 0; i < name.length(); i++) { if (Character.isUpperCase(name.charAt(i))) { builder.append(name.charAt(i)); } } if (builder.length() == 0) { builder.append(name.charAt(0)); } return builder.toString(); }
From source file:Main.java
/** * Parse the given name./*from www . ja v a 2s. com*/ * * @param sourceName * @param separator * @return some stuff parsed from the name */ private static List<String> parseName(String sourceName, char separator) { List<String> result = new ArrayList<String>(); if (sourceName != null) { StringBuilder currentWord = new StringBuilder(64); boolean lastIsLower = false; int index; int length; for (index = 0, length = sourceName.length(); index < length; ++index) { char curChar = sourceName.charAt(index); if (!Character.isJavaIdentifierPart(curChar)) { curChar = separator; } if (Character.isUpperCase(curChar) || (!lastIsLower && Character.isDigit(curChar)) || curChar == separator) { if (lastIsLower && currentWord.length() > 1 || curChar == separator && currentWord.length() > 0) { result.add(currentWord.toString()); currentWord = new StringBuilder(64); } lastIsLower = false; } else { if (!lastIsLower) { int currentWordLength = currentWord.length(); if (currentWordLength > 1) { char lastChar = currentWord.charAt(--currentWordLength); currentWord.setLength(currentWordLength); result.add(currentWord.toString()); currentWord = new StringBuilder(64); currentWord.append(lastChar); } } lastIsLower = true; } if (curChar != separator) { currentWord.append(curChar); } } result.add(currentWord.toString()); } return result; }
From source file:com.vaadin.spring.internal.Conventions.java
public static String upperCamelToLowerHyphen(String string) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < string.length(); i++) { char c = string.charAt(i); if (Character.isUpperCase(c)) { c = Character.toLowerCase(c); if (shouldPrependHyphen(string, i)) { sb.append('-'); }//from ww w. j a v a2 s. c om } sb.append(c); } return sb.toString(); }
From source file:Main.java
/** * This method adds underscore in between the words (eg: converts GeneHomolog * to Gene_Homolog)/*from www . j a v a2 s . co m*/ * * @param name */ public static void evaluateString(String name, List<String> options, List<String> words) { if (options == null || words == null) throw new IllegalArgumentException("Options or Words is not initialized"); //remove package name if the name is a class name if (name != null) { int index = name.lastIndexOf("."); name = name.substring(index + 1); } //Set optionSet = new HashSet(); options.add(name); char firstChar = name.charAt(0); firstChar = Character.toUpperCase(firstChar); if (name.indexOf("_") > 0) { String temp = Character.toString(firstChar) + name.substring(1); options.add(temp); } String temp = firstChar + name.substring(1).toLowerCase(); options.add(temp); String evaluatedString = null; ; StringBuffer wholeWords = new StringBuffer(); StringBuffer tempSeparateWord = new StringBuffer(); char[] chars = name.toCharArray(); StringBuffer sb = new StringBuffer(); boolean first = true; int index = 0; for (int i = 0; i < chars.length; i++) { //Character c = new Character(chars[i]); //System.out.println("inside loop i = " +i); if (Character.isUpperCase(chars[i])) { if ((i > 1) && ((i - index) > 1)) { //System.out.println("Inside capital if"); first = false; sb.append("_").append(chars[i]); words.add(tempSeparateWord.toString()); tempSeparateWord = new StringBuffer(); tempSeparateWord.append(chars[i]); wholeWords.append(" ").append(chars[i]); } else { wholeWords.append(chars[i]); tempSeparateWord.append(chars[i]); sb.append(chars[i]); } index = i; } else { if (chars[i] != '_') { sb.append(chars[i]); wholeWords.append(chars[i]); tempSeparateWord.append(chars[i]); } } } //System.out.println("Converted string: "+sb.toString()); //if the string contains "_", then make the first character uppercase if (!first) { char c = Character.toUpperCase(sb.charAt(0)); sb.deleteCharAt(0); sb.insert(0, c); char c1 = Character.toUpperCase(wholeWords.charAt(0)); wholeWords.deleteCharAt(0); wholeWords.insert(0, c1); } options.add(sb.toString()); options.add(wholeWords.toString()); if (words.size() > 0) { /* StringBuffer tmp = (StringBuffer)separateWords.get(0); char c2 = Character.toUpperCase(tmp.charAt(0)); tmp.deleteCharAt(0); tmp.insert(0, c2); separateWords.remove(0); separateWords.add(0, tmp); */ String temp2 = words.get(words.size() - 1).toString(); if (tempSeparateWord != null) { temp = tempSeparateWord.toString(); if (temp2.compareToIgnoreCase(temp) != 0) { words.add(temp); } } } List possibleOptions = new ArrayList(options); options = null;//garbage collection ready //testing for (int i = 0; i < possibleOptions.size(); i++) { System.out.println("options[" + i + "]=" + possibleOptions.get(i)); } for (int i = 0; i < words.size(); i++) { System.out.println("separateWords[" + i + "]=" + words.get(i)); } return; }
From source file:com.viettel.ws.client.JDBCUtil.java
public static String convertToOrigin(String s) { String newStr = ""; for (char c : s.toCharArray()) { if (!Character.isDigit(c) && Character.isUpperCase(c)) { newStr += ("_" + String.valueOf(c)); } else if (!Character.isDigit(c) && Character.isLowerCase(c)) { newStr += String.valueOf(c).toUpperCase(); } else {/* w w w . j a va 2 s . c o m*/ newStr += String.valueOf(c); } } return newStr; }