Example usage for java.lang Character isUpperCase

List of usage examples for java.lang Character isUpperCase

Introduction

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

Prototype

public static boolean isUpperCase(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is an uppercase character.

Usage

From source file:org.powertac.logtool.common.DomainObjectReader.java

private String resolveDoubleCaps(String name) {
    // lowercase first char of field name with two initial caps
    if (Character.isUpperCase(name.charAt(0)) && Character.isUpperCase(name.charAt(1))) {
        char[] chars = name.toCharArray();
        chars[0] = Character.toLowerCase(chars[0]);
        return (String.valueOf(chars));
    }/*from ww w .  j a  v  a 2 s  . c om*/
    return name;
}

From source file:org.lockss.util.NumberUtil.java

/**
 * Increment an alphabetical string by the given delta, considering the string
 * to represent a value in base-26 using the characters a-z or A-Z - the
 * string is treated case-insensitively. For example, with a delta of 1:
 * <ul>// w  w w.  ja  v a  2s.  c o m
 *   <li>aaa to aab</li>
 *   <li>aaz to aba</li>
 *   <li>zzy to zzz</li>
 *   <li>zyz to zza</li>
 * </ul>
 * <p>
 * Note that after 'z' comes 'ba', because 'a' corresponds to 0 and is so
 * every number is implicitly preceded by 'a'. This may not be what is desired
 * for some sequences, in which case this may need to be adapted.
 * <p>
 * The string is lower cased before the increment is applied, and then each
 * character position that was upper case in the original string is upper
 * cased before returning. An exception will be thrown if any character is
 * outside of a-z after lower casing. If the value limit for the string length
 * is reached, the returned string will be longer; the extra characters will
 * be lower cased, which may be unwanted.
 *
 * @param s a purely alphabetical string
 * @return a string incremented according to base-26
 * @throws NumberFormatException if the string contains inappropriate characters or cannot be incremented
 */
public static String incrementBase26String(String s, int delta) throws NumberFormatException {
    // Track the case of each character, so we can reset them before returning
    BitSet cases = new BitSet();
    for (int i = 0; i < s.length(); i++) {
        cases.set(i, Character.isUpperCase(s.charAt(i)));
    }
    // Convert, increment, convert back
    String res = toBase26(fromBase26(s.toLowerCase()) + delta);
    // Pad the string to the correct length with 'a'
    res = StringUtils.leftPad(res, s.length(), 'a');
    // Re-case the chars - using an offset in case the new string is longer
    char[] carr = res.toCharArray();
    int offset = carr.length - s.length();
    for (int pos = 0; pos < s.length(); pos++) {
        if (cases.get(pos))
            carr[offset + pos] = Character.toUpperCase(carr[offset + pos]);
    }
    return new String(carr);
}

From source file:org.opensextant.util.TextUtils.java

/**
 * detects if string alpha chars are purely lower case.
 * //w  w  w. jav a 2s.co  m
 * @param text
 *            text
 * @param textcase
 *            1 lower, 2 upper
 * @return if case matches given textcase param
 */
public static boolean checkCase(String text, int textcase) {
    if (text == null) {
        return false;
    }
    int caseCount = 0;

    for (char c : text.toCharArray()) {
        if (!Character.isLetter(c)) {
            continue;
        }
        if (textcase == 1) {
            if (Character.isUpperCase(c)) {
                // Checking for lower case; Fail if upper case is found.
                return false;
            } else if (Character.isLowerCase(c)) {
                ++caseCount;
            }
        } else if (textcase == 2) {
            if (Character.isLowerCase(c)) {
                // Checking for upper case; Fail if lower case is found.
                return false;
            } else if (Character.isUpperCase(c)) {
                ++caseCount;
            }
        }
    }
    // IF at least one letter found in the case, return true.
    // It is possible that mixed-language text that has no case-sense 
    // is mixed up with ASCII or Romance language text. 
    //   test     LOWER   UPPER
    //   A b  ==>  no      no
    //   A  ==>  no      yes
    //   a  ==>  yes      no
    return caseCount > 0;
}

From source file:org.jboss.errai.codegen.util.CDIAnnotationUtils.java

public static String formatDefaultElName(final String rawName) {
    if (rawName.isEmpty() || Character.isLowerCase(rawName.charAt(0))
            || (rawName.length() > 1 && Character.isUpperCase(rawName.charAt(1)))) {
        return rawName;
    } else {//from w  w w .j a va2s. c o m
        final StringBuilder builder = new StringBuilder(rawName);
        builder.setCharAt(0, Character.toLowerCase(builder.charAt(0)));

        return builder.toString();
    }
}

From source file:com.simplexwork.mysql.tools.utils.DocumentUtils.java

/**
 * mapperxml??/*  www . j  av  a2 s  . c o  m*/
 * @param str
 * @return
 */
private static String getMapperXmlName(String str) {
    str = getStartSmallName(str);
    for (int i = 0; i < str.length(); i++) {
        char c = str.charAt(i);
        if (Character.isUpperCase(c)) {
            String upper = c + "";
            String lower = "-" + upper.toLowerCase();
            str = str.replace(upper, lower);
        }
    }
    return str;
}

From source file:org.languagetool.rules.uk.TokenAgreementRule.java

private static boolean isCapitalized(String token) {
    return token.length() > 1 && Character.isUpperCase(token.charAt(0))
            && Character.isLowerCase(token.charAt(1));
}

From source file:org.codehaus.griffon.commons.GriffonClassUtils.java

/**
 * Converts a property name into its natural language equivalent eg ('firstName' becomes 'First Name')
 * @param name The property name to convert
 * @return The converted property name/*ww  w .  jav a2s . co m*/
 */
public static String getNaturalName(String name) {
    List words = new ArrayList();
    int i = 0;
    char[] chars = name.toCharArray();
    for (int j = 0; j < chars.length; j++) {
        char c = chars[j];
        String w;
        if (i >= words.size()) {
            w = "";
            words.add(i, w);
        } else {
            w = (String) words.get(i);
        }

        if (Character.isLowerCase(c) || Character.isDigit(c)) {
            if (Character.isLowerCase(c) && w.length() == 0)
                c = Character.toUpperCase(c);
            else if (w.length() > 1 && Character.isUpperCase(w.charAt(w.length() - 1))) {
                w = "";
                words.add(++i, w);
            }

            words.set(i, w + c);
        } else if (Character.isUpperCase(c)) {
            if ((i == 0 && w.length() == 0) || Character.isUpperCase(w.charAt(w.length() - 1))) {
                words.set(i, w + c);
            } else {
                words.add(++i, String.valueOf(c));
            }
        }

    }

    StringBuffer buf = new StringBuffer();

    for (Iterator j = words.iterator(); j.hasNext();) {
        String word = (String) j.next();
        buf.append(word);
        if (j.hasNext())
            buf.append(' ');
    }
    return buf.toString();
}

From source file:org.opencms.search.solr.spellchecking.CmsSolrSpellchecker.java

/**
 * Parse JSON parameters from this request.
 *
 * @param jsonRequest The request in the JSON format.
 * @return CmsSpellcheckingRequest object that contains parsed parameters or null, if JSON input is not well
 * defined.//from   w  w  w  .j a va  2  s .co  m
 */
private CmsSpellcheckingRequest parseJsonRequest(JSONObject jsonRequest) {

    final String id = jsonRequest.optString(JSON_ID);

    final JSONObject params = jsonRequest.optJSONObject(JSON_PARAMS);

    if (null == params) {
        LOG.debug("Invalid JSON request: No field \"params\" defined. ");
        return null;
    }
    final JSONArray words = params.optJSONArray(JSON_WORDS);
    final String lang = params.optString(JSON_LANG, LANG_DEFAULT);
    if (null == words) {
        LOG.debug("Invalid JSON request: No field \"words\" defined. ");
        return null;
    }

    // Convert JSON array to array of type String
    final List<String> wordsToCheck = new LinkedList<String>();
    for (int i = 0; i < words.length(); i++) {
        final String word = words.opt(i).toString();
        wordsToCheck.add(word);

        if (Character.isUpperCase(word.codePointAt(0))) {
            wordsToCheck.add(word.toLowerCase());
        }
    }

    return new CmsSpellcheckingRequest(wordsToCheck.toArray(new String[wordsToCheck.size()]), lang, id);
}

From source file:com.nridge.core.base.field.Field.java

/**
 * Returns a title that has been derived from the name of the
 * field.  This method will handle the conversion as follows:
 *
 * <ul>/*from w  w  w.j  a  v  a  2s. c  o  m*/
 *     <li>id becomes Id</li>
 *     <li>employee_name becomes Employee Name</li>
 *     <li>federatedName becomes Federated Name</li>
 * </ul>
 *
 * The logic will ignore any other conventions and simply pass
 * the original character forward.
 *
 * @param aFieldName Name of the field to convert.
 *
 * @return Title for the field name.
 */
public static String nameToTitle(String aFieldName) {
    if (StringUtils.isNotEmpty(aFieldName)) {
        char curChar;
        boolean isLastSpace = true;
        boolean isLastLower = false;

        StringBuilder stringBuilder = new StringBuilder();
        int strLength = aFieldName.length();
        for (int i = 0; i < strLength; i++) {
            curChar = aFieldName.charAt(i);

            if ((curChar == StrUtl.CHAR_UNDERLINE) || (curChar == StrUtl.CHAR_DOT)) {
                curChar = StrUtl.CHAR_SPACE;
                stringBuilder.append(curChar);
            } else if (isLastSpace)
                stringBuilder.append(Character.toUpperCase(curChar));
            else if ((Character.isUpperCase(curChar)) && (isLastLower)) {
                stringBuilder.append(StrUtl.CHAR_SPACE);
                stringBuilder.append(curChar);
            } else
                stringBuilder.append(curChar);

            isLastSpace = (curChar == StrUtl.CHAR_SPACE);
            isLastLower = Character.isLowerCase(curChar);
        }

        return stringBuilder.toString();
    } else
        return aFieldName;
}

From source file:org.apache.openejb.util.classloader.URLClassLoaderFirst.java

public static boolean shouldSkip(final String name) {
    if (name == null) { // can happen with rest servlet definition or errors
        return false;
    }// ww  w  .  j a  v  a  2 s. com

    for (final String prefix : FORCED_SKIP) {
        if (name.startsWith(prefix)) {
            return true;
        }
    }
    for (final String prefix : FORCED_LOAD) {
        if (name.startsWith(prefix)) {
            return false;
        }
    }

    if (name.startsWith("java.")) {
        return true;
    }
    if (name.startsWith("javax.faces.")) {
        return false;
    }
    if (name.startsWith("javax.mail.")) {
        return false;
    }
    if (name.startsWith("javax.")) {
        return isInServer(name);
    }
    if (name.startsWith("sun.")) {
        return isInJvm(name);
    }

    // can be provided in the webapp
    if (name.startsWith("javax.servlet.jsp.jstl")) {
        return false;
    }

    if (name.startsWith("org.")) {
        final String org = name.substring("org.".length());

        if (org.startsWith("apache.")) {
            final String apache = org.substring("apache.".length());

            // the following block is classes which enrich webapp classloader
            if (apache.startsWith("webbeans.jsf")) {
                return false;
            }
            if (apache.startsWith("tomee.mojarra.")) {
                return false;
            }

            // here we find server classes
            if (apache.startsWith("bval.")) {
                return true;
            }
            if (apache.startsWith("openjpa.")) {
                return true;
            }
            if (apache.startsWith("xbean.")) {
                return !apache.substring("xbean.".length()).startsWith("spring");
            }
            if (apache.startsWith("geronimo.")) {
                return true;
            }
            if (apache.startsWith("coyote.")) {
                return true;
            }
            if (apache.startsWith("webbeans.")) {
                return true;
            }
            if (apache.startsWith("log4j.") && SKIP_LOG4J) {
                return true;
            }
            if (apache.startsWith("catalina.")) {
                return true;
            }
            if (apache.startsWith("jasper.")) {
                return true;
            }
            if (apache.startsWith("tomcat.")) {
                return true;
            }
            if (apache.startsWith("el.")) {
                return true;
            }
            // if (apache.startsWith("jsp")) return true; // precompiled jsp have to be loaded from the webapp
            if (apache.startsWith("naming.")) {
                return true;
            }
            if (apache.startsWith("taglibs.")) {
                return true;
            }

            if (apache.startsWith("openejb.")) { // skip all excepted webapp enrichment artifacts
                return !isWebAppEnrichment(apache.substring("openejb.".length()));
            }

            if (apache.startsWith("commons.")) {
                final String commons = apache.substring("commons.".length());

                // don't stop on commons package since we don't bring all commons
                if (commons.startsWith("beanutils.")) {
                    return isInServer(name);
                }
                if (commons.startsWith("cli.")) {
                    return true;
                }
                if (commons.startsWith("codec.")) {
                    return true;
                }
                if (commons.startsWith("collections.")) {
                    return true;
                }
                if (commons.startsWith("dbcp.")) {
                    return true;
                }
                if (commons.startsWith("digester.")) {
                    return true;
                }
                if (commons.startsWith("jocl.")) {
                    return true;
                }
                if (commons.startsWith("lang.")) { // openjpa
                    return true;
                }
                if (commons.startsWith("lang3.")) { // us
                    return true;
                }
                if (commons.startsWith("logging.")) {
                    return false;
                }
                if (commons.startsWith("pool.")) {
                    return true;
                }
                if (commons.startsWith("net.") && SKIP_COMMONS_NET) {
                    return true;
                }

                return false;
            }

            if (SKIP_MYFACES && apache.startsWith("myfaces.")) {
                // we bring only myfaces-impl (+api but that's javax)
                // mainly inspired from a comparison with tomahawk packages
                final String myfaces = name.substring("myfaces.".length());
                if (myfaces.startsWith("shared.")) {
                    return true;
                }
                if (myfaces.startsWith("ee6.")) {
                    return true;
                }
                if (myfaces.startsWith("lifecycle.")) {
                    return true;
                }
                if (myfaces.startsWith("context.")) {
                    return true;
                }
                if (myfaces.startsWith("logging.")) {
                    return true;
                }
                // tomahawk uses component.html package
                if (myfaces.startsWith("component.visit.")
                        || myfaces.equals("component.ComponentResourceContainer")) {
                    return true;
                }
                if (myfaces.startsWith("application.")) {
                    return true;
                }
                if (myfaces.startsWith("config.")) {
                    return true;
                }
                if (myfaces.startsWith("event.")) {
                    return true;
                }

                if (myfaces.startsWith("resource.")) {
                    return true;
                }
                if (myfaces.startsWith("el.")) {
                    return true;
                }
                if (myfaces.startsWith("spi.")) {
                    return true;
                }
                if (myfaces.startsWith("convert.")) {
                    return true;
                }
                if (myfaces.startsWith("debug.")) {
                    return true;
                }
                if (myfaces.startsWith("util.")) {
                    return true;
                }
                if (myfaces.startsWith("view.")) {
                    return true;
                }
                if (myfaces.equals("convert.ConverterUtils")) {
                    return true;
                }

                if (myfaces.startsWith("renderkit.")) {
                    final String renderkit = myfaces.substring("renderkit.".length());
                    if (renderkit.startsWith("html.Html")) {
                        return true;
                    }
                    final char firstNextletter = renderkit.charAt(0);
                    if (Character.isUpperCase(firstNextletter)) {
                        return true;
                    }
                    return false;
                }

                if (myfaces.startsWith("taglib.")) {
                    final String taglib = myfaces.substring("taglib.".length());
                    if (taglib.startsWith("html.Html")) {
                        return true;
                    }
                    if (taglib.startsWith("core.")) {
                        return true;
                    }
                    return false;
                }

                if (myfaces.startsWith("webapp.")) {
                    final String webapp = myfaces.substring("webapp.".length());
                    if (webapp.startsWith("Faces")) {
                        return true;
                    }
                    if (webapp.startsWith("Jsp")) {
                        return true;
                    }
                    if (webapp.startsWith("Startup")) {
                        return true;
                    }
                    if (webapp.equals("AbstractFacesInitializer")) {
                        return true;
                    }
                    if (webapp.equals("MyFacesServlet")) {
                        return true;
                    }
                    if (webapp.equals("ManagedBeanDestroyerListener")) {
                        return true;
                    }
                    if (webapp.equals("WebConfigParamsLogger")) {
                        return true;
                    }
                    return false;
                }

                return false;
            }

            if (apache.startsWith("activemq.")) {
                return SKIP_JMS && isInServer(name);
            }

            return false;
        }

        // other org packages
        if (org.startsWith("hsqldb.") && SKIP_HSQLDB) {
            return true;
        }
        if (org.startsWith("codehaus.swizzle.")) {
            final String swizzle = org.substring("codehaus.swizzle.".length());
            if (swizzle.startsWith("stream.")) {
                return true;
            }
            if (swizzle.startsWith("rss.")) {
                return true;
            }
            if (swizzle.startsWith("Grep.class") || swizzle.startsWith("Lexer.class")) {
                return true;
            }
            return false;
        }
        if (org.startsWith("w3c.dom.") || org.startsWith("xml.sax.")) {
            return isInJvm(name);
        }
        if (org.startsWith("eclipse.jdt.")) {
            return true;
        }

        // let an app use its own slf4j impl (so its own api too)
        // if (org.startsWith("slf4j")) return true;

        return false;
    }

    // other packages
    if (name.startsWith("com.sun.")) {
        return isInJvm(name);
    }
    if (name.startsWith("serp.bytecode.")) {
        return true;
    }

    return false;
}