Example usage for java.lang Character toUpperCase

List of usage examples for java.lang Character toUpperCase

Introduction

In this page you can find the example usage for java.lang Character toUpperCase.

Prototype

public static int toUpperCase(int codePoint) 

Source Link

Document

Converts the character (Unicode code point) argument to uppercase using case mapping information from the UnicodeData file.

Usage

From source file:com.netspective.sparx.util.xml.XmlSource.java

/**
 * Given a text string, return a string that would be suitable for that string to be used
 * as a Java constant (public static final XXX). The rule is to basically take every letter
 * or digit and return it in uppercase and every non-letter or non-digit as an underscore.
 *//*  w  w  w .  ja  va  2s.com*/
public static String xmlTextToJavaConstant(String xml) {
    if (xml == null || xml.length() == 0)
        return xml;

    StringBuffer constant = new StringBuffer();
    for (int i = 0; i < xml.length(); i++) {
        char ch = xml.charAt(i);
        constant.append(Character.isJavaIdentifierPart(ch) ? Character.toUpperCase(ch) : '_');
    }
    return constant.toString();
}

From source file:com.lonepulse.robozombie.proxy.Zombie.java

/**
 * <p>Accepts an object and scans it for {@link Bite} annotations. If found, a <b>thread-safe proxy</b> 
 * for the endpoint interface will be injected.</p>
 * /*  w  ww  .j a va2s  .co  m*/
 * <p>Injection targets will be searched up an inheritance hierarchy until a type is found which is 
 * <b>not</b> in a package whose name starts with the given package prefixes.</p>
 * <br>
 * <b>Usage:</b>
 * <br><br>
 * <ul>
 * <li>
 * <h5>Property Injection</h5>
 * <pre>
 * <code><b>@Bite</b>
 * private GitHubEndpoint gitHubEndpoint;
 * {
 * &nbsp; &nbsp; Zombie.infect(Arrays.asList("com.example.service", "com.example.manager"), this);
 * }
 * </code>
 * </pre>
 * </li>
 * <li>
 * <h5>Setter Injection</h5>
 * <pre>
 * <code><b>@Bite</b>
 * private GitHubEndpoint gitHubEndpoint;
 * {
 * &nbsp; &nbsp; Zombie.infect(Arrays.asList("com.example.service", "com.example.manager"), this);
 * }
 * </code>
 * <code>
 * public void setGitHubEndpoint(GitHubEndpoint gitHubEndpoint) {
 * 
 * &nbsp; &nbsp; this.gitHubEndpoint = gitHubEndpoint;
 * }
 * </code>
 * </pre>
 * </li>
 * </ul>
 * 
 * @param packagePrefixes
 *          the prefixes of packages to restrict hierarchical lookup of injection targets; if {@code null} 
 *          or {@code empty}, {@link #infect(Object, Object...)} will be used
 * <br><br>
 * @param victim
 *          an object with endpoint references marked to be <i>bitten</i> and infected 
 * <br><br>
 * @param moreVictims
 *          more unsuspecting objects with endpoint references to be infected
 * <br><br>
 * @throws NullPointerException
 *          if the object supplied for endpoint injection is {@code null} 
 * <br><br>
 * @since 1.3.0
 */
public static void infect(List<String> packagePrefixes, Object victim, Object... moreVictims) {

    assertNotNull(victim);

    List<Object> injectees = new ArrayList<Object>();
    injectees.add(victim);

    if (moreVictims != null && moreVictims.length > 0) {

        injectees.addAll(Arrays.asList(moreVictims));
    }

    Class<?> endpointInterface = null;

    for (Object injectee : injectees) {

        Class<?> type = injectee.getClass();

        do {

            for (Field field : Fields.in(type).annotatedWith(Bite.class)) {

                try {

                    endpointInterface = field.getType();
                    Object proxyInstance = EndpointProxyFactory.INSTANCE.create(endpointInterface);

                    try { //1.Simple Field Injection 

                        field.set(injectee, proxyInstance);
                    } catch (IllegalAccessException iae) { //2.Setter Injection 

                        String fieldName = field.getName();
                        String mutatorName = "set" + Character.toUpperCase(fieldName.charAt(0))
                                + fieldName.substring(1);

                        try {

                            Method mutator = injectee.getClass().getDeclaredMethod(mutatorName,
                                    endpointInterface);
                            mutator.invoke(injectee, proxyInstance);
                        } catch (NoSuchMethodException nsme) { //3.Forced Field Injection

                            field.setAccessible(true);
                            field.set(injectee, proxyInstance);
                        }
                    }
                } catch (Exception e) {

                    Log.e(Zombie.class.getName(),
                            new StringBuilder().append("Failed to inject the endpoint proxy instance of type ")
                                    .append(endpointInterface.getName()).append(" on property ")
                                    .append(field.getName()).append(" at ")
                                    .append(injectee.getClass().getName()).append(". ").toString(),
                            e);
                }
            }

            type = type.getSuperclass();
        } while (!hierarchyTerminal(type, packagePrefixes));
    }
}

From source file:com.gargoylesoftware.htmlunit.javascript.IEConditionalCompilationScriptPreProcessor.java

/**
 * Returns the index within the JavaScript code of the first occurrence of the specified substring.
 * This method searches inside multi-lines comments, but ignores the string literals and single line comments.
 * @param sourceCode JavaScript source/*w  w  w .  j a  v a2s .c  o  m*/
 * @param str any string
 * @param fromIndex the index from which to start the search
 * @return the index
 */
private static int indexOf(final String sourceCode, final String str, final int fromIndex) {
    PARSING_STATUS parsingStatus = PARSING_STATUS.NORMAL;
    char stringChar = 0;
    final int sourceCodeLength = sourceCode.length();
    for (int i = 0; i < sourceCodeLength; i++) {
        if ((parsingStatus == PARSING_STATUS.NORMAL || parsingStatus == PARSING_STATUS.IN_MULTI_LINE_COMMENT)
                && i >= fromIndex && i + str.length() <= sourceCodeLength
                && sourceCode.substring(i, i + str.length()).equals(str)) {
            return i;
        }
        final char ch = sourceCode.charAt(i);
        switch (ch) {
        case '/':
            if (parsingStatus == PARSING_STATUS.NORMAL && (i + 1 < sourceCodeLength)) {
                final char nextCh = sourceCode.charAt(i + 1);
                if (nextCh == '/') {
                    parsingStatus = PARSING_STATUS.IN_SINGLE_LINE_COMMENT;
                } else if (nextCh == '*') {
                    parsingStatus = PARSING_STATUS.IN_MULTI_LINE_COMMENT;
                } else {
                    stringChar = ch;
                    parsingStatus = PARSING_STATUS.IN_REG_EXP;
                }
            } else if (parsingStatus == PARSING_STATUS.IN_REG_EXP && ch == stringChar) {
                stringChar = 0;
                parsingStatus = PARSING_STATUS.NORMAL;
            }
            break;

        case '*':
            if (parsingStatus == PARSING_STATUS.IN_MULTI_LINE_COMMENT && i + 1 < sourceCodeLength) {
                final char nextCh = sourceCode.charAt(i + 1);
                if (nextCh == '/') {
                    parsingStatus = PARSING_STATUS.NORMAL;
                }
            }
            break;

        case '\n':
            if (parsingStatus == PARSING_STATUS.IN_SINGLE_LINE_COMMENT) {
                parsingStatus = PARSING_STATUS.NORMAL;
            }
            break;

        case '\'':
        case '"':
            if (parsingStatus == PARSING_STATUS.NORMAL) {
                stringChar = ch;
                parsingStatus = PARSING_STATUS.IN_STRING;
            } else if (parsingStatus == PARSING_STATUS.IN_STRING && ch == stringChar) {
                stringChar = 0;
                parsingStatus = PARSING_STATUS.NORMAL;
            }
            break;

        case '\\':
            if (parsingStatus == PARSING_STATUS.IN_STRING) {
                if (i + 3 < sourceCodeLength && sourceCode.charAt(i + 1) == 'x') {
                    final char ch1 = Character.toUpperCase(sourceCode.charAt(i + 2));
                    final char ch2 = Character.toUpperCase(sourceCode.charAt(i + 3));
                    if ((ch1 >= '0' && ch1 <= '9' || ch1 >= 'A' && ch1 <= 'F')
                            && (ch2 >= '0' && ch2 <= '9' || ch2 >= 'A' && ch2 <= 'F')) {
                        final char character = (char) Integer.parseInt(sourceCode.substring(i + 2, i + 4), 16);
                        if (character >= ' ') {
                            i += 3;
                            continue;
                        }
                    }
                } else if (i + 1 < sourceCodeLength) {
                    i++;
                    continue;
                }
            }

        default:
        }
    }
    return -1;
}

From source file:it.mb.whatshare.Utils.java

/**
 * Capitalizes a string./*from  www .  j av a  2 s. c o  m*/
 * 
 * @param s
 *            the string to be capitalized
 * @return the capitalized string
 */
static String capitalize(String s) {
    if (s == null || s.length() == 0)
        return "";
    return Character.toUpperCase(s.charAt(0)) + s.substring(1);
}

From source file:com.espertech.esper.event.bean.PropertyHelper.java

private static String getGetterSetterMethodName(String propertyName, String operation) {
    StringWriter writer = new StringWriter();
    writer.write(operation);/*from  w  w w . j a  v a  2 s  . co m*/
    writer.write(Character.toUpperCase(propertyName.charAt(0)));
    writer.write(propertyName.substring(1));
    return writer.toString();
}

From source file:com.thoughtworks.go.util.SelectorUtils.java

/**
 * Tests whether or not a string matches against a pattern.
 * The pattern may contain two special characters:<br>
 * '*' means zero or more characters<br>
 * '?' means one and only one character/*from   ww w. ja  v  a2s  .com*/
 *
 * @param pattern The pattern to match against.
 *                Must not be <code>null</code>.
 * @param str     The string which must be matched against the pattern.
 *                Must not be <code>null</code>.
 * @param isCaseSensitive Whether or not matching should be performed
 *                        case sensitively.
 *
 *
 * @return <code>true</code> if the string matches against the pattern,
 *         or <code>false</code> otherwise.
 */
public static boolean match(String pattern, String str, boolean isCaseSensitive) {
    char[] patArr = pattern.toCharArray();
    char[] strArr = str.toCharArray();
    int patIdxStart = 0;
    int patIdxEnd = patArr.length - 1;
    int strIdxStart = 0;
    int strIdxEnd = strArr.length - 1;
    char ch;

    boolean containsStar = false;
    for (int i = 0; i < patArr.length; i++) {
        if (patArr[i] == '*') {
            containsStar = true;
            break;
        }
    }

    if (!containsStar) {
        // No '*'s, so we make a shortcut
        if (patIdxEnd != strIdxEnd) {
            return false; // Pattern and string do not have the same size
        }
        for (int i = 0; i <= patIdxEnd; i++) {
            ch = patArr[i];
            if (ch != '?') {
                if (isCaseSensitive && ch != strArr[i]) {
                    return false; // Character mismatch
                }
                if (!isCaseSensitive && Character.toUpperCase(ch) != Character.toUpperCase(strArr[i])) {
                    return false; // Character mismatch
                }
            }
        }
        return true; // String matches against pattern
    }

    if (patIdxEnd == 0) {
        return true; // Pattern contains only '*', which matches anything
    }

    // Process characters before first star
    while ((ch = patArr[patIdxStart]) != '*' && strIdxStart <= strIdxEnd) {
        if (ch != '?') {
            if (isCaseSensitive && ch != strArr[strIdxStart]) {
                return false; // Character mismatch
            }
            if (!isCaseSensitive && Character.toUpperCase(ch) != Character.toUpperCase(strArr[strIdxStart])) {
                return false; // Character mismatch
            }
        }
        patIdxStart++;
        strIdxStart++;
    }
    if (strIdxStart > strIdxEnd) {
        // All characters in the string are used. Check if only '*'s are
        // left in the pattern. If so, we succeeded. Otherwise failure.
        for (int i = patIdxStart; i <= patIdxEnd; i++) {
            if (patArr[i] != '*') {
                return false;
            }
        }
        return true;
    }

    // Process characters after last star
    while ((ch = patArr[patIdxEnd]) != '*' && strIdxStart <= strIdxEnd) {
        if (ch != '?') {
            if (isCaseSensitive && ch != strArr[strIdxEnd]) {
                return false; // Character mismatch
            }
            if (!isCaseSensitive && Character.toUpperCase(ch) != Character.toUpperCase(strArr[strIdxEnd])) {
                return false; // Character mismatch
            }
        }
        patIdxEnd--;
        strIdxEnd--;
    }
    if (strIdxStart > strIdxEnd) {
        // All characters in the string are used. Check if only '*'s are
        // left in the pattern. If so, we succeeded. Otherwise failure.
        for (int i = patIdxStart; i <= patIdxEnd; i++) {
            if (patArr[i] != '*') {
                return false;
            }
        }
        return true;
    }

    // process pattern between stars. padIdxStart and patIdxEnd point
    // always to a '*'.
    while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) {
        int patIdxTmp = -1;
        for (int i = patIdxStart + 1; i <= patIdxEnd; i++) {
            if (patArr[i] == '*') {
                patIdxTmp = i;
                break;
            }
        }
        if (patIdxTmp == patIdxStart + 1) {
            // Two stars next to each other, skip the first one.
            patIdxStart++;
            continue;
        }
        // Find the pattern between padIdxStart & padIdxTmp in str between
        // strIdxStart & strIdxEnd
        int patLength = (patIdxTmp - patIdxStart - 1);
        int strLength = (strIdxEnd - strIdxStart + 1);
        int foundIdx = -1;
        strLoop: for (int i = 0; i <= strLength - patLength; i++) {
            for (int j = 0; j < patLength; j++) {
                ch = patArr[patIdxStart + j + 1];
                if (ch != '?') {
                    if (isCaseSensitive && ch != strArr[strIdxStart + i + j]) {
                        continue strLoop;
                    }
                    if (!isCaseSensitive && Character.toUpperCase(ch) != Character
                            .toUpperCase(strArr[strIdxStart + i + j])) {
                        continue strLoop;
                    }
                }
            }

            foundIdx = strIdxStart + i;
            break;
        }

        if (foundIdx == -1) {
            return false;
        }

        patIdxStart = patIdxTmp;
        strIdxStart = foundIdx + patLength;
    }

    // All characters in the string are used. Check if only '*'s are left
    // in the pattern. If so, we succeeded. Otherwise failure.
    for (int i = patIdxStart; i <= patIdxEnd; i++) {
        if (patArr[i] != '*') {
            return false;
        }
    }
    return true;
}

From source file:com.capgemini.boot.core.factory.internal.SettingBackedBeanFactoryPostProcessor.java

private String getGetterMethodForSetting(String settingName) {
    //Convert first letter of name to uppercase
    final char first = Character.toUpperCase(settingName.charAt(0));
    return "get" + first + settingName.substring(1);
}

From source file:com.orion.plugin.Plugin.java

/**
 * Create a new object according to the specified <tt>Plugin</tt> name
 * Invoke the constructor and return back the initialized object
 * //from   ww w .ja  v  a  2s  .c  o  m
 * @author Daniele Pantaleone
 * @param  name The name of the <tt>Plugin</tt>
 * @param  config The <tt>Plugin</tt> configuration file object
 * @param  orion <tt>Orion</tt> object reference
 * @throws ClassNotFoundException If the <tt>Plugin</tt> class fails in being loaded at runtime 
 * @throws NoSuchMethodException If a matching <tt>Method</tt> is not found
 * @throws InvocationTargetException If the underlying constructor throws an <tt>Exception</tt>
 * @throws IllegalArgumentException If the number of actual and formal parameters differ or if an unwrapping conversion for primitive arguments fails 
 * @throws IllegalAccessException If plugin <tt>Constructor</tt> object is enforcing Java language access control and the underlying constructor is inaccessible 
 * @throws InstantiationException If the <tt>Class</tt> that declares the underlying constructor represents an abstract class
 * @throws SecurityException If there is a violation while calling a non visible method (private/protected)
 * @return An initialized <tt>Plugin</tt>
 **/
public static Plugin getPlugin(String name, Configuration config, Orion orion)
        throws ClassNotFoundException, NoSuchMethodException, SecurityException, InstantiationException,
        IllegalAccessException, IllegalArgumentException, InvocationTargetException {

    // Loading the class using the configuration file name. Invoking the constructor and returning a initialized Plugin object
    Class<?> pluginClass = Class.forName("com.orion.plugin." + Character.toUpperCase(name.charAt(0))
            + name.substring(1).toLowerCase() + "Plugin");
    Constructor<?> construct = pluginClass.getConstructor(Configuration.class, Orion.class);
    Plugin plugin = (Plugin) construct.newInstance(config, orion);
    return plugin;

}

From source file:com.ngranek.unsolved.server.generator.MessagesGenerator.java

public String firstToUpper(String text) {
    return Character.toUpperCase(text.charAt(0)) + text.substring(1);
}