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:de.rnd7.kata.reversi.logic.ai.AIMatrix.java

private static void processLine(final AIMatrix matrix, final int y, final String line) {
    int x = 0;/*from   w  w  w . j av  a  2  s  .  co  m*/
    for (final char ch : line.toCharArray()) {
        final int weight;
        if (Character.isLowerCase(ch)) {
            weight = -Character.toUpperCase(ch);
        } else {
            weight = ch;
        }

        matrix.set(new Coordinate(x++, y), weight);
    }
}

From source file:Main.java

/**
 * <p>/* www . jav  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();
}

From source file:Main.java

public static boolean isUpperCase(String s) {
    int len = s.length();
    for (int i = 0; i < len; i++) {
        char ch = s.charAt(i);
        if (Character.toUpperCase(ch) != ch)
            return false;
    }/*from www  .j  ava2  s  .c  o  m*/
    return len != 0;
}

From source file:com.threecrickets.jygments.grammar.Lexer.java

public static Lexer getByName(String name) throws ResolutionException {
    if ((name == null) || (name.length() == 0))
        name = "Lexer";
    else if (Character.isLowerCase(name.charAt(0)))
        name = Character.toUpperCase(name.charAt(0)) + name.substring(1) + "Lexer";

    Lexer lexer = getByFullName(name);/*from   w  w w .  j av  a2  s .  c o m*/
    if (lexer != null)
        return lexer;
    else {
        // Try contrib package
        String pack = Jygments.class.getPackage().getName() + ".contrib";
        lexer = getByFullName(pack + "." + name);
        if (lexer == null) {
            // Try this package
            pack = Lexer.class.getPackage().getName();
            lexer = getByFullName(pack + "." + name);
        }
        return lexer;
    }
}

From source file:StringUtil.java

/**
 * @return the string provided with its first character capitalized
 *//*from   w  w  w. ja  v  a2s  .c om*/
public static String capitalize(String s) {
    if (s.length() == 0) {
        return s;
    }
    char first = s.charAt(0);
    char capitalized = Character.toUpperCase(first);
    return (first == capitalized) ? s : capitalized + s.substring(1);
}

From source file:com.amazonaws.services.iot.client.shadow.AwsIotJsonSerializer.java

private static Object invokeGetterMethod(Object target, Field field) throws IOException {
    String fieldName = Character.toUpperCase(field.getName().charAt(0)) + field.getName().substring(1);
    String getter = "get" + fieldName;

    Method method;/*from  www  . j  av a  2  s .  c  o  m*/
    try {
        method = target.getClass().getMethod(getter);
    } catch (NoSuchMethodException | SecurityException e) {
        if (e instanceof NoSuchMethodException && boolean.class.equals(field.getType())) {
            getter = "is" + fieldName;
            try {
                method = target.getClass().getMethod(getter);
            } catch (NoSuchMethodException | SecurityException ie) {
                throw new IllegalArgumentException(ie);
            }
        } else {
            throw new IllegalArgumentException(e);
        }
    }

    Object value;
    try {
        value = method.invoke(target);
    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        throw new IOException(e);
    }
    return value;
}

From source file:com.kenai.redminenb.util.RedmineUtil.java

/**
 * Helper method to convert the first letter of a string to uppercase. And
 * prefix the string with some next string.
 *//*from w  ww. ja va2s . c o  m*/
public static String capitalize(String s) {
    return StringUtils.isBlank(s) ? s : Character.toUpperCase(s.charAt(0)) + s.substring(1);
}

From source file:com.enremmeta.onenow.Utils.java

public static String capitalize(String s) {
    return Character.toUpperCase(s.charAt(0)) + s.substring(1);
}

From source file:com.hs.mail.imap.schedule.ScheduleUtils.java

public static Date getTimeAfter(String str, Date defaultTime) {
    if (str != null) {
        int sz = str.length();
        for (int i = 0; i < sz; i++) {
            char ch = str.charAt(i);
            if (!Character.isDigit(ch)) {
                try {
                    int amount = Integer.parseInt(str.substring(0, i));
                    switch (Character.toUpperCase(ch)) {
                    case 'H':
                        return DateUtils.addHours(new Date(), amount);
                    case 'M':
                        return DateUtils.addMinutes(new Date(), amount);
                    }/* w  w w . ja  va  2  s .c o m*/
                } catch (NumberFormatException e) {
                    break;
                }
            }
        }
    }
    return defaultTime;
}

From source file:Main.java

/**
 * Green implementation of regionMatches.
 *
 * @param cs         the {@code CharSequence} to be processed
 * @param ignoreCase whether or not to be case insensitive
 * @param thisStart  the index to start on the {@code cs} CharSequence
 * @param substring  the {@code CharSequence} to be looked for
 * @param start      the index to start on the {@code substring} CharSequence
 * @param length     character length of the region
 * @return whether the region matched// ww w  . ja  v  a  2 s . c om
 */
static boolean regionMatches(final CharSequence cs, final boolean ignoreCase, final int thisStart,
        final CharSequence substring, final int start, final int length) {
    if (cs instanceof String && substring instanceof String) {
        return ((String) cs).regionMatches(ignoreCase, thisStart, (String) substring, start, length);
    }
    int index1 = thisStart;
    int index2 = start;
    int tmpLen = length;

    while (tmpLen-- > 0) {
        final char c1 = cs.charAt(index1++);
        final char c2 = substring.charAt(index2++);

        if (c1 == c2) {
            continue;
        }

        if (!ignoreCase) {
            return false;
        }

        // The same check as in String.regionMatches():
        if (Character.toUpperCase(c1) != Character.toUpperCase(c2)
                && Character.toLowerCase(c1) != Character.toLowerCase(c2)) {
            return false;
        }
    }

    return true;
}