List of usage examples for java.lang Character toUpperCase
public static int toUpperCase(int codePoint)
From source file:Main.java
public static String capitalize(String text) { boolean capitalizeNextChar = true; char[] array = text.toCharArray(); for (int i = 0; i < array.length; i++) { Character c = text.charAt(i); if (splitChar.contains(c)) capitalizeNextChar = true;/*from w w w . ja va 2s .c om*/ else if (capitalizeNextChar) { array[i] = Character.toUpperCase(array[i]); capitalizeNextChar = false; } } return new String(array); }
From source file:Main.java
/** * This method adds underscore in between the words (eg: converts GeneHomolog * to Gene_Homolog)/* ww w. ja va 2 s . c om*/ * * @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:Main.java
public final static boolean isAlphabet(String value) { if (value == null || value.length() == 0) return false; for (int i = 0; i < value.length(); i++) { char c = Character.toUpperCase(value.charAt(i)); if ('A' <= c && c <= 'Z') return true; }//ww w .j a v a 2 s . c om return false; }
From source file:Main.java
public static String getShortWeekdayName(int day) { if (day < 1 || day > 7) throw new IndexOutOfBoundsException("Invalid index, value must be between 1 and 7"); String dayName = dateFormatSymbols.getShortWeekdays()[day]; return dayName.replace(dayName.charAt(0), Character.toUpperCase(dayName.charAt(0))); }
From source file:Main.java
/** * Capitalizes the 1st character of the given string * /*from w ww . j av a 2 s . c om*/ * @param str the String to capitalize * @return the capitalized String */ public static String capitalize(String str) { if (str == null || str.isEmpty()) return null; return Character.toUpperCase(str.charAt(0)) + str.substring(1); }
From source file:Main.java
/** * Returns the mnemonic integer.//from w w w. ja v a 2 s.c om * * @param c The character (uppercase) * @return The mnemonic. */ @SuppressWarnings("incomplete-switch") private static int setMnemonicsGet(char c) { int mnemonic = 0; switch (Character.toUpperCase(c)) { case '0': mnemonic = KeyEvent.VK_0; break; case '1': mnemonic = KeyEvent.VK_1; break; case '2': mnemonic = KeyEvent.VK_2; break; case '3': mnemonic = KeyEvent.VK_3; break; case '4': mnemonic = KeyEvent.VK_4; break; case '5': mnemonic = KeyEvent.VK_5; break; case '6': mnemonic = KeyEvent.VK_6; break; case '7': mnemonic = KeyEvent.VK_7; break; case '8': mnemonic = KeyEvent.VK_8; break; case '9': mnemonic = KeyEvent.VK_9; break; case 'A': mnemonic = KeyEvent.VK_A; break; case 'B': mnemonic = KeyEvent.VK_B; break; case 'C': mnemonic = KeyEvent.VK_C; break; case 'D': mnemonic = KeyEvent.VK_D; break; case 'E': mnemonic = KeyEvent.VK_E; break; case 'F': mnemonic = KeyEvent.VK_F; break; case 'G': mnemonic = KeyEvent.VK_G; break; case 'H': mnemonic = KeyEvent.VK_H; break; case 'I': mnemonic = KeyEvent.VK_I; break; case 'J': mnemonic = KeyEvent.VK_J; break; case 'K': mnemonic = KeyEvent.VK_K; break; case 'L': mnemonic = KeyEvent.VK_L; break; case 'M': mnemonic = KeyEvent.VK_M; break; case 'N': mnemonic = KeyEvent.VK_N; break; case 'O': mnemonic = KeyEvent.VK_O; break; case 'P': mnemonic = KeyEvent.VK_P; break; case 'Q': mnemonic = KeyEvent.VK_Q; break; case 'R': mnemonic = KeyEvent.VK_R; break; case 'S': mnemonic = KeyEvent.VK_S; break; case 'T': mnemonic = KeyEvent.VK_T; break; case 'U': mnemonic = KeyEvent.VK_U; break; case 'V': mnemonic = KeyEvent.VK_V; break; case 'W': mnemonic = KeyEvent.VK_W; break; case 'X': mnemonic = KeyEvent.VK_X; break; case 'Y': mnemonic = KeyEvent.VK_Y; break; case 'Z': mnemonic = KeyEvent.VK_Z; break; } return mnemonic; }
From source file:Main.java
public static final boolean hasChinese(String checkStr) { boolean checkedStatus = false; boolean isError = false; String spStr = " _-"; int checkStrLength = checkStr.length() - 1; for (int i = 0; i <= checkStrLength; i++) { char ch = checkStr.charAt(i); if (ch < '\176') { ch = Character.toUpperCase(ch); if (((ch < 'A') || (ch > 'Z')) && ((ch < '0') || (ch > '9')) && (spStr.indexOf(ch) < 0)) { isError = true;// w ww . jav a 2 s .co m } } } checkedStatus = !isError; return checkedStatus; }
From source file:JavaScript.java
private static String toUpperCaseEncodedChars(final String inStr) { int lastPercentPosition = -3; // 0- (-3 ) > 2: ensures the first character is not uppercased accidently final char[] c = inStr.toCharArray(); char[] cOut = new char[c.length]; for (int i = 0; i < c.length; i++) { if (c[i] == '%') { lastPercentPosition = i;//from w ww . j ava 2 s .c om } final int diff = i - lastPercentPosition; if (diff == 1 || diff == 2) { cOut[i] = Character.toUpperCase(c[i]); } else { cOut[i] = c[i]; } } return new String(cOut); }
From source file:com.hs.mail.imap.schedule.ScheduleUtils.java
public static Date getDateBefore(String str) { if (str != null) { int sz = str.length(); for (int i = 0; i < sz; i++) { char ch = str.charAt(i); if (!Character.isDigit(ch)) { try { int amount = Integer.parseInt(str.substring(0, i)); switch (Character.toUpperCase(ch)) { case 'D': return DateUtils.addDays(new Date(), -amount); case 'M': return DateUtils.addMonths(new Date(), -amount); case 'Y': return DateUtils.addYears(new Date(), -amount); }// w ww . jav a2 s. c om } catch (NumberFormatException e) { break; } } } } return null; }
From source file:Main.java
/** * Converts a string that contains upper-case letter and underscores (e.g., * constant names) to a camel-case string. For example, MY_CONSTANT is converted * to myConstant./*ww w .j a v a 2 s .c o m*/ * * @param text the string to convert * * @return a camel-case version of text */ public static String convertAllCapsToLowerCamelCase(String text) { String lowerCase = text.toLowerCase(); while (true) { int i = lowerCase.indexOf('_'); if (i < 0) { break; } String head = lowerCase.substring(0, i); if (i + 1 == lowerCase.length()) { lowerCase = head; break; } else { char charAfterUnderscore = lowerCase.charAt(i + 1); char upperCase = Character.toUpperCase(charAfterUnderscore); if (i + 2 < lowerCase.length()) { String tail = lowerCase.substring(i + 2, lowerCase.length()); lowerCase = head + upperCase + tail; } else { lowerCase = head + upperCase; break; } } } return lowerCase; }