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

/**
 * <p>Swaps the case of a String changing upper and title case to
 * lower case, and lower case to upper case.</p>
 *
 * <ul>//from w w  w. j  a v a 2s .  c om
 *  <li>Upper case character converts to Lower case</li>
 *  <li>Title case character converts to Lower case</li>
 *  <li>Lower case character converts to Upper case</li>
 * </ul>
 *
 * <p>For a word based algorithm, see {@link WordUtils#swapCase(String)}.
 * A <code>null</code> input String returns <code>null</code>.</p>
 *
 * <pre>
 * StringUtils.swapCase(null)                 = null
 * StringUtils.swapCase("")                   = ""
 * StringUtils.swapCase("The dog has a BONE") = "tHE DOG HAS A bone"
 * </pre>
 *
 * <p>NOTE: This method changed in Lang version 2.0.
 * It no longer performs a word based algorithm.
 * If you only use ASCII, you will notice no change.
 * That functionality is available in WordUtils.</p>
 *
 * @param str  the String to swap case, may be null
 * @return the changed String, <code>null</code> if null String input
 */
public static String swapCase(String str) {
    int strLen;
    if (str == null || (strLen = str.length()) == 0) {
        return str;
    }
    StringBuffer buffer = new StringBuffer(strLen);

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

From source file:com.adaptris.core.marshaller.xstream.XStreamUtils.java

/**
 * Converts a lowercase hyphen separated format into a camelcase based
 * format. Used by the unmarshalling process to convert an xml element into
 * a java class/field name.//from w w  w  .  j a va 2s.co  m
 * 
 * @param xmlElementName
 *            - Current element name to be processed.
 * @return translated name
 */
public static String toFieldName(String xmlElementName) {
    if (xmlElementName == null) {
        return null;
    }
    if (xmlElementName.length() == 0) {
        return xmlElementName;
    }
    if (xmlElementName.length() == 1) {
        return xmlElementName.toLowerCase();
    }
    // -- Follow the Java beans Introspector::decapitalize
    // -- convention by leaving alone String that start with
    // -- 2 uppercase characters.
    if (Character.isUpperCase(xmlElementName.charAt(0)) && Character.isUpperCase(xmlElementName.charAt(1))) {
        return xmlElementName;
    }
    // -- process each character
    StringBuilder input = new StringBuilder(xmlElementName);
    StringBuilder output = new StringBuilder();
    output.append(Character.toLowerCase(input.charAt(0)));
    boolean multiHyphens = false;
    for (int i = 1; i < input.length(); i++) {
        char ch = input.charAt(i);
        if (ch == '-') {
            if (input.charAt(++i) != '-') {
                output.append(Character.toUpperCase(input.charAt(i)));
            } else {
                multiHyphens = true;
            }
        } else {
            if (multiHyphens) {
                output.append(Character.toUpperCase(ch));
            } else {
                output.append(ch);
            }
            multiHyphens = false;

        }
    }
    return output.toString();
}

From source file:org.wiztools.commons.RotN.java

private static String process(final String inString,
        final Map<Character, Character> map) throws IllegalArgumentException {
    char[] arr = inString.toCharArray();
    StringBuilder sb = new StringBuilder(arr.length);
    for(char c: arr) {
        Character out = map.get(c);
        if(out == null) {
            sb.append(c);/*from w  w  w . ja  v  a 2s. c  o  m*/
        }
        else {
            if(Character.isUpperCase(c))
                sb.append(Character.toUpperCase(out));
            else
                sb.append(out);
        }
    }
    return sb.toString();
}

From source file:org.hippoecm.frontend.util.PluginConfigMapper.java

private static String toConfigKey(String camelKey) {
    StringBuilder b = new StringBuilder(camelKey.length() + 4);
    for (char ch : camelKey.toCharArray()) {
        if (Character.isUpperCase(ch)) {
            b.append('.').append(Character.toLowerCase(ch));
        } else {/*ww w.jav  a2s  .  co m*/
            b.append(ch);
        }
    }
    return b.toString();
}

From source file:com.acuityph.commons.util.ClassUtils.java

/**
 * @param methodName/*from   ww  w .j  a  v a 2 s  .c  om*/
 *        the method name to check
 * @return true if the given method name matches a property accessor (getter or setter) pattern
 */
private static boolean isPropertyAccessorName(final String methodName) {
    return hasLength(methodName) && methodName.length() > 3
            && (methodName.startsWith("set") || methodName.startsWith("get"))
            && Character.isUpperCase(methodName.charAt(3));
}

From source file:com.github.jdot.type.Property.java

/**
 * Returns new BeanProperty instance if the specified element is a JavaBean accessor method, otherwise null.
 * /*from w  ww .  j  a  v a 2 s.c om*/
 * @param element
 * @return
 */
public static Property build(Type owner, ExecutableElement element) {
    Property beanProperty = null;
    String name = null;
    boolean propertyFound = true;
    boolean writeable = false;
    String type = null;

    // Check modifiers
    boolean publicFound = false;
    boolean staticFound = false;
    for (Modifier modifier : element.getModifiers()) {
        if (Modifier.PUBLIC.equals(modifier)) {
            publicFound = true;
        }
        if (Modifier.STATIC.equals(modifier)) {
            staticFound = true;
        }
    }
    if (!publicFound || staticFound) {
        propertyFound = false;
    }

    // Check method name
    if (propertyFound) {
        String methodName = element.getSimpleName().toString();
        if (methodName.startsWith("set") && Character.isUpperCase(methodName.charAt(3))) {
            name = StringUtils.uncapitalize(methodName.substring(3));
            writeable = true;
        } else if (methodName.startsWith("get") && Character.isUpperCase(methodName.charAt(3))) {
            name = StringUtils.uncapitalize(methodName.substring(3));
        } else if (methodName.startsWith("is") && Character.isUpperCase(methodName.charAt(2))) {
            name = StringUtils.uncapitalize(methodName.substring(2));
        } else {
            propertyFound = false;
        }
    }

    // Check arguments / return type
    if (propertyFound) {
        if (writeable) {
            if (element.getParameters().size() == 1
                    && TypeKind.VOID.equals(element.getReturnType().getKind())) {
                type = element.getParameters().get(0).asType().toString();
            } else {
                propertyFound = false;
            }
        } else {
            if (TypeKind.VOID.equals(element.getReturnType().getKind())) {
                propertyFound = false;
            } else {
                type = element.getReturnType().toString();
            }
        }
    }

    if (propertyFound) {
        beanProperty = new Property(owner, element, name, type, writeable);
    }
    return beanProperty;
}

From source file:com.technion.studybuddy.GCM.ServerUtilities.java

private static String capitalize(String s) {
    if (s == null || s.length() == 0)
        return "";
    char first = s.charAt(0);
    if (Character.isUpperCase(first))
        return s;
    else/*  w  ww. ja v  a  2 s.c  om*/
        return Character.toUpperCase(first) + s.substring(1);
}

From source file:org.lendingclub.mercator.aws.JsonConverter.java

private String getKey(String key) {
    if (Character.isUpperCase(key.charAt(0))) {
        return Character.toLowerCase(key.charAt(0)) + key.substring(1);
    }//from w ww.jav a 2 s .  co  m
    return key;
}

From source file:org.paxml.bean.SplitTag.java

public static void splitByCapital(String str, List<String> result) {
    int start = 0;
    for (int i = 0; i < str.length(); i++) {

        Character c = str.charAt(i);
        if (Character.isUpperCase(c)) {
            // if the next char is lowercased, end the previous word
            if ((i - 1 >= 0 && !Character.isUpperCase(str.charAt(i - 1)))
                    || (i + 1 < str.length() && searchLowercase(str, i + 1) > 0)) {
                String word = str.substring(start, i);
                if (StringUtils.isNotBlank(word)) {
                    result.add(word);/*from   ww  w.  j ava  2s. co  m*/
                }
                start = i;
            } else {

            }
        }
    }
    String last = str.substring(start, str.length());
    if (StringUtils.isNotBlank(last)) {
        result.add(last);
    }
}

From source file:de.micromata.genome.gwiki.plugin.wikilink_1_0.GWikiWikiLinkFragment.java

public static boolean isWikiLinkWord(String text) {
    if (StringUtils.isBlank(text) == true) {
        return false;
    }//  ww  w  .j  a v  a  2  s. c o m
    if (text.length() < 4) {
        return false;
    }
    boolean lastUpperCase = true;
    int uccount = 1;
    for (int i = 1; i < text.length(); ++i) {
        char c = text.charAt(i);
        boolean uc = Character.isUpperCase(c);
        if (uc == true && lastUpperCase == true) {
            return false;
        }
        uccount += (uc ? 1 : 0);
        lastUpperCase = uc;
    }
    if (uccount > 1) {
        return true;
    } else {
        return false;
    }
}