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:Main.java

/**
 * Utility method to take a string and convert it to normal Java variable name capitalization. This normally means converting the first character from upper case to lower case, but in the (unusual) special case when there is more than one character and both the first and second characters are upper case, we leave it alone.
 * <p>/*  www .j  ava 2 s .co m*/
 * Thus "FooBah" becomes "fooBah" and "X" becomes "x", but "URL" stays as "URL".
 * 
 * @param name
 *          The string to be decapitalized.
 * @return The decapitalized version of the string.
 */
public static String decapitalize(String name) {
    if (name == null || name.length() == 0) {
        return name;
    }
    if (name.length() > 1 && Character.isUpperCase(name.charAt(1)) && Character.isUpperCase(name.charAt(0))) {
        return name;
    }
    char chars[] = name.toCharArray();
    chars[0] = Character.toLowerCase(chars[0]);
    return new String(chars);
}

From source file:StringUtils.java

private static int getCharKind(int c) {
    if (c == -1) {
        return EOI;
    }/*  w w  w.  j a v  a2  s. c o  m*/

    char ch = (char) c;

    if (Character.isLowerCase(ch))
        return LOWER;
    else if (Character.isUpperCase(ch))
        return UPPER;
    else if (Character.isDigit(ch))
        return DIGIT;
    else
        return OTHER;
}

From source file:org.luwrain.extensions.mssapi.SSML.java

/** convert text to ssml xml with upper pitch control for each upper case char
 * @param pitch pitch increase in % */
public static String upperCasePitchControl(String text, int pitch) {
    String xml = StringEscapeUtils.escapeXml11(text);
    StringBuilder sb = new StringBuilder(xml.length());
    sb.append(//ww  w. ja  v a 2  s . c  o m
            "<?xml version='1.0' encoding='utf-8'?><speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='ru-RU'><prosody pitch='+0%'>");
    StringBuilder sbul = new StringBuilder(xml.length());
    Boolean lasupper = null;
    for (char c : xml.toCharArray()) {
        if (lasupper == null)
            lasupper = Character.isUpperCase(c);
        if (lasupper != Character.isUpperCase(c)) {
            if (lasupper) {
                sb.append("<prosody pitch='");
                sb.append(String.format("%+d", pitch));
                sb.append("%'>");
                sb.append(sbul);
                sb.append("</prosody>");
            } else {
                sb.append(sbul);
            }
            sbul.delete(0, sbul.length());
        }
        lasupper = Character.isUpperCase(c);
        sbul.append(c);
    }
    if (lasupper) {
        sb.append("<prosody pitch='");
        sb.append(String.format("%+d", pitch));
        sb.append("%'>");
        sb.append(sbul);
        sb.append("</prosody>");
    } else {
        sb.append(sbul);
    }
    sb.append("</prosody></speak>");
    return sb.toString();
}

From source file:io.github.jeddict.jcode.util.StringHelper.java

public static String firstLower(String string) {
    if (isBlank(string)) {
        return EMPTY;
    }/*  w w w. j a  v a 2 s.c o m*/
    boolean makeFirstLower = string.length() < 2 || (!Character.isUpperCase(string.charAt(1)));
    return makeFirstLower ? string.substring(0, 1).toLowerCase() + string.substring(1) : string;
}

From source file:Strings.java

/**
 * Returns <code>true</code> if the first character in the
 * specified array is an upper case letter and all subsequent
 * characters are lower case letters./*from w ww.  j  av a  2  s .co  m*/
 *
 * @param chars Array of characters to test.
 * @return <code>true</code> if all of the characters in the
 * specified array are lower case letters.
 */
public static boolean capitalized(char[] chars) {
    if (chars.length == 0)
        return false;
    if (!Character.isUpperCase(chars[0]))
        return false;
    for (int i = 1; i < chars.length; ++i)
        if (!Character.isLowerCase(chars[i]))
            return false;
    return true;
}

From source file:org.eclipse.vorto.codegen.examples.webdevicegenerator.tasks.templates.WordSeperator.java

/**
 * Seperate camel style string into words e.g. "isOn"can to separated into
 * "Is On"//from   w  w  w  . ja v a 2  s  .co  m
 * 
 * @param camelString
 * @return
 */
public static String splitIntoWords(String camelString) {
    if (camelString == null || camelString.length() == 0) {
        return camelString;
    }

    StringUtils.trim(camelString);

    char[] characters = camelString.toCharArray();
    String resultWords = "";

    for (int i = 0; i < characters.length; i++) {
        if (i == 0) {
            resultWords = String.valueOf(Character.toUpperCase(characters[0]));
        } else {
            if (Character.isUpperCase(characters[i])) {
                resultWords += " ";
            }
            resultWords += characters[i];
        }
    }
    return resultWords;
}

From source file:Main.java

static Map<String, Method> getGetPropertyMethods(Class<?> beanClass) {
    HashMap<String, Method> props;
    if (getPropsCache.containsKey(beanClass)) {
        props = getPropsCache.get(beanClass);
    } else {//from  w w  w .  j a  v a2 s. com
        props = new HashMap<String, Method>();
        getPropsCache.put(beanClass, props);
        Method[] ms = beanClass.getMethods();
        for (int i = 0; i < ms.length; i++) {
            Method m = ms[i];
            String name = m.getName();
            if (name.startsWith("get") && name.length() > 3 && Character.isUpperCase(name.charAt(3))) {
                name = name.substring(3);
                props.put(name, m);
            }
        }
    }
    return props;
}

From source file:Main.java

static Map<String, Method> getSetPropertyMethods(Class<?> beanClass) {
    HashMap<String, Method> props;
    if (setPropsCache.containsKey(beanClass)) {
        props = setPropsCache.get(beanClass);
    } else {//from   w w  w. j  a  va  2s  . c  o  m
        props = new HashMap<String, Method>();
        setPropsCache.put(beanClass, props);
        Method[] ms = beanClass.getMethods();
        for (int i = 0; i < ms.length; i++) {
            Method m = ms[i];
            String name = m.getName();
            if (name.startsWith("set") && name.length() > 3 && Character.isUpperCase(name.charAt(3))
                    && m.getParameterTypes().length == 1) {
                name = name.substring(3);
                props.put(name, m);
            }
        }
    }
    return props;
}

From source file:Main.java

public String getSymbol(String currencyCode, Locale locale) {
    if (currencyCode == null || locale == null)
        throw new NullPointerException();

    if (currencyCode.length() != 3)
        throw new IllegalArgumentException("currency code length not 3");

    for (int i = 0; i < 3; i++)
        if (!Character.isUpperCase(currencyCode.charAt(i)))
            throw new IllegalArgumentException("bad currency code");

    if (!locale.equals(locales[0]))
        throw new IllegalArgumentException("unsupported locale");

    if (currencyCode.equals("ERN"))
        return "Nfk";
    else//from   w  w  w. j a  v a2 s . com
        return null;
}

From source file:Main.java

/**
 * <p>/*from ww w.j av  a 2 s  .c  o m*/
 * Swaps the case of String.
 * </p>
 * <p/>
 * <p>
 * Properly looks after making sure the start of words are Titlecase and not Uppercase.
 * </p>
 * <p/>
 * <p>
 * <code>null</code> is returned as <code>null</code>.
 * </p>
 *
 * @param str the String to swap the case of
 * @return the modified String
 */
public static String swapCase(String str) {
    if (str == null) {
        return null;
    }
    int sz = str.length();
    StringBuilder buffer = new StringBuilder(sz);

    boolean whitespace = false;
    char ch;
    char tmp;

    for (int i = 0; i < sz; i++) {
        ch = str.charAt(i);
        if (Character.isUpperCase(ch)) {
            tmp = Character.toLowerCase(ch);
        } else if (Character.isTitleCase(ch)) {
            tmp = Character.toLowerCase(ch);
        } else if (Character.isLowerCase(ch)) {
            if (whitespace) {
                tmp = Character.toTitleCase(ch);
            } else {
                tmp = Character.toUpperCase(ch);
            }
        } else {
            tmp = ch;
        }
        buffer.append(tmp);
        whitespace = Character.isWhitespace(ch);
    }
    return buffer.toString();
}