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

/**
 * Compiles the given regular expression into a Pattern that may or may not be case-sensitive, depending on the regular expression.
 * If the regular expression contains any capital letter, that is assumed to be meaningful, and the resulting Pattern is case-sensitive.
 * If the whole regular expression is lower-case, the resulting Pattern is case-insensitive.
 * /*w  w w.j  a  v a  2s . c om*/
 * This is useful for implementing functionality like emacs/vim's "smart case", hence the name.
 * 
 * By default, we enable (?m) on the assumption that it's more useful if ^ and $ match the start and end of each line rather than just the start and end of input.
 */
public static Pattern smartCaseCompile(String regularExpression) {
    boolean caseInsensitive = true;
    for (int i = 0; i < regularExpression.length(); ++i) {
        if (Character.isUpperCase(regularExpression.charAt(i))) {
            caseInsensitive = false;
        }
    }
    int flags = Pattern.MULTILINE;
    if (caseInsensitive) {
        flags |= Pattern.CASE_INSENSITIVE;
    }
    return Pattern.compile(regularExpression, flags);
}

From source file:Main.java

/**
 * Removes invalid char from element names.
 *//*from  w  w  w.j  a va2 s . co  m*/
public static String asElementName(String x) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < x.length(); ++i) {
        char c = x.charAt(i);
        if (Character.isUpperCase(c) || Character.isLowerCase(c) || Character.isDigit(c) || c == '-'
                || c == '_') {
            sb.append(c);
        }
    }
    String elementName = sb.toString();
    if (elementName.length() == 0 || (!Character.isUpperCase(elementName.charAt(0))
            && !Character.isLowerCase(elementName.charAt(0)))) {
        return "e" + elementName;
    }
    return elementName;
}

From source file:Main.java

public static String toXmlName(String s) {
    s = removePrefix(s);//w ww  .j a  v  a  2  s. c o  m
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (i != 0 && Character.isUpperCase(c)) {
            sb.append("-");
        }
        sb.append(Character.toLowerCase(c));
    }
    return sb.toString();
}

From source file:StringUtil.java

public static String uncaps(String string) {
    if (string.length() == 0) {
        return string;
    }//from   www .  ja  va2 s  . c om
    char ch = string.charAt(0);
    if (Character.isUpperCase(ch)) {
        ch = Character.toLowerCase(ch);
        return ch + string.substring(1);
    }
    return string;
}

From source file:Main.java

/**
 * Take the input string and un-camel-case it.
 * <p/>/*from   w  w  w  . ja  v  a 2  s.c  om*/
 * 'ThisIsIt' will become 'this-is-it'.
 *
 * @param input
 * @return deHumped string
 */
public static String addAndDeHump(String input) {
    StringBuilder sb = new StringBuilder();

    for (int i = 0; i < input.length(); i++) {
        if ((i != 0) && Character.isUpperCase(input.charAt(i))) {
            sb.append('-');
        }

        sb.append(input.charAt(i));
    }

    return sb.toString().trim().toLowerCase(Locale.ENGLISH);
}

From source file:Main.java

public static String toConstantFormat(String str) {
    int n = str.length();
    List<Character> list = new ArrayList<Character>();
    char c;//  w  w  w  .j a  va2 s.co  m
    for (int i = 0; i < n; i++) {
        c = str.charAt(i);
        if (i != 0 && Character.isUpperCase(c)) {
            list.add('_');
        }
        list.add(Character.toUpperCase(c));
    }

    StringBuffer buffer = new StringBuffer();
    for (Character character : list) {
        buffer.append(character);
    }
    return buffer.toString();

}

From source file:Main.java

public static Map<String, Object> getProperties(Object object, boolean includeSuperClasses, boolean deepCopy) {
    HashMap<String, Object> map = new HashMap<String, Object>();
    if (object == null) {
        return map;
    }//from  w  w  w  .  ja va2 s.c  o m

    Class<?> objectClass = object.getClass();
    Method[] methods = includeSuperClasses ? objectClass.getMethods() : objectClass.getDeclaredMethods();
    for (Method method : methods) {
        if (method.getParameterTypes().length == 0 && !method.getReturnType().equals(Void.TYPE)) {
            String methodName = method.getName();
            String propertyName = "";
            if (methodName.startsWith("get")) {
                propertyName = methodName.substring(3);
            } else if (methodName.startsWith("is")) {
                propertyName = methodName.substring(2);
            }
            if (propertyName.length() > 0 && Character.isUpperCase(propertyName.charAt(0))) {
                propertyName = Character.toLowerCase(propertyName.charAt(0)) + propertyName.substring(1);

                Object value = null;
                try {
                    value = method.invoke(object);
                } catch (Exception e) {
                }

                Object value2 = value;

                if (!deepCopy) {
                    map.put(propertyName, value);
                } else {
                    if (isSimpleObject(value)) {
                        map.put(propertyName, value);
                    } else if (value instanceof Map) {
                        Map<String, Object> submap = new HashMap<String, Object>();
                        for (Map.Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) {
                            submap.put(String.valueOf(entry.getKey()),
                                    convertObject(entry.getValue(), includeSuperClasses));
                        }
                        map.put(propertyName, submap);
                    } else if (value instanceof Iterable) {
                        List<Object> sublist = new ArrayList<Object>();
                        for (Object v : (Iterable<?>) object) {
                            sublist.add(convertObject(v, includeSuperClasses));
                        }
                        map.put(propertyName, sublist);
                    } else if (value.getClass().isArray()) {
                        List<Object> sublist = new ArrayList<Object>();
                        int length = Array.getLength(value);
                        for (int i = 0; i < length; i++) {
                            sublist.add(convertObject(Array.get(value, i), includeSuperClasses));
                        }
                        map.put(propertyName, sublist);
                    } else {
                        map.put(propertyName, getProperties(value, includeSuperClasses, deepCopy));
                    }
                }
            }
        }
    }

    return map;
}

From source file:org.netbeans.jcode.core.util.StringHelper.java

public static String firstLower(String string) {
    boolean makeFirstLower = string.length() < 2 || (!Character.isUpperCase(string.charAt(1)));
    return makeFirstLower ? string.substring(0, 1).toLowerCase() + string.substring(1) : string;
}

From source file:com.nortal.petit.beanmapper.BeanMappingStringUtils.java

/**
 * Transforms the given camel case string into it's underscore
 * representation. Example: someString -&gt; some_string.
 * // w w  w.j a v  a  2  s. com
 * @param camelCase
 *            string in camel case.
 * @return string in underscore representation.
 */
public static String camelCaseToUnderscore(String camelCase) {
    if (StringUtils.isBlank(camelCase)) {
        return camelCase;
    }

    StringBuilder sb = new StringBuilder();

    for (Character c : camelCase.toCharArray()) {
        if (Character.isUpperCase(c)) {
            c = Character.toLowerCase(c);
            if (sb.length() > 0) {
                sb.append("_");
            }
        }

        sb.append(c);
    }

    return sb.toString();
}

From source file:Main.java

/**
 * Translates a Java file name to a XML file name according
 * to Android naming convention.//from  w  w  w. ja v  a2  s.  c o m
 *
 * Doesn't append .xml extension
 *
 * @return XML file name associated with Java file name
 */
public static String getXmlFileNameFromJavaFileName(String javaFileName) {

    if (javaFileName.endsWith(".java")) {
        // cut off ".java"
        javaFileName = javaFileName.substring(0, javaFileName.length() - 5);
    }

    char[] charsJava = javaFileName.toCharArray();
    StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i < charsJava.length; i++) {
        char currentChar = charsJava[i];
        if (Character.isUpperCase(currentChar) && i != 0) {
            stringBuilder.append('_');
        }
        stringBuilder.append(Character.toLowerCase(currentChar));
    }
    return stringBuilder.toString();
}