List of usage examples for java.lang Character toUpperCase
public static int toUpperCase(int codePoint)
From source file:es.logongas.openshift.ant.JenkinsPasswordHashPropertyTask.java
/** * The MIT License//w w w .j a v a2s .c om * * Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi, David Calavera, Seiji Sogabe * Generates random salt. */ private String generateSalt() { StringBuilder buf = new StringBuilder(); SecureRandom sr = new SecureRandom(); for (int i = 0; i < 6; i++) {// log2(52^6)=34.20... so, this is about 32bit strong. boolean upper = sr.nextBoolean(); char ch = (char) (sr.nextInt(26) + 'a'); if (upper) { ch = Character.toUpperCase(ch); } buf.append(ch); } return buf.toString(); }
From source file:com.karura.framework.utils.JsHelper.java
public static String jsFragmentForAsyncResponse(String receiver, String method, String action, int timeout, Pair... params) throws IllegalArgumentException { JSONObject payload = new JSONObject(); try {/*from ww w .j ava 2s .c o m*/ payload.put("receiver", receiver); String method2 = Character.toUpperCase(method.charAt(0)) + method.substring(1); payload.put("method", method2); if (timeout != INVALID_TIMEOUT) { payload.put("timeout", timeout); } if (action != null) { payload.put("action", action); } JSONObject apiPayload = new JSONObject(); for (Pair p : params) { apiPayload.put((String) p.first, p.second); } payload.put("data", apiPayload); } catch (JSONException e) { throw new IllegalArgumentException(); } String stringify = payload.toString(); return stringify; }
From source file:com.madrobot.di.wizard.json.JSONSerializer.java
private String getGetMethodName(String fieldName, final Class<?> classType) { String methodName = ""; if (Converter.isBoolean(classType)) { if (fieldName.startsWith("is")) { methodName = fieldName;//w ww . jav a2s . c o m } else { methodName = "is" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1); } } else { methodName = "get" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1); } return methodName; }
From source file:com.amazonaws.services.iot.client.shadow.AwsIotJsonDeserializer.java
private static void invokeSetterMethod(Object target, String name, Class<?> type, Object value) throws IOException { String setter = "set" + Character.toUpperCase(name.charAt(0)) + name.substring(1); Method method;/* w w w .j a va 2s. c o m*/ try { method = target.getClass().getMethod(setter, type); } catch (NoSuchMethodException | SecurityException e) { throw new IllegalArgumentException(e); } try { method.invoke(target, value); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new IOException(e); } }
From source file:com.gargoylesoftware.htmlunit.javascript.regexp.mozilla.MozillaTestGenerator.java
/** * Outputs java test case for the specified JavaScript source. * @param author the author name//from w ww. j a va 2s .c om * @param htmlunitRoot HtmlUnit root path * @param mozillaRoot Mozilla root path * @param jsPath relative JavaScript source path, e.g. "/js/src/tests/js1_2/regexp/everything.js" * @param initialScript whether another initial script is needed or not * @throws IOException if a reading error occurs */ public static void printMozillaTest(final String author, final String htmlunitRoot, final String mozillaRoot, final String jsPath, final boolean initialScript) throws IOException { for (final Object o : FileUtils.readLines(new File(htmlunitRoot, "LICENSE.txt"))) { System.out.println(o); } final String[] jsPathTokens = jsPath.split("/"); System.out.println( "package com.gargoylesoftware.htmlunit.javascript.regexp.mozilla." + jsPathTokens[4] + ";"); System.out.println(); System.out.println("import org.junit.Test;"); System.out.println("import org.junit.runner.RunWith;"); System.out.println(); System.out.println("import com.gargoylesoftware.htmlunit.BrowserRunner;"); System.out.println("import com.gargoylesoftware.htmlunit.WebDriverTestCase;"); System.out.println("import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts;"); System.out.println(); System.out.println("/**"); System.out.println(" * Tests originally in '" + jsPath + "'."); System.out.println(" *"); System.out.println(" * @author " + author); System.out.println(" */"); System.out.println("@RunWith(BrowserRunner.class)"); String className = jsPathTokens[jsPathTokens.length - 1]; className = Character.toUpperCase(className.charAt(0)) + className.substring(1, className.length() - 3); System.out.println("public class " + className + "Test extends WebDriverTestCase {"); final List<String> lines = FileUtils.readLines(new File(mozillaRoot, jsPath)); int testNumber = 1; for (int i = 0; i < lines.size(); i++) { final String line = lines.get(i); if (line.startsWith("new TestCase")) { if (line.endsWith(";")) { System.out.println("ERROR...... test case ends with ; in " + (i + 1)); continue; } int x = i + 1; String next = lines.get(x++).trim(); while (!next.endsWith(";")) { next = lines.get(x++).trim(); } final String expected = getExpected(next); final String script; if (next.startsWith("String(")) { final int p0 = next.indexOf("String(", 1) + "String(".length(); script = next.substring(p0, next.length() - 3); } else if (next.startsWith("\"")) { script = next.substring(expected.length() + 3, next.length() - 2).trim(); } else { script = next.substring(next.indexOf(',') + 1, next.length() - 2).trim(); } System.out.println(); System.out.println(" /**"); System.out.println(" * Tests " + script + "."); System.out.println(" * @throws Exception if the test fails"); System.out.println(" */"); System.out.println(" @Test"); System.out.println(" @Alerts(\"" + expected + "\")"); System.out.println(" public void test" + testNumber++ + "() throws Exception {"); if (initialScript) { System.out.print(" test(initialScript, "); } else { System.out.print(" test("); } System.out.println("\"" + script.replace("\\", "\\\\").replace("\"", "\\\"") + "\");"); System.out.println(" }"); } } System.out.println(); if (initialScript) { System.out.println(" private void test(final String script) throws Exception {"); System.out.println(" test(null, script);"); System.out.println(" }"); System.out.println(""); System.out.println( " private void test(final String initialScript, final String script) throws Exception {"); System.out.println(" String html = \"<html><head><title>foo</title><script>\\n\";"); System.out.println(" if (initialScript != null) {"); System.out.println(" html += initialScript + \";\\n\";"); System.out.println(" }"); System.out.println(" html += \" alert(\" + script + \");\\n\""); System.out.println(" + \"</script></head><body>\\n\""); System.out.println(" + \"</body></html>\";"); System.out.println(" loadPageWithAlerts2(html);"); System.out.println(" }"); } else { System.out.println(" private void test(final String script) throws Exception {"); System.out.println(" final String html = \"<html><head><title>foo</title><script>\\n\""); System.out.println(" + \" alert(\" + script + \");\\n\""); System.out.println(" + \"</script></head><body>\\n\""); System.out.println(" + \"</body></html>\";"); System.out.println(" loadPageWithAlerts2(html);"); System.out.println(" }"); } System.out.println("}"); }
From source file:jin.collection.util.PropertyUtil.java
private static String capitalize(final String property) { return Character.toUpperCase(property.charAt(0)) + property.substring(1); }
From source file:MultiKeyCombo.java
public int selectionForKey(char aKey, ComboBoxModel aModel) { // Reset if invalid character if (aKey == KeyEvent.CHAR_UNDEFINED) { currentSearch.setLength(0);/*w w w . j a v a 2 s . c o m*/ return -1; } // Since search, don't reset search resetTimer.stop(); // Convert input to uppercase char key = Character.toUpperCase(aKey); // Build up search string currentSearch.append(key); // Find selected position within model to starting searching from Object selectedElement = aModel.getSelectedItem(); int selectedIndex = -1; if (selectedElement != null) { for (int i = 0, n = aModel.getSize(); i < n; i++) { if (aModel.getElementAt(i) == selectedElement) { selectedIndex = i; break; } } } boolean found = false; String search = currentSearch.toString(); // Search from selected forward, wrap back to beginning if not found for (int i = 0, n = aModel.getSize(); i < n; i++) { String element = aModel.getElementAt(selectedIndex).toString().toUpperCase(); if (element.startsWith(search)) { found = true; break; } selectedIndex++; if (selectedIndex == n) { selectedIndex = 0; // wrap } } // Restart timer resetTimer.start(); return (found ? selectedIndex : -1); }
From source file:com.qtplaf.library.util.StringUtils.java
/** * Separates with a blank the different tokens that can compose a normal class or method name, like for instance * doSomething into Do something./* ww w . java 2 s . c o m*/ * * @param str The string to separate. * @return The separated string. */ public static String separeTokens(String str) { StringBuilder b = new StringBuilder(); if (str != null) { for (int i = 0; i < str.length(); i++) { if (i == 0) { b.append(Character.toUpperCase(str.charAt(i))); } else { if (Character.isLowerCase(str.charAt(i - 1)) && Character.isUpperCase(str.charAt(i))) { b.append(' '); if ((i < str.length() - 1) && Character.isUpperCase(str.charAt(i + 1))) { b.append(str.charAt(i)); } else { b.append(Character.toLowerCase(str.charAt(i))); } } else { b.append(str.charAt(i)); } } } } return b.toString(); }
From source file:Main.java
/** * Internal method used by the getGetter method to try the different possible prefixes 'get', 'has' and 'is'. * * @param target Target object exposing the getter. * @param property Property being searched. * @param prefix Prefix for the supposed getter. * @return The getter method if it exists, null otherwise. *///from www. j a va2 s . c om protected static Method getGetterWithPrefix(final Class target, final String property, final String prefix) { String name = prefix + Character.toUpperCase(property.charAt(0)); if (property.length() > 1) name = name + property.substring(1); return getMethod(target, name); }
From source file:com.softmotions.commons.bean.BeanUtils.java
/** * Gets a property from the given bean.//from w w w . j a v a2s .co m * * @param clazz The class to determine the property type for. * @param propertyName The name of the property to read. * @param lenient If true is passed for this attribute, null will returned for * in case no matching getter method is defined, else an Exception will be throw * in this case. * @return The determined value. * @throws BeanException In case the bean access failed. */ public static Class getPropertyType(Class clazz, String propertyName, boolean lenient) throws BeanException { try { // getting property object from bean using "getNnnn", where nnnn is parameter name Method getterMethod = null; try { // first trying form getPropertyNaae for regular value String getterName = "get" + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1); getterMethod = clazz.getMethod(getterName, GETTER_ARG_TYPES); } catch (NoSuchMethodException ex) { // next trying isPropertyNaae for possible boolean String getterName = "is" + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1); getterMethod = clazz.getMethod(getterName, GETTER_ARG_TYPES); } return getterMethod.getReturnType(); } catch (NoSuchMethodError | NoSuchMethodException ex) { if (!lenient) { throw new BeanException("Property '" + propertyName + "' is undefined for given bean from class " + clazz.getName() + "."); } } return null; }