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.easyjf.util.StringUtils.java

private static String changeFirstCharacterCase(String str, boolean capitalize) {
    if (str == null || str.length() == 0)
        return str;
    StringBuffer buf = new StringBuffer(str.length());
    if (capitalize)
        buf.append(Character.toUpperCase(str.charAt(0)));
    else// w  ww. jav  a  2s  .  com
        buf.append(Character.toLowerCase(str.charAt(0)));
    buf.append(str.substring(1));
    return buf.toString();
}

From source file:com.redhat.rhn.common.util.StringUtil.java

/**
 * Converts the passed in string to a valid java Class name. This basically
 * capitalizes each word and removes all word delimiters.
 * @param strIn The string to convert.//from   w w  w.  ja v  a2 s .com
 * @return The converted string.
 */
public static String classify(String strIn) {
    String str = strIn.trim();
    StringBuilder result = new StringBuilder(str.length());
    boolean wasWhitespace = false;

    for (int i = 0, j = 0; i < str.length(); i++) {
        char c = str.charAt(i);
        if (Character.isLetterOrDigit(c)) {
            if (i == 0) {
                c = Character.toUpperCase(c);
            }
            if (wasWhitespace) {
                c = Character.toUpperCase(c);
                wasWhitespace = false;
            }
            result.insert(j, c);
            j++;
            continue;
        }
        wasWhitespace = true;
    }
    return result.toString();
}

From source file:nz.co.senanque.validationengine.ValidationUtils.java

private static String figureIsGetter(final String name) {
    return name == null ? null : "is" + Character.toUpperCase(name.charAt(0)) + name.substring(1);
}

From source file:com.wavemaker.commons.util.StringUtils.java

/**
 * Converts the given snake case string to Java Field name.
 *
 * eg://  w  ww . j a  v a2  s.  co m
 * User -> user
 * User_id -> userId
 * user_id -> userId
 * USER_ID -> userId
 *
 * @param inputString string to convert
 * @return java field identifier
 */
public static String toFieldName(String inputString) {
    if (inputString == null || inputString.isEmpty()) {
        return inputString;
    }

    String result = "";
    char firstChar = inputString.charAt(0);
    char firstCharToUpperCase = Character.toLowerCase(firstChar);
    result += firstCharToUpperCase;
    for (int i = 1; i < inputString.length(); i++) {
        char currentChar = inputString.charAt(i);
        if (currentChar != '_') {
            char previousChar = inputString.charAt(i - 1);
            if (previousChar == '_') {
                char currentCharToUpperCase = Character.toUpperCase(currentChar);
                result += currentCharToUpperCase;
            } else {
                char currentCharToLowerCase = Character.toLowerCase(currentChar);
                result += currentCharToLowerCase;
            }
        }
    }
    return result;
}

From source file:net.duckling.ddl.web.controller.task.TaskBaseController.java

/**
 * ?JSONJSON? users:[{ id: a ??? value:[{ id:
 * abc@cnic.cn (UID) name: ?? },......] },.... ]
 * /*  ww  w .  j  ava2s  .  c om*/
 * @param list
 *            SimpleUser
 * @return
 */
private JSONObject getAlphabetJSONFromSortedPinyin(List<SimpleUser> list) {
    JSONArray array = new JSONArray();
    if (null == list || list.isEmpty()) {
        return new JSONObject();
    }

    Map<Character, JSONArray> map = new TreeMap<Character, JSONArray>();
    for (SimpleUser user : list) {
        Character c = null;
        if (StringUtils.isEmpty(user.getPinyin())) {
            c = user.getUid().charAt(0);
        } else {
            c = user.getPinyin().charAt(0);
        }
        c = Character.toUpperCase(c);
        JSONArray child = map.get(c);
        if (child == null) {
            child = new JSONArray();
            map.put(c, child);
        }
        child.add(getJSONFromSimpleUser(user));
    }

    for (Entry<Character, JSONArray> entry : map.entrySet()) {
        add2Array(array, entry.getValue(), entry.getKey());
    }
    JSONObject obj = new JSONObject();
    obj.put("users", array);
    return obj;
}

From source file:hu.javaforum.commons.ReflectionHelper.java

/**
 * Returns the getter method of the field. It is recursive method.
 *
 * @param instanceClass The bean class/*from  w  ww.j a v  a 2  s  .co m*/
 * @param instance The bean instance
 * @param fieldName The field name
 * @return The getter method, if it is exists
 * null, if the getter method is not exists
 */
protected static Method getGetterMethod(final Class instanceClass, final Object instance,
        final String fieldName) {
    if ("java.lang.Object".equals(instanceClass.getName())) {
        return null;
    }

    try {
        StringBuilder sb = new StringBuilder(fieldName.length() + GET_WORD.length());
        sb.append(GET_WORD);
        sb.append(fieldName);
        sb.setCharAt(GET_WORD.length(), Character.toUpperCase(sb.charAt(GET_WORD.length())));
        return instanceClass.getDeclaredMethod(sb.toString());
    } catch (NoSuchMethodException except) {
        return getGetterMethod(instanceClass.getSuperclass(), instance, fieldName);
    }
}

From source file:de.pawlidi.openaletheia.utils.AletheiaUtils.java

/**
 * /*from   w ww  .  j  av a  2 s.c  o m*/
 * @param macAddress
 * @return
 */
public static String normalizeMacAddress(String macAddress) {
    if (StringUtils.isNotBlank(macAddress)) {
        if (isMacAddressCandidate(macAddress)) {
            macAddress = macAddress.trim();
            StringBuilder addressBuilder = new StringBuilder();
            for (int i = 0; i < macAddress.length(); i++) {
                char part = macAddress.charAt(i);
                addressBuilder.append(Character.toUpperCase(part));
                if (i % 2 == 0) {
                    addressBuilder.append("-");
                }
            }
            macAddress = addressBuilder.toString();
        }
    }
    return macAddress;
}

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

/**
 *
 * @param input/*from  w ww .j a v  a2 s. co  m*/
 * @return
 * @example
 *
 * BankAccount => BANK_ACCOUNT Bank_Account => BANK_ACCOUNT
 */
public static String toConstant(String input) {
    String constant = EMPTY;
    Character lastChar = null;
    for (Character curChar : input.toCharArray()) {
        if (lastChar == null) {
            // First character
            lastChar = Character.toUpperCase(curChar);
            constant = constant + lastChar;

        } else {
            if (Character.isLowerCase(lastChar)
                    && (Character.isUpperCase(curChar) || Character.isDigit(curChar))) {
                constant = constant + '_' + curChar;
            } else {
                constant = constant + Character.toUpperCase(curChar);
            }
            lastChar = curChar;
        }

    }
    return constant;
}

From source file:hu.javaforum.util.internal.ReflectionHelper.java

/**
 * Returns the getter method of the field. It is recursive method.
 *
 * @param instanceClass The bean class/*from   w w  w  .  j  a v  a 2 s. c om*/
 * @param instance The bean instance
 * @param fieldName The field name
 * @return The getter method, if it is exists
 * null, if the getter method is not exists
 */
protected static Method getGetterMethod(final Class instanceClass, final Object instance,
        final String fieldName) {
    PerfLogger logger = new PerfLogger(LOGGER);

    if ("java.lang.Object".equals(instanceClass.getName())) {
        return null;
    }

    try {
        StringBuilder sb = new StringBuilder(fieldName.length() + GET_WORD.length());
        sb.append(GET_WORD);
        sb.append(fieldName);
        sb.setCharAt(GET_WORD.length(), Character.toUpperCase(sb.charAt(GET_WORD.length())));
        return instanceClass.getDeclaredMethod(sb.toString());
    } catch (NoSuchMethodException except) {
        logger.debug("Invoking %1$s.%2$s() because %3$s", instanceClass.getSuperclass().getName(), fieldName,
                except.getMessage());
        return getGetterMethod(instanceClass.getSuperclass(), instance, fieldName);
    }
}

From source file:ca.uhn.hl7v2.sourcegen.SourceGenerator.java

/** Capitalizes first character of the given text. */
private static String capitalize(String text) {
    StringBuffer cap = new StringBuffer();
    if (text.length() > 0) {
        cap.append(Character.toUpperCase(text.charAt(0)));
        cap.append(text.substring(1, text.length()));
    }//from   ww  w .ja  v  a  2 s .  c om
    return cap.toString();
}