List of usage examples for java.lang Character toUpperCase
public static int toUpperCase(int codePoint)
From source file:co.id.app.sys.util.StringUtils.java
/** * Return a field name string from the given field label. * <p/>// w ww .j a va 2 s.c om * A label of " OK do it!" is returned as "okDoIt". Any &nbsp; * characters will also be removed. * <p/> * A label of "customerSelect" is returned as "customerSelect". * * @param label the field label or caption * @return a field name string from the given field label */ public static String toName(String label) { if (label == null) { throw new IllegalArgumentException("Null label parameter"); } boolean doneFirstLetter = false; boolean lastCharBlank = false; boolean hasWhiteSpace = (label.indexOf(' ') != -1); HtmlStringBuffer buffer = new HtmlStringBuffer(label.length()); for (int i = 0, size = label.length(); i < size; i++) { char aChar = label.charAt(i); if (aChar != ' ') { if (Character.isJavaIdentifierPart(aChar)) { if (lastCharBlank) { if (doneFirstLetter) { buffer.append(Character.toUpperCase(aChar)); lastCharBlank = false; } else { buffer.append(Character.toLowerCase(aChar)); lastCharBlank = false; doneFirstLetter = true; } } else { if (doneFirstLetter) { if (hasWhiteSpace) { buffer.append(Character.toLowerCase(aChar)); } else { buffer.append(aChar); } } else { buffer.append(Character.toLowerCase(aChar)); doneFirstLetter = true; } } } } else { lastCharBlank = true; } } return buffer.toString(); }
From source file:com.moviejukebox.model.Library.java
private static Index indexByTitle(Iterable<Movie> moviesList) { Index index = new Index(); for (Movie movie : moviesList) { if (!movie.isExtra() && (!removeTitleExplodeSet || !movie.isSetMaster())) { String title = movie.getStrippedTitleSort(); if (title.length() > 0) { Character firstCharacter = Character.toUpperCase(title.charAt(0)); if (!Character.isLetter(firstCharacter)) { index.addMovie("09", movie); movie.addIndex(INDEX_TITLE, "09"); } else if (charGroupEnglish && ((firstCharacter >= 'A' && firstCharacter <= 'Z') || (firstCharacter >= 'a' && firstCharacter <= 'z'))) { index.addMovie("AZ", movie); movie.addIndex(INDEX_TITLE, "AZ"); } else { String newChar = StringTools.characterMapReplacement(firstCharacter); index.addMovie(newChar, movie); movie.addIndex(INDEX_TITLE, newChar); }//from ww w. j a v a 2 s . co m } } } return index; }
From source file:com.projity.field.Field.java
private final void setAccessorMethods() { if (clazz != null && property != null) { StringBuffer javaName = new StringBuffer(property); javaName.setCharAt(0, Character.toUpperCase(javaName.charAt(0))); // First look for a getter that has a context (indexed or not) methodGet = MethodUtils.getAccessibleMethod(clazz, "get" + javaName, (isIndexed() ? getterIndexedContextParams : getterContextParams)); if (methodGet == null) // try is instead of get methodGet = MethodUtils.getAccessibleMethod(clazz, "is" + javaName, (isIndexed() ? getterIndexedContextParams : getterContextParams)); // If not found, then use standard getter (indexed or not) if (methodGet == null) { getHasNoContext = true;//from w w w . jav a 2 s .c o m methodGet = MethodUtils.getAccessibleMethod(clazz, "get" + javaName, (isIndexed() ? getterIndexedParams : getterParams)); if (methodGet == null) // try is instead of get methodGet = MethodUtils.getAccessibleMethod(clazz, "is" + javaName, (isIndexed() ? getterIndexedParams : getterParams)); } if (methodGet != null) internalType = methodGet.getReturnType(); else log.error("Not getter found for field " + getId()); // First look for a setter that has a context (indexed or not) methodSet = MethodUtils.getAccessibleMethod(clazz, "set" + javaName, (isIndexed() ? new Class[] { int.class, internalType, FieldContext.class } : new Class[] { internalType, FieldContext.class })); // If not found, then use standard setter (indexed or not) if (methodSet == null) { setHasNoContext = true; methodSet = MethodUtils.getAccessibleMethod(clazz, "set" + javaName, (isIndexed() ? new Class[] { int.class, internalType } : new Class[] { internalType })); } if (methodSet == null && !readOnly) { log.warn("No setter found for non-read-only field: " + getId()); } methodReset = MethodUtils.getAccessibleMethod(clazz, "fieldReset" + javaName, getterContextParams); if (resetHasNoContext = (methodReset == null)) methodReset = MethodUtils.getAccessibleMethod(clazz, "fieldReset" + javaName, getterParams); methodReadOnly = MethodUtils.getAccessibleMethod(clazz, "isReadOnly" + javaName, getterContextParams); if (readOnlyHasNoContext = (methodReadOnly == null)) methodReadOnly = MethodUtils.getAccessibleMethod(clazz, "isReadOnly" + javaName, getterParams); //lc // methodObjectReadOnly = MethodUtils.getAccessibleMethod(clazz, "isReadOnly", getterParams); methodHide = MethodUtils.getAccessibleMethod(clazz, "fieldHide" + javaName, (isIndexed() ? getterIndexedContextParams : getterContextParams)); if (hideHasNoContext = (methodHide == null)) methodHide = MethodUtils.getAccessibleMethod(clazz, "fieldHide" + javaName, (isIndexed() ? getterIndexedParams : getterParams)); methodOptions = MethodUtils.getAccessibleMethod(clazz, "fieldOptions" + javaName, getterContextParams); if (optionsHasNoContext = (methodOptions == null)) methodOptions = MethodUtils.getAccessibleMethod(clazz, "fieldOptions" + javaName, getterParams); } }
From source file:co.id.app.sys.util.StringUtils.java
/** * Return the setter method name for the given property name. * * @param property the property name/*from ww w.j av a 2s . co m*/ * @return the setter method name for the given property name. */ public static String toSetterName(String property) { HtmlStringBuffer buffer = new HtmlStringBuffer(property.length() + 3); buffer.append("set"); buffer.append(Character.toUpperCase(property.charAt(0))); buffer.append(property.substring(1)); return buffer.toString(); }
From source file:cn.remex.core.util.StringUtils.java
private static String changeFirstCharacterCase(final String str, final boolean capitalize) { if (str == null || str.length() == 0) { return str; }//from w w w . ja v a 2s . c o m StringBuffer buf = new StringBuffer(str.length()); if (capitalize) { buf.append(Character.toUpperCase(str.charAt(0))); } else { buf.append(Character.toLowerCase(str.charAt(0))); } buf.append(str.substring(1)); return buf.toString(); }
From source file:org.sakaiproject.reports.logic.impl.ReportsManagerImpl.java
public String replaceSystemValues(String string, Map beans) { StringBuffer buffer = new StringBuffer(string); Set beanNames = beans.keySet(); for (Iterator it = beanNames.iterator(); it.hasNext();) { String beanName = (String) it.next(); // see if the string contains reference(s) to the supported beans for (int i = buffer.indexOf(beanName), j = beanName.length(); i != -1; i = buffer.indexOf(beanName)) { // if it does, parse the property of the bean the report query references int k = buffer.indexOf("}", i + j); if (k == -1) throw new RuntimeException("Missing closing brace \"}\" in report query: " + string); String property = buffer.substring(i + j, k); // construct the bean property's corresponding "getter" method String getter = null; String param = null;//from w w w. j a va 2s . co m if (beanName.indexOf(".attribute.") != -1) { getter = "getAttribute"; param = property; } else if (beanName.indexOf(".property.") != -1) { getter = "getProperties"; param = null; } else { getter = "get" + Character.toUpperCase(property.charAt(0)) + property.substring(1); param = null; } try { // use reflection to invoke the method on the bean Object bean = beans.get(beanName); Class clasz = bean.getClass(); Class[] args = param == null ? (Class[]) null : new Class[] { String.class }; Method method = clasz.getMethod(getter, args); Object result = method.invoke(bean, (param == null ? (Object[]) null : new Object[] { param })); if (beanName.indexOf(".property.") != -1) { clasz = org.sakaiproject.entity.api.ResourceProperties.class; getter = "getProperty"; args = new Class[] { String.class }; param = property; method = clasz.getMethod(getter, args); result = method.invoke(result, new Object[] { param }); } // replace the bean expression in the report query with the actual value of calling the bean's corresponding getter method buffer.delete(i, k + 1); buffer.insert(i, (result == null ? "null" : result instanceof Time ? ((Time) result).toStringSql() : result.toString().replaceAll("'", "''"))); } catch (Exception ex) { throw new RuntimeException(ex.getMessage(), ex); } } } return buffer.toString(); }
From source file:mondrian.olap.Util.java
/** * Converts a camel-case name to an upper-case name with underscores. * * <p>For example, <code>camelToUpper("FooBar")</code> returns "FOO_BAR". * * @param s Camel-case string// w w w .jav a 2s .c o m * @return Upper-case string */ public static String camelToUpper(String s) { StringBuilder buf = new StringBuilder(s.length() + 10); int prevUpper = -1; for (int i = 0; i < s.length(); ++i) { char c = s.charAt(i); if (Character.isUpperCase(c)) { if (i > prevUpper + 1) { buf.append('_'); } prevUpper = i; } else { c = Character.toUpperCase(c); } buf.append(c); } return buf.toString(); }
From source file:com.xybase.utils.StringUtils.java
/** * Convert a string to a valid camel case string * * @param inputString the input string to convert to camel case * @param firstCharacterUppercase when true first word will be converted to upper case as well * @return camel case of the input//from w ww . j av a 2 s . c o m */ public static String getCamelCaseString(String inputString, boolean firstCharacterUppercase) { StringBuilder sb = new StringBuilder(); boolean nextUpperCase = false; for (int i = 0; i < inputString.length(); i++) { char c = inputString.charAt(i); switch (c) { case '_': case '-': case '@': case '$': case '#': case ' ': if (sb.length() > 0) { nextUpperCase = true; } break; default: if (nextUpperCase) { sb.append(Character.toUpperCase(c)); nextUpperCase = false; } else { sb.append(Character.toLowerCase(c)); } break; } } if (firstCharacterUppercase) { sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); } return sb.toString(); }
From source file:com.cohort.util.String2.java
/** * This tries to quickly determine if the string is a correctly * formatted number (including decimal, hexadecimal, octal, and "NaN" (any case)). * * <p>This may not be perfect. In the future, this may be changed to be perfect. * That shouldn't affect its use.//from w w w . java2s .c o m * * @param s usually already trimmed, since any space in s will return false. * @return true if s is *probably* a number. * This returns false if s is *definitely* not a number. * "NaN" (case insensitive) returns true. (It is a numeric value of sorts.) * null and "" return false. */ public static final boolean isNumber(String s) { if (s == null) return false; int sLength = s.length(); if (sLength == 0) return false; char ch0 = s.charAt(0); //hexadecimal? e.g., 0x2AFF //octal not supported if (ch0 == '0' && sLength >= 3 && Character.toUpperCase(s.charAt(1)) == 'X') { //ensure all remaining chars are hexadecimal for (int po = 2; po < sLength; po++) { if ("0123456789abcdefABCDEF".indexOf(s.charAt(po)) < 0) return false; } return true; } //NaN? if (ch0 == 'n' || ch0 == 'N') return s.toUpperCase().equals("NAN"); //*** rest of method: test if floating point //is 1st char .+-? int po = 0; char ch = s.charAt(po); boolean hasPeriod = ch == '.'; if (hasPeriod || ch == '-') { if (sLength == 1) //must be another char return false; ch = s.charAt(++po); //is 2nd char .? if (ch == '.') { if (hasPeriod || sLength == 2) // 2nd period or . after e are not allowed return false; hasPeriod = true; ch = s.charAt(++po); } } //initial digit if (ch < '0' || ch > '9') //there must be a digit return false; //subsequent chars boolean hasE = false; while (++po < sLength) { ch = s.charAt(po); if (ch == '.') { if (hasPeriod || hasE || po == sLength - 1) // 2nd period or . after e are not allowed return false; hasPeriod = true; } else if (ch == 'e' || ch == 'E') { if (hasE || po == sLength - 1) //e as last char is not allowed return false; hasE = true; ch = s.charAt(++po); if (ch == '-' || ch == '+') { if (po == sLength - 1) return false; ch = s.charAt(++po); } if (ch < '0' || ch > '9') //there must be a digit after e return false; } else if (ch < '0' || ch > '9') { return false; } } return true; //probably a number }
From source file:keyboard.ecloga.com.eclogakeyboard.EclogaKeyboard.java
@Override public void onPress(final int primaryCode) { setVibration();//from ww w . ja v a2 s. c om final InputConnection ic = getCurrentInputConnection(); if (popupKeypress && (primaryCode == 32 || primaryCode == 126 || primaryCode == -5 || primaryCode == -1 || primaryCode == EmojiKeyboardView.KEYCODE_EMOJI_1 || primaryCode == EmojiKeyboardView.KEYCODE_EMOJI_2 || primaryCode == EmojiKeyboardView.KEYCODE_EMOJI_3 || primaryCode == EmojiKeyboardView.KEYCODE_EMOJI_4 || primaryCode == EmojiKeyboardView.KEYCODE_EMOJI_5)) { kv.setPreviewEnabled(false); } if (oppositeCase) { timer = new CountDownTimer(300, 1) { @Override public void onTick(long millisUntilFinished) { } @Override public void onFinish() { if (!swipe) { if (primaryCode == 46) { ic.commitText(",", 1); printedCommaa = true; if (autoSpacing) { ic.commitText(" ", 1); } } else if (primaryCode == 32) { Intent intent = new Intent(getApplicationContext(), Home.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } else if (primaryCode == -5) { if (voiceInput) { if (mVoiceRecognitionTrigger.isInstalled()) { mVoiceRecognitionTrigger.startVoiceRecognition(); } } } else { char code = (char) primaryCode; if (Character.isLetter(code) && caps) { code = Character.toLowerCase(code); } else if (Character.isLetter(code) && !caps) { code = Character.toUpperCase(code); } ic.commitText(String.valueOf(code), 1); } printedDifferent = true; } } }.start(); } if (spaceDot) { if (primaryCode == 32) { doubleSpace++; if (doubleSpace == 2) { ic.deleteSurroundingText(1, 0); ic.commitText(".", 1); if (autoSpacing) { ic.commitText(" ", 1); } printedDot = true; doubleSpace = 0; } else { printedDot = false; } } else { printedDot = false; doubleSpace = 0; } } }