List of usage examples for java.lang Character toUpperCase
public static int toUpperCase(int codePoint)
From source file:com.ichi2.libanki.Collection.java
/** * Utils ******************************************************************** *************************** *//* ww w . j a va 2s .com*/ public int nextID(String type) { type = "next" + Character.toUpperCase(type.charAt(0)) + type.substring(1); int id; try { id = mConf.getInt(type); } catch (JSONException e) { id = 1; } try { mConf.put(type, id + 1); } catch (JSONException e) { throw new RuntimeException(e); } return id; }
From source file:com.github.alexfalappa.nbspringboot.projects.initializr.InitializrProjectWizardIterator.java
private void createNbActions(String pkg, String mvnName, FileObject dir) throws IOException { // build main class string StringBuilder mainClass = new StringBuilder(pkg); mainClass.append('.').append(Character.toUpperCase(mvnName.charAt(0))).append(mvnName.substring(1)) .append("Application"); // retrieve default options from prefs final Preferences prefs = NbPreferences.forModule(PrefConstants.class); final boolean bForceColor = prefs.getBoolean(PREF_FORCE_COLOR_OUTPUT, true); final boolean bManualRestart = prefs.getBoolean(PREF_MANUAL_RESTART, false); final String strVmOpts = Utils.vmOptsFromPrefs(); // create nbactions.xml from template FileObject foTmpl = Templates.getTemplate(wiz); new FileBuilder(foTmpl, dir).name("nbactions").param("mainClass", mainClass.toString()) .param("forceColor", bForceColor).param("manualRestart", bManualRestart).param("vmOpts", strVmOpts) .build();// w w w .jav a2 s . c om }
From source file:Inflector.java
/** * Returns a copy of the input with the first character converted to uppercase and the remainder to lowercase. * /*w w w. j a v a 2 s . c om*/ * @param words the word to be capitalized * @return the string with the first character capitalized and the remaining characters lowercased */ public String capitalize(String words) { if (words == null) return null; String result = words.trim(); if (result.length() == 0) return ""; if (result.length() == 1) return result.toUpperCase(); return "" + Character.toUpperCase(result.charAt(0)) + result.substring(1).toLowerCase(); }
From source file:ips1ap101.lib.base.util.StrUtils.java
public static String getCamelCase(String string, String gap, boolean toLowerCaseLess) { if (string == null) { return null; }//from w ww . j av a 2 s . com String x = string.trim(); String y = ""; String z = StringUtils.isBlank(gap) ? StringUtils.EMPTY : gap.trim(); boolean b = false; boolean g = false; char c; for (int i = 0; i < x.length(); i++) { c = x.charAt(i); switch (c) { case '_': case '-': case '.': b = true; break; default: if (b) { y += g ? z : ""; y += Character.toUpperCase(c); } else { y += toLowerCaseLess ? c : Character.toLowerCase(c); } b = false; g = true; break; } } return y; }
From source file:com.commander4j.util.JUtility.java
/** * Method capitaliseAll./*from w w w .j ava 2 s . c om*/ * * @param str * String * @return String */ public static String capitaliseAll(String str) { String result = ""; char ch; // One of the characters in str. char prevCh; // The character that comes before ch in the string. int i; // A position in str, from 0 to str.length()-1. if (str != null) { prevCh = '.'; // Prime the loop with any non-letter character. for (i = 0; i < str.length(); i++) { ch = str.charAt(i); if (Character.isLetter(ch) && !Character.isLetter(prevCh)) { result = result + Character.toUpperCase(ch); } else { result = result + ch; } prevCh = ch; // prevCh for next iteration is ch. } } return result; }
From source file:com.ing.connector.util.WStringUtil.java
/** * checkForZip --> uppercases the state code where appropriate *//* w w w . j av a 2 s. co m*/ private String checkForZip(String aString) { String lString = aString; String lStateSubString = null; int lLength = lString.length(); int lStateIndex = 0; boolean lHasStateCode = true; boolean lState = false; if (lLength >= 5) { for (int i = 0; i < lLength - 4; i++) { //various 5 char strings to test for zip codes String lZipSubString = lString.substring(i, (i + 5)); char[] lZipSubArray = lZipSubString.toCharArray(); boolean lZip = true; for (int j = 0; j < 5; j++) { if (!Character.isDigit(lZipSubArray[j])) { lZip = false; } } if (lZip) { if (i > 0) { String lPreZipSubString = lString.substring(0, i); if (lPreZipSubString.length() >= 2) { for (int k = lPreZipSubString.length() - 2; k >= 0; k--) { //various 2 char strings to test for state codes lStateSubString = lPreZipSubString.substring(k, (k + 2)); char[] lStateSubArray = lStateSubString.toCharArray(); lState = true; for (int m = 0; m < 2; m++) { if (!Character.isLetter(lStateSubArray[m])) { lState = false; } } if (lState) { //we have found a state code! lStateIndex = k; break; } } } if (lState) { if (lStateSubString.equalsIgnoreCase("AL") || lStateSubString.equalsIgnoreCase("AK") || lStateSubString.equalsIgnoreCase("AZ") || lStateSubString.equalsIgnoreCase("AR") || lStateSubString.equalsIgnoreCase("CA") || lStateSubString.equalsIgnoreCase("CO") || lStateSubString.equalsIgnoreCase("CT") || lStateSubString.equalsIgnoreCase("DE") || lStateSubString.equalsIgnoreCase("DC") || lStateSubString.equalsIgnoreCase("FL") || lStateSubString.equalsIgnoreCase("GA") || lStateSubString.equalsIgnoreCase("HI") || lStateSubString.equalsIgnoreCase("ID") || lStateSubString.equalsIgnoreCase("IL") || lStateSubString.equalsIgnoreCase("IN") || lStateSubString.equalsIgnoreCase("IA") || lStateSubString.equalsIgnoreCase("KS") || lStateSubString.equalsIgnoreCase("KY") || lStateSubString.equalsIgnoreCase("LA") || lStateSubString.equalsIgnoreCase("ME") || lStateSubString.equalsIgnoreCase("MD") || lStateSubString.equalsIgnoreCase("MA") || lStateSubString.equalsIgnoreCase("MI") || lStateSubString.equalsIgnoreCase("MN") || lStateSubString.equalsIgnoreCase("MS") || lStateSubString.equalsIgnoreCase("MO") || lStateSubString.equalsIgnoreCase("MT") || lStateSubString.equalsIgnoreCase("NE") || lStateSubString.equalsIgnoreCase("NV") || lStateSubString.equalsIgnoreCase("NH") || lStateSubString.equalsIgnoreCase("NJ") || lStateSubString.equalsIgnoreCase("NM") || lStateSubString.equalsIgnoreCase("NY") || lStateSubString.equalsIgnoreCase("NC") || lStateSubString.equalsIgnoreCase("ND") || lStateSubString.equalsIgnoreCase("OH") || lStateSubString.equalsIgnoreCase("OK") || lStateSubString.equalsIgnoreCase("OR") || lStateSubString.equalsIgnoreCase("PA") || lStateSubString.equalsIgnoreCase("PR") || lStateSubString.equalsIgnoreCase("RI") || lStateSubString.equalsIgnoreCase("SC") || lStateSubString.equalsIgnoreCase("SD") || lStateSubString.equalsIgnoreCase("TN") || lStateSubString.equalsIgnoreCase("TX") || lStateSubString.equalsIgnoreCase("UT") || lStateSubString.equalsIgnoreCase("VT") || lStateSubString.equalsIgnoreCase("VA") || lStateSubString.equalsIgnoreCase("WA") || lStateSubString.equalsIgnoreCase("WV") || lStateSubString.equalsIgnoreCase("WI") || lStateSubString.equalsIgnoreCase("WY")) { char[] lCharArray = lString.toCharArray(); lCharArray[lStateIndex] = Character.toUpperCase(lCharArray[lStateIndex]); lCharArray[lStateIndex + 1] = Character.toUpperCase(lCharArray[lStateIndex + 1]); lString = new String(lCharArray); } // if (lStateSubString.equalsIgnoreCase("AL") || ... } // if(lState) } // if(i > 0) } // if (lZip) } // for (int i=0; i < lLength - 4; i++) } // if(lLength >= 5) return lString; }
From source file:it.cnr.icar.eric.server.security.authorization.RegistryAttributeFinderModule.java
private static String capitalize(String s) { if (s.length() == 0) { return s; }//ww w.j a va2 s . c o m char chars[] = s.toCharArray(); chars[0] = Character.toUpperCase(chars[0]); return new String(chars); }
From source file:com.twinsoft.convertigo.beans.CheckBeans.java
private static void analyzeJavaClass(String javaClassName) { try {//from w ww . j av a 2 s . c o m Class<?> javaClass = Class.forName(javaClassName); String javaClassSimpleName = javaClass.getSimpleName(); if (!DatabaseObject.class.isAssignableFrom(javaClass)) { //Error.NON_DATABASE_OBJECT.add(javaClassName); return; } nBeanClass++; String dboBeanInfoClassName = javaClassName + "BeanInfo"; MySimpleBeanInfo dboBeanInfo = null; try { dboBeanInfo = (MySimpleBeanInfo) (Class.forName(dboBeanInfoClassName)).newInstance(); } catch (ClassNotFoundException e) { if (!Modifier.isAbstract(javaClass.getModifiers())) { Error.MISSING_BEAN_INFO .add(javaClassName + " (expected bean info: " + dboBeanInfoClassName + ")"); } return; } catch (Exception e) { e.printStackTrace(); return; } BeanDescriptor beanDescriptor = dboBeanInfo.getBeanDescriptor(); // Check abstract class if (Modifier.isAbstract(javaClass.getModifiers())) { // Check icon (16x16) String declaredIconName = MySimpleBeanInfo.getIconName(dboBeanInfo, MySimpleBeanInfo.ICON_COLOR_16x16); if (declaredIconName != null) { Error.ABSTRACT_CLASS_WITH_ICON.add(javaClassName); } // Check icon (32x32) declaredIconName = MySimpleBeanInfo.getIconName(dboBeanInfo, MySimpleBeanInfo.ICON_COLOR_32x32); if (declaredIconName != null) { Error.ABSTRACT_CLASS_WITH_ICON.add(javaClassName); } // Check display name if (!beanDescriptor.getDisplayName().equals("?")) { Error.ABSTRACT_CLASS_WITH_DISPLAY_NAME.add(javaClassName); } // Check description if (!beanDescriptor.getShortDescription().equals("?")) { Error.ABSTRACT_CLASS_WITH_DESCRIPTION.add(javaClassName); } } else { nBeanClassNotAbstract++; // Check bean declaration in database_objects.xml if (!dboXmlDeclaredDatabaseObjects.contains(javaClassName)) { Error.BEAN_DEFINED_BUT_NOT_USED.add(javaClassName); } // Check icon name policy (16x16) String declaredIconName = MySimpleBeanInfo.getIconName(dboBeanInfo, MySimpleBeanInfo.ICON_COLOR_16x16); String expectedIconName = javaClassName.replace(javaClassSimpleName, "images/" + javaClassSimpleName); expectedIconName = "/" + expectedIconName.replace('.', '/') + "_color_16x16"; expectedIconName = expectedIconName.toLowerCase() + ".png"; if (declaredIconName != null) { if (!declaredIconName.equals(expectedIconName)) { Error.BEAN_ICON_NAMING_POLICY.add(javaClassName + "\n" + " Declared: " + declaredIconName + "\n" + " Expected: " + expectedIconName); } } // Check icon file (16x16) File iconFile = new File(srcBase + declaredIconName); if (!iconFile.exists()) { Error.BEAN_MISSING_ICON.add(javaClassName + " - icon missing: " + declaredIconName); } else { icons.remove(declaredIconName); } // Check icon name policy (32x32) declaredIconName = MySimpleBeanInfo.getIconName(dboBeanInfo, MySimpleBeanInfo.ICON_COLOR_32x32); expectedIconName = javaClassName.replace(javaClassSimpleName, "images/" + javaClassSimpleName); expectedIconName = "/" + expectedIconName.replace('.', '/') + "_color_32x32"; expectedIconName = expectedIconName.toLowerCase() + ".png"; if (declaredIconName != null) { if (!declaredIconName.equals(expectedIconName)) { Error.BEAN_ICON_NAMING_POLICY.add(javaClassName + "\n" + " Declared: " + declaredIconName + "\n" + " Expected: " + expectedIconName); } } // Check icon file (32x32) iconFile = new File(srcBase + declaredIconName); if (!iconFile.exists()) { Error.BEAN_MISSING_ICON.add(javaClassName + " - icon missing: " + declaredIconName); } else { icons.remove(declaredIconName); } // Check display name if (beanDescriptor.getDisplayName().equals("?")) { Error.BEAN_MISSING_DISPLAY_NAME.add(javaClassName); } // Check description if (beanDescriptor.getShortDescription().equals("?")) { Error.BEAN_MISSING_DESCRIPTION.add(javaClassName); } } // Check declared bean properties PropertyDescriptor[] propertyDescriptors = dboBeanInfo.getLocalPropertyDescriptors(); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { String propertyName = propertyDescriptor.getName(); try { javaClass.getDeclaredField(propertyName); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { try { // Try to find it in the upper classes javaClass.getField(propertyName); } catch (SecurityException e1) { // printStackTrace(); } catch (NoSuchFieldException e1) { Error.PROPERTY_DECLARED_BUT_NOT_FOUND.add(javaClassName + ": " + propertyName); } } } Method[] methods = javaClass.getDeclaredMethods(); List<Method> listMethods = Arrays.asList(methods); List<String> listMethodNames = new ArrayList<String>(); for (Method method : listMethods) { listMethodNames.add(method.getName()); } Field[] fields = javaClass.getDeclaredFields(); for (Field field : fields) { int fieldModifiers = field.getModifiers(); // Ignore static fields (constants) if (Modifier.isStatic(fieldModifiers)) continue; String fieldName = field.getName(); String errorMessage = javaClassName + ": " + field.getName(); // Check bean info PropertyDescriptor propertyDescriptor = isBeanProperty(fieldName, dboBeanInfo); if (propertyDescriptor != null) { // Check bean property name policy if (!propertyDescriptor.getName().equals(fieldName)) { Error.PROPERTY_NAMING_POLICY.add(errorMessage); } String declaredGetter = propertyDescriptor.getReadMethod().getName(); String declaredSetter = propertyDescriptor.getWriteMethod().getName(); String formattedFieldName = Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1); String expectedGetter = "get" + formattedFieldName; String expectedSetter = "set" + formattedFieldName; // Check getter name policy if (!declaredGetter.equals(expectedGetter)) { Error.GETTER_SETTER_DECLARED_EXPECTED_NAMES_MISMATCH .add(errorMessage + "\n" + " Declared getter: " + declaredGetter + "\n" + " Expected getter: " + expectedGetter); } // Check setter name policy if (!declaredSetter.equals(expectedSetter)) { Error.GETTER_SETTER_DECLARED_EXPECTED_NAMES_MISMATCH .add(errorMessage + "\n" + " Declared setter: " + declaredSetter + "\n" + " Expected setter: " + expectedSetter); } // Check required private modifiers for bean property if (!Modifier.isPrivate(fieldModifiers)) { Error.PROPERTY_NOT_PRIVATE.add(errorMessage); } // Check getter if (!listMethodNames.contains(declaredGetter)) { Error.GETTER_SETTER_DECLARED_BUT_NOT_FOUND .add(errorMessage + " - Declared getter not found: " + declaredGetter); } // Check setter if (!listMethodNames.contains(declaredSetter)) { Error.GETTER_SETTER_DECLARED_BUT_NOT_FOUND .add(errorMessage + " - Declared setter not found: " + declaredGetter); } // Check non transient modifier if (Modifier.isTransient(fieldModifiers)) { Error.PROPERTY_TRANSIENT.add(errorMessage); } } else if (!Modifier.isTransient(fieldModifiers)) { Error.FIELD_NOT_TRANSIENT.add(errorMessage); } } } catch (ClassNotFoundException e) { System.out.println("ERROR on " + javaClassName); e.printStackTrace(); } }
From source file:com.flipkart.flux.resource.StateMachineResource.java
/** * Helper method to return a display friendly name for the specified label. * Returns a phrase containing single-space separated words that were split at Camel Case boundaries *///from w w w. j a v a 2 s.c om private String getDisplayName(String label) { if (label == null) { return null; } String words = label.replaceAll( // Based on http://stackoverflow.com/questions/2559759/how-do-i-convert-camelcase-into-human-readable-names-in-java String.format("%s|%s|%s", "(?<=[A-Z])(?=[A-Z][a-z])", "(?<=[^A-Z])(?=[A-Z])", "(?<=[A-Za-z])(?=[^A-Za-z])"), " "); StringBuffer sb = new StringBuffer(); for (String s : words.split(" ")) { sb.append(Character.toUpperCase(s.charAt(0))); if (s.length() > 1) { sb.append(s.substring(1, s.length()).toLowerCase()); sb.append(" "); // add the single space back. Used for wrapping words onto next line in the display } } return sb.toString().trim(); }
From source file:com.commander4j.util.JUtility.java
static String capitalize(String input) { String str = input.toLowerCase(); String result = ""; char ch;//from ww w . java 2 s. c o m char prevCh; int i; prevCh = '.'; for (i = 0; i < str.length(); i++) { ch = str.charAt(i); if (Character.isLetter(ch) && !Character.isLetter(prevCh)) { result = result + Character.toUpperCase(ch); } else { result = result + ch; } prevCh = ch; } return result; }