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:bboss.org.apache.velocity.runtime.parser.node.SetPropertyExecutor.java

/**
 * @param clazz/*from w w w  . j  a  v  a  2s .c  om*/
 * @param property
 * @param arg
 */
protected void discover(final Class clazz, final String property, final Object arg) {
    Object[] params = new Object[] { arg };

    try {
        StrBuilder sb = new StrBuilder("set");
        sb.append(property);

        setMethod(introspector.getMethod(clazz, sb.toString(), params));

        if (!isAlive()) {
            /*
             *  now the convenience, flip the 1st character
             */

            char c = sb.charAt(3);

            if (Character.isLowerCase(c)) {
                sb.setCharAt(3, Character.toUpperCase(c));
            } else {
                sb.setCharAt(3, Character.toLowerCase(c));
            }

            setMethod(introspector.getMethod(clazz, sb.toString(), params));
        }
    }
    /**
     * pass through application level runtime exceptions
     */
    catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        String msg = "Exception while looking for property setter for '" + property;
        log.error(msg, e);
        throw new VelocityException(msg, e);
    }
}

From source file:de.topicmapslab.kuria.runtime.PropertyBinding.java

/**
 *  {@inheritDoc}/*  w w  w  . j  a v  a2  s .  c  o  m*/
 */
public String getLabel() {
    if ((label == null) && (fieldName != null))
        label = Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1);
    return label;
}

From source file:com.android.dialer.lookup.openstreetmap.OpenStreetMapForwardLookup.java

@Override
public ContactInfo[] lookup(Context context, String filter, Location lastLocation) {

    // The OSM API doesn't support case-insentive searches, but does
    // support regular expressions.
    String regex = "";
    for (int i = 0; i < filter.length(); i++) {
        char c = filter.charAt(i);
        regex += "[" + Character.toUpperCase(c) + Character.toLowerCase(c) + "]";
    }/*  w ww .j  a va 2  s. c o  m*/

    String request = String.format(Locale.ENGLISH, LOOKUP_QUERY, regex, RADIUS, lastLocation.getLatitude(),
            lastLocation.getLongitude());

    try {
        String httpResponse = httpPostRequest(request);

        JSONObject results = new JSONObject(httpResponse);

        return getEntries(results);
    } catch (IOException e) {
        Log.e(TAG, "Failed to execute query", e);
    } catch (JSONException e) {
        Log.e(TAG, "JSON error", e);
    }

    return null;
}

From source file:com.benfante.minimark.blo.ImporterBo.java

public List<Question> readQuestionSet(Reader r) throws ParseException, IOException {
    List<Question> result = new LinkedList<Question>();
    int lineCount = 0;
    String line = null;// w ww  .ja  va2s.c  o m
    BufferedReader br = null;
    if (r instanceof BufferedReader) {
        br = (BufferedReader) r;
    } else {
        br = new BufferedReader(r);
    }
    endstream: while ((line = br.readLine()) != null) {
        lineCount++;
        // skip empty and comment lines
        if (StringUtils.isBlank(line) || line.charAt(0) == 'c') {
            continue;
        }
        char questionType = 0;
        String questionId = "";
        StringBuffer questionText = new StringBuffer();
        List<FixedAnswer> answers = new LinkedList<FixedAnswer>();
        String tmp;
        if (line.charAt(0) != 'd') {
            throw new ParseException("Start of question not found", lineCount);
        }
        StringTokenizer tk = new StringTokenizer(line, "|");
        tk.nextToken(); // skip the initial 'd'
        // question id
        tmp = tk.nextToken();
        if (tmp != null) {
            questionId = tmp;
        } else {
            throw new ParseException("Question id not found", lineCount);
        }
        // question type
        tmp = tk.nextToken();
        if ((tmp != null) && (tmp.length() > 0)) {
            questionType = Character.toUpperCase(tmp.charAt(0));
            if ((questionType != 'A') && (questionType != 'R') && (questionType != 'C')
                    && (questionType != 'T')) {
                throw new ParseException("Question type unknown", lineCount);
            }
        } else {
            throw new ParseException("Question type not found", lineCount);
        }
        // answer scrambling flag
        tmp = tk.nextToken();
        if ((tmp != null) && (tmp.length() > 0)) {
            //                char acf = tmp.charAt(0);
            //                switch (acf) {
            //                    case 'u':
            //                        answerScrambling = false;
            //                        break;
            //                    case 's':
            //                        answerScrambling = true;
            //                        break;
            //                    default:
            //                        throw new ParseException("Answer scrambling flag unknown", lineCount);
            //                }
        } else {
            throw new ParseException("Answer scrambling flag not found", lineCount);
        }
        // question text
        tmp = tk.nextToken();
        if ((tmp != null) && (tmp.length() > 0)) {
            questionText.append(tmp);
            if ((questionType == 'A') || (questionType == 'T')) { // multiline questions
                while ((line = br.readLine()) != null) {
                    lineCount++;
                    if (StringUtils.isBlank(line)) {
                        break;
                    }
                    questionText.append('\n').append(line);
                }
            }
        } else {
            throw new ParseException("Question text not found", lineCount);
        }
        // suggested answers
        if ((questionType == 'R') || (questionType == 'C')) {
            while ((line = br.readLine()) != null) {
                lineCount++;
                if (StringUtils.isBlank(line)) {
                    break;
                }
                tk = new StringTokenizer(line, "|");
                // correct char
                tmp = tk.nextToken();
                boolean correct = false;
                if ((tmp != null) && (tmp.length() > 0)) {
                    char correctChar = line.charAt(0);
                    if (correctChar == 'y') {
                        correct = true;
                    } else if (correctChar == 'n') {
                        correct = false;
                    } else {
                        throw new ParseException("Correct char unknown", lineCount);
                    }
                } else {
                    throw new ParseException("Correct char not found (" + tmp + ")", lineCount);
                }
                tmp = tk.nextToken();
                String answerText = null;
                if ((tmp != null) && (tmp.length() > 0)) {
                    answerText = tmp;
                } else {
                    throw new ParseException("Answer text not found", lineCount);
                }
                FixedAnswer fixedAnswer = new FixedAnswer();
                fixedAnswer.setContent(answerText);
                fixedAnswer.setContentFilter(TextFilterUtils.HTML_FILTER_CODE);
                fixedAnswer.setCorrect(correct);
                fixedAnswer.setWeight(BigDecimal.ONE);
                answers.add(fixedAnswer);
            }
        }
        Question newQuestion = makeQuestion(questionType, questionId, questionText.toString(), answers);
        result.add(newQuestion);
    }
    return result;
}

From source file:au.org.ala.delta.intkey.directives.StandardIntkeyDirective.java

@Override
public IntkeyDirectiveInvocation doProcess(IntkeyContext context, String data) throws Exception {
    StringBuilder stringRepresentationBuilder = new StringBuilder();
    stringRepresentationBuilder.append(StringUtils.join(getControlWords(), " ").toUpperCase());

    List<String> tokens = ParsingUtils.tokenizeDirectiveCall(data);
    Queue<String> tokenQueue = new ArrayDeque<String>(tokens);

    IntkeyDirectiveInvocation invoc = buildCommandObject();

    if (_intkeyFlagsList != null && tokenQueue.size() > 0) {
        boolean matchingFlags = true;
        while (matchingFlags) {
            boolean tokenMatched = false;
            String token = tokenQueue.peek();

            if (token != null) {
                for (IntkeyDirectiveFlag flag : _intkeyFlagsList) {
                    if (flag.takesStringValue()) {
                        // Flag can have a string value supplied with it in
                        // format "/X=string", where X is the character
                        // symbol. Note that
                        // it is acceptable to supply such a flag without a
                        // following equals sign and string value.
                        if (token.matches("^/[" + Character.toLowerCase(flag.getSymbol())
                                + Character.toUpperCase(flag.getSymbol()) + "](=.+)?")) {

                            // If string value is not supplied, it defaults
                            // to empty string
                            String flagStringValue = "";

                            String[] tokenPieces = token.split("=");

                            // There should only be 0 or 1 equals sign. If
                            // more than none is supplied, no match.
                            if (tokenPieces.length < 3) {
                                if (tokenPieces.length == 2) {
                                    flagStringValue = tokenPieces[1];
                                }//  w  w w .jav a  2  s  . c  o m

                                BeanUtils.setProperty(invoc, flag.getName(), flagStringValue);
                                tokenQueue.remove();
                                tokenMatched = true;
                                stringRepresentationBuilder.append(" ");
                                stringRepresentationBuilder.append(token);
                                break;
                            }
                        }
                    } else {
                        if (token.equalsIgnoreCase("/" + flag.getSymbol())) {

                            BeanUtils.setProperty(invoc, flag.getName(), true);
                            tokenQueue.remove();
                            tokenMatched = true;
                            stringRepresentationBuilder.append(" ");
                            stringRepresentationBuilder.append(token);
                            break;
                        }
                    }
                }

                matchingFlags = tokenMatched;
            } else {
                matchingFlags = false;
            }
        }
    }

    // The arguments list needs to be generated each time a call to the
    // directive is processed. This is
    // because most arguments need to have provided with an initial value
    // which is used when prompting the user.
    // This initial value needs to be read out of the IntkeyContext at the
    // time of parsing.
    // E.g. the integer argument for the SET TOLERANCE directive will have
    // an initial value equal to the
    // the value of the tolerance setting before the call to the directive.
    List<IntkeyDirectiveArgument<?>> intkeyArgsList = generateArgumentsList(context);

    if (intkeyArgsList != null) {
        for (IntkeyDirectiveArgument<?> arg : intkeyArgsList) {
            Object parsedArgumentValue = arg.parseInput(tokenQueue, context,
                    StringUtils.join(_controlWords, " "), stringRepresentationBuilder);
            if (parsedArgumentValue != null) {
                BeanUtils.setProperty(invoc, arg.getName(), parsedArgumentValue);
            } else {
                // No argument value supplied, user cancelled out of the
                // prompt dialog.
                return null;
            }
        }
    }

    invoc.setStringRepresentation(stringRepresentationBuilder.toString());

    return invoc;
}

From source file:bboss.org.apache.velocity.runtime.parser.node.PropertyExecutor.java

/**
 * @param clazz//w  ww.  ja va2  s  .  c o  m
 * @param property
 */
protected void discover(final Class clazz, final String property) {
    /*
     *  this is gross and linear, but it keeps it straightforward.
     */

    try {
        Object[] params = {};

        StringBuffer sb = new StringBuffer("get");
        sb.append(property);

        setMethod(introspector.getMethod(clazz, sb.toString(), params));

        if (!isAlive()) {
            /*
             *  now the convenience, flip the 1st character
             */

            char c = sb.charAt(3);

            if (Character.isLowerCase(c)) {
                sb.setCharAt(3, Character.toUpperCase(c));
            } else {
                sb.setCharAt(3, Character.toLowerCase(c));
            }

            setMethod(introspector.getMethod(clazz, sb.toString(), params));
        }
    }
    /**
     * pass through application level runtime exceptions
     */
    catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        String msg = "Exception while looking for property getter for '" + property;
        log.error(msg, e);
        throw new VelocityException(msg, e);
    }
}

From source file:com.kstenschke.shifter.utils.UtilsTextual.java

/**
 * @param   str      String to be converted
 * @return  String   Given string converted to lower case with only first char in upper case
 *///from   ww  w .j  a  va2 s. c om
public static String toUcFirst(String str) {
    return Character.toUpperCase(str.charAt(0)) + str.substring(1).toLowerCase();
}

From source file:fr.paris.lutece.util.bean.BeanUtil.java

/**
 * Remove underscore and set the next letter in caps
 * @param strSource The source/*from   w ww .j  a  v  a2  s . c  om*/
 * @return The converted string
 */
public static String convertUnderscores(String strSource) {
    StringBuilder sb = new StringBuilder();
    boolean bCapitalizeNext = false;

    for (char c : strSource.toCharArray()) {
        if (c == UNDERSCORE) {
            bCapitalizeNext = true;
        } else {
            if (bCapitalizeNext) {
                sb.append(Character.toUpperCase(c));
                bCapitalizeNext = false;
            } else {
                sb.append(c);
            }
        }
    }

    return sb.toString();
}

From source file:lucee.commons.lang.StringUtil.java

public static String capitalize(String input, char[] delims) {

    if (isEmpty(input))
        return input;

    if (ArrayUtil.isEmpty(delims))
        delims = new char[] { '.', '-', '(', ')' };

    StringBuilder sb = new StringBuilder(input.length());

    boolean isLastDelim = true, isLastSpace = true;
    int len = input.length();
    for (int i = 0; i < len; i++) {

        char c = input.charAt(i);

        if (Character.isWhitespace(c)) {

            if (!isLastSpace)
                sb.append(' ');

            isLastSpace = true;/*from w w w.  j a  va 2  s  . c  o m*/
        } else {

            sb.append((isLastSpace || isLastDelim) ? Character.toUpperCase(c) : c);

            isLastDelim = _contains(delims, c);
            isLastSpace = false;
        }
    }

    return sb.toString();
}

From source file:net.sf.keystore_explorer.utilities.io.HexUtil.java

private static String getHexClearLineDump(byte[] bytes, int len) {
    StringBuffer sbHex = new StringBuffer();
    StringBuffer sbClr = new StringBuffer();

    for (int cnt = 0; cnt < len; cnt++) {
        // Convert byte to int
        byte b = bytes[cnt];
        int i = b & 0xFF;

        // First part of byte will be one hex char
        int i1 = (int) Math.floor(i / 16);

        // Second part of byte will be one hex char
        int i2 = i % 16;

        // Get hex characters
        sbHex.append(Character.toUpperCase(Character.forDigit(i1, 16)));
        sbHex.append(Character.toUpperCase(Character.forDigit(i2, 16)));

        if ((cnt + 1) < len) {
            // Divider between hex characters
            sbHex.append(' ');
        }//w w  w.j a  v  a 2  s .c o  m

        // Get clear character

        // Character to display if character not defined in Unicode or is a
        // control charcter
        char c = '.';

        // Not a control character and defined in Unicode
        if ((!Character.isISOControl((char) i)) && (Character.isDefined((char) i))) {
            Character clr = new Character((char) i);
            c = clr.charValue();
        }

        sbClr.append(c);
    }

    /*
     * Put both dumps together in one string (hex, clear) with appropriate
     * padding between them (pad to array length)
     */
    StringBuffer strBuff = new StringBuffer();

    strBuff.append(sbHex.toString());

    int i = bytes.length - len;
    for (int cnt = 0; cnt < i; cnt++) {
        strBuff.append("   "); // Each missing byte takes up three spaces
    }

    strBuff.append("   "); // The gap between hex and clear output is three
    // spaces
    strBuff.append(sbClr.toString());

    return strBuff.toString();
}