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:edu.duke.cabig.c3pr.utils.StringUtils.java

public static String camelCase(String inputString) {

    String camelCaseStr = "";

    if (inputString == null)
        return camelCaseStr;

    String lowerCase = inputString.toLowerCase();

    StringTokenizer strTokenizer = new StringTokenizer(lowerCase, " ");
    String strToken = "";
    StringBuffer strBuf = null;/*from   w  ww  .  ja  v  a  2  s .co  m*/
    char[] charAry = null;

    while (strTokenizer.hasMoreTokens()) {
        strBuf = new StringBuffer();
        strToken = strTokenizer.nextToken();
        charAry = strToken.toCharArray();
        strBuf.append(Character.toUpperCase(charAry[0]));
        int remaingstrLength = charAry.length - 1;
        strBuf.append(charAry, 1, remaingstrLength);
        camelCaseStr = camelCaseStr + " " + strBuf.toString();
    }
    return camelCaseStr;

}

From source file:Main.java

private static String urlencode(final String content, final Charset charset, final BitSet safechars,
        final boolean blankAsPlus) {
    if (content == null) {
        return null;
    }/*from  ww w  .  j  av  a  2 s  . c  om*/
    StringBuilder buf = new StringBuilder();
    ByteBuffer bb = charset.encode(content);
    while (bb.hasRemaining()) {
        int b = bb.get() & 0xff;
        if (safechars.get(b)) {
            buf.append((char) b);
        } else if (blankAsPlus && b == ' ') {
            buf.append('+');
        } else {
            buf.append("%");
            char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, RADIX));
            char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, RADIX));
            buf.append(hex1);
            buf.append(hex2);
        }
    }
    return buf.toString();
}

From source file:de.micromata.genome.util.bean.PrivateBeanUtils.java

/**
 * Gets the getter from field name.// w w w.jav a2s .c  om
 *
 * @param fieldName the field name
 * @param prefix the prefix
 * @return the getter from field name
 */
public static String getGetterOrSetterMethodNameFromFieldName(String fieldName, String prefix) {
    char fl = Character.toUpperCase(fieldName.charAt(0));
    String getter = prefix + fl;

    if (fieldName.length() < 2) {
        return getter;
    }
    return getter + fieldName.substring(1);
}

From source file:com.towerlabs.yildizyemek.JSonProcess.java

public String[] toUpperCaseWords(String[] texts) {

    boolean isSpecialChar;
    char[] charsStr;

    for (int i = 0; i < texts.length; i++) {

        isSpecialChar = false;//from   w  ww. j  a va 2 s. com
        charsStr = texts[i].toLowerCase(Locale.getDefault()).toCharArray();

        for (int j = 0; j < charsStr.length; j++) {

            if (Character.isLetter(charsStr[j])) {
                if (!isSpecialChar) {
                    charsStr[j] = Character.toUpperCase(charsStr[j]);
                }
                isSpecialChar = true;
            } else {
                isSpecialChar = false;
            }
        }

        texts[i] = new String(charsStr);

    }

    return texts;
}

From source file:com.github.dozermapper.protobuf.util.ProtoUtils.java

/**
 * Gets the field value from the {@link Message}, which matches the fieldName,
 * either with an exact match, or after applying a transformation to camel-case.
 * <p>//from  ww w. j  a v a2 s  .com
 * Returns null if there is no match.
 *
 * @param message   {@link Message} instance
 * @param fieldName fieldName to find
 * @return field value from the {@link Message} for the specified field name, or null if none found
 */
public static Object getFieldValue(Object message, String fieldName) {
    Object answer = null;

    Map<Descriptors.FieldDescriptor, Object> fieldsMap = ((Message) message).getAllFields();
    for (Map.Entry<Descriptors.FieldDescriptor, Object> field : fieldsMap.entrySet()) {
        if (sameField(fieldName, field.getKey().getName())) {
            if (field.getKey().isMapField()) {
                // Capitalize the first letter of the string;
                String propertyName = Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1);
                String methodName = String.format("get%sMap", propertyName);

                try {
                    Method mapGetter = message.getClass().getMethod(methodName);
                    answer = mapGetter.invoke(message);
                    break;
                } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
                    throw new MappingException("Could not introspect map field with method " + methodName, e);
                }
            } else {
                answer = field.getValue();
                break;
            }
        }
    }

    return answer;
}

From source file:com.android.dialer.omni.clients.OsmApi.java

/**
 * Fetches and returns a list of named Places around the provided latitude and
 * longitude parameters. The bounding box is calculated from lat-distance, lon-distance
 * to lat+distance, lon+distance.//w w  w.j  av a  2  s.c o m
 * This method is NOT asynchronous. Run it in a thread.
 *
 * @param name Name to search
 * @param lat Latitude of the point to search around
 * @param lon Longitude of the point to search around
 * @param distance Max distance (polar coordinates)
 * @return the list of matching places
 */
@Override
public List<Place> getNamedPlacesAround(String name, double lat, double lon, double distance) {
    List<Place> places;

    if (DEBUG)
        Log.d(TAG, "Getting places named " + name);

    double latStart = lat - distance / 2.0;
    double latEnd = lat + distance / 2.0;
    double lonStart = lon - distance / 2.0;
    double lonEnd = lon + distance / 2.0;

    // The OSM API doesn't support case-insentive searches, but does support RegEx. So
    // we hack around a bit.
    String finalName = "";
    for (int i = 0; i < name.length(); i++) {
        char c = name.charAt(i);
        finalName = finalName + "[" + Character.toUpperCase(c) + Character.toLowerCase(c) + "]";
    }

    // Build request data
    String request = "[out:json];node[\"name\"~\"" + finalName + "\"][\"phone\"]" + "(" + latStart + ","
            + lonStart + "," + latEnd + "," + lonEnd + ");out body;";

    try {
        places = getPlaces(request);
    } catch (Exception e) {
        Log.e(TAG, "Unable to get named places around", e);
        places = new ArrayList<Place>();
    }

    if (DEBUG)
        Log.d(TAG, "Returning " + places.size() + " places");

    return places;
}

From source file:com.googlesource.gerrit.plugins.hooks.rtc.network.RTCHttpParams.java

private String getParamName(String name) {
    StringBuilder camelisedName = new StringBuilder();
    for (String namePart : name.split("[\\.-]")) {
        if (camelisedName.length() > 0) {
            camelisedName.append(Character.toUpperCase(namePart.charAt(0)));
            camelisedName.append(namePart.substring(1, namePart.length()));
        } else {// w w  w  . j  av  a2 s .  c o  m
            camelisedName.append(namePart);
        }
    }
    return camelisedName.toString();
}

From source file:Main.java

/**
 * Returns the length of the filename prefix, such as <code>C:/</code> or <code>~/</code>.
 * <p>/*from   www .jav a2s.  co  m*/
 * This method will handle a file in either Unix or Windows format.
 * <p>
 * The prefix length includes the first slash in the full filename
 * if applicable. Thus, it is possible that the length returned is greater
 * than the length of the input string.
 * <pre>
 * Windows:
 * a\b\c.txt           --> ""          --> relative
 * \a\b\c.txt          --> "\"         --> current drive absolute
 * C:a\b\c.txt         --> "C:"        --> drive relative
 * C:\a\b\c.txt        --> "C:\"       --> absolute
 * \\server\a\b\c.txt  --> "\\server\" --> UNC
 *
 * Unix:
 * a/b/c.txt           --> ""          --> relative
 * /a/b/c.txt          --> "/"         --> absolute
 * ~/a/b/c.txt         --> "~/"        --> current user
 * ~                   --> "~/"        --> current user (slash added)
 * ~user/a/b/c.txt     --> "~user/"    --> named user
 * ~user               --> "~user/"    --> named user (slash added)
 * </pre>
 * <p>
 * The output will be the same irrespective of the machine that the code is running on.
 * ie. both Unix and Windows prefixes are matched regardless.
 *
 * @param filename  the filename to find the prefix in, null returns -1
 * @return the length of the prefix, -1 if invalid or null
 */
public static int getPrefixLength(String filename) {
    if (filename == null) {
        return -1;
    }
    int len = filename.length();
    if (len == 0) {
        return 0;
    }
    char ch0 = filename.charAt(0);
    if (ch0 == ':') {
        return -1;
    }
    if (len == 1) {
        if (ch0 == '~') {
            return 2; // return a length greater than the input
        }
        return (isSeparator(ch0) ? 1 : 0);
    } else {
        if (ch0 == '~') {
            int posUnix = filename.indexOf(UNIX_SEPARATOR, 1);
            int posWin = filename.indexOf(WINDOWS_SEPARATOR, 1);
            if (posUnix == -1 && posWin == -1) {
                return len + 1; // return a length greater than the input
            }
            posUnix = (posUnix == -1 ? posWin : posUnix);
            posWin = (posWin == -1 ? posUnix : posWin);
            return Math.min(posUnix, posWin) + 1;
        }
        char ch1 = filename.charAt(1);
        if (ch1 == ':') {
            ch0 = Character.toUpperCase(ch0);
            if (ch0 >= 'A' && ch0 <= 'Z') {
                if (len == 2 || isSeparator(filename.charAt(2)) == false) {
                    return 2;
                }
                return 3;
            }
            return -1;

        } else if (isSeparator(ch0) && isSeparator(ch1)) {
            int posUnix = filename.indexOf(UNIX_SEPARATOR, 2);
            int posWin = filename.indexOf(WINDOWS_SEPARATOR, 2);
            if ((posUnix == -1 && posWin == -1) || posUnix == 2 || posWin == 2) {
                return -1;
            }
            posUnix = (posUnix == -1 ? posWin : posUnix);
            posWin = (posWin == -1 ? posUnix : posWin);
            return Math.min(posUnix, posWin) + 1;
        } else {
            return (isSeparator(ch0) ? 1 : 0);
        }
    }
}

From source file:com.ing.connector.util.WStringUtil.java

/**
 *  checkForSpecialPrefixes --> processes the known prefix:
 *                        "McX" so that the letter "X"
 *                        proceeding the prefix is
 *                        capitalized/*ww w .j  av  a 2 s  .c  o  m*/
 */
private String checkForSpecialPrefixes(String aString) {
    String lString = aString;
    int lLength = lString.length();

    if (lLength >= 3) {
        String[] lArray = new String[(lLength - 2)];

        for (int i = 0; i < lLength - 2; i++) {
            lArray[i] = lString.substring(i, i + 3);

            if (lArray[i].substring(0, 2).equalsIgnoreCase("Mc") && Character.isLetter(lString.charAt(i + 2))) {
                char[] lChar = lString.toCharArray();

                lChar[i + 2] = Character.toUpperCase(lChar[i + 2]);

                lString = new String(lChar);
            }
        }
    }

    return lString;
}

From source file:com.anrisoftware.globalpom.reflection.beans.BeanAccessImpl.java

private String getGetterName(String name, String prefix) {
    StringBuilder builder = new StringBuilder();
    char nameChar = Character.toUpperCase(name.charAt(0));
    builder.append(prefix);//from  w  w  w .j av a 2 s .  co  m
    builder.append(nameChar);
    builder.append(name.substring(1));
    return builder.toString();
}