Example usage for java.lang Character charValue

List of usage examples for java.lang Character charValue

Introduction

In this page you can find the example usage for java.lang Character charValue.

Prototype

@HotSpotIntrinsicCandidate
public char charValue() 

Source Link

Document

Returns the value of this Character object.

Usage

From source file:Main.java

/**
 * <p>Converts the character to a String that contains the one character.</p>
 * /*w ww  .  j  a  va 2 s .co m*/
 * <p>For ASCII 7 bit characters, this uses a cache that will return the
 * same String object each time.</p>
 * 
 * <p>If {@code null} is passed in, {@code null} will be returned.</p>
 *
 * <pre>
 *   CharUtils.toString(null) = null
 *   CharUtils.toString(' ')  = " "
 *   CharUtils.toString('A')  = "A"
 * </pre>
 *
 * @param ch  the character to convert
 * @return a String containing the one specified character
 */
public static String toString(final Character ch) {
    if (ch == null) {
        return null;
    }
    return toString(ch.charValue());
}

From source file:Main.java

/**
 * <p>Converts the string to the Unicode format '\u0020'.</p>
 * /* w ww  .j  ava2 s .  c om*/
 * <p>This format is the Java source code format.</p>
 * 
 * <p>If {@code null} is passed in, {@code null} will be returned.</p>
 *
 * <pre>
 *   CharUtils.unicodeEscaped(null) = null
 *   CharUtils.unicodeEscaped(' ')  = "\u0020"
 *   CharUtils.unicodeEscaped('A')  = "\u0041"
 * </pre>
 * 
 * @param ch  the character to convert, may be null
 * @return the escaped Unicode string, null if null input
 */
public static String unicodeEscaped(final Character ch) {
    if (ch == null) {
        return null;
    }
    return unicodeEscaped(ch.charValue());
}

From source file:Main.java

/**
 * <p>Converts the string to the unicode format '\u0020'.</p>
 * //from ww w.  jav  a  2 s.  c o  m
 * <p>This format is the Java source code format.</p>
 * 
 * <p>If <code>null</code> is passed in, <code>null</code> will be returned.</p>
 *
 * <pre>
 *   CharUtils.unicodeEscaped(null) = null
 *   CharUtils.unicodeEscaped(' ')  = "\u0020"
 *   CharUtils.unicodeEscaped('A')  = "\u0041"
 * </pre>
 * 
 * @param ch  the character to convert, may be null
 * @return the escaped unicode string, null if null input
 */
public static String unicodeEscaped(Character ch) {
    if (ch == null) {
        return null;
    }
    return unicodeEscaped(ch.charValue());
}

From source file:org.eclipse.wb.internal.core.eval.evaluators.DoubleEvaluator.java

/**
 * Converts given {@link Expression} into "double" value.
 *//* w w  w.j av  a  2  s .  c o m*/
private static double getDoubleValue(EvaluationContext context, Expression expression) throws Exception {
    Object value = AstEvaluationEngine.evaluate(context, expression);
    // Character
    if (value instanceof Character) {
        Character character = (Character) value;
        return character.charValue();
    }
    // Number
    Number number = (Number) value;
    return number.doubleValue();
}

From source file:org.eclipse.wb.internal.core.eval.evaluators.FloatEvaluator.java

/**
 * Converts given {@link Expression} into "float" value.
 */// w w  w  . j av  a2 s .c  o  m
private static float getFloatValue(EvaluationContext context, Expression expression) throws Exception {
    Object value = AstEvaluationEngine.evaluate(context, expression);
    // Character
    if (value instanceof Character) {
        Character character = (Character) value;
        return character.charValue();
    }
    // Number
    Number number = (Number) value;
    return number.floatValue();
}

From source file:Main.java

/**
 * Converts to primitive array./*from   w  w w. j  a v  a  2  s  .c o  m*/
 */
public static char[] values(Character[] array) {
    char[] dest = new char[array.length];
    for (int i = 0; i < array.length; i++) {
        Character v = array[i];
        if (v != null) {
            dest[i] = v.charValue();
        }
    }
    return dest;
}

From source file:org.eclipse.wb.internal.core.eval.evaluators.LongEvaluator.java

/**
 * Converts given {@link Expression} into "long" value.
 *//*w  ww  . ja  va2s .  com*/
private static long getLongValue(EvaluationContext context, Expression expression) throws Exception {
    Object value = AstEvaluationEngine.evaluate(context, expression);
    // Character
    if (value instanceof Character) {
        Character character = (Character) value;
        return character.charValue();
    }
    // Number
    Number number = (Number) value;
    return number.longValue();
}

From source file:Main.java

/**
 * <p>Converts the character to the Integer it represents, throwing an
 * exception if the character is not numeric.</p>
 * /*from w w  w. j  a v  a2 s.com*/
 * <p>This method coverts the char '1' to the int 1 and so on.</p>
 *
 * <pre>
 *   CharUtils.toIntValue(null, -1) = -1
 *   CharUtils.toIntValue('3', -1)  = 3
 *   CharUtils.toIntValue('A', -1)  = -1
 * </pre>
 *
 * @param ch  the character to convert
 * @param defaultValue  the default value to use if the character is not numeric
 * @return the int value of the character
 */
public static int toIntValue(Character ch, int defaultValue) {
    if (ch == null) {
        return defaultValue;
    }
    return toIntValue(ch.charValue(), defaultValue);
}

From source file:Main.java

/**
 * Replaces HTML entities in a string buffer
 * @param buffer the string buffer// ww  w .  j av  a  2s  .c  om
 */
public static void replaceEntities(StringBuffer buffer) {
    int i = 0;
    while (i < buffer.length()) {
        if (buffer.charAt(i) == '&') {
            int j = i + 1;
            while (j < buffer.length() && buffer.charAt(j) != ';')
                j++;
            if (j < buffer.length()) {
                char[] chars = new char[j - i - 1];
                buffer.getChars(i + 1, j, chars, 0);
                Character repl = (Character) replacements.get(new String(chars));
                if (repl != null) {
                    buffer.delete(i, j);
                    buffer.setCharAt(i, repl.charValue());
                } else
                    i = j;
            } else
                i = j;
        }
        i++;
    }
}

From source file:com.glaf.core.util.Tools.java

public static boolean isDatabaseField(String sourceString) {
    if (sourceString == null || sourceString.trim().length() < 2 || sourceString.trim().length() > 26) {
        return false;
    }/*ww  w.  j  a  va  2  s  . c om*/
    char[] sourceChrs = sourceString.toCharArray();
    Character chr = Character.valueOf(sourceChrs[0]);
    if (!((chr.charValue() == 95) || (65 <= chr.charValue() && chr.charValue() <= 90)
            || (97 <= chr.charValue() && chr.charValue() <= 122))) {
        return false;
    }
    for (int i = 1; i < sourceChrs.length; i++) {
        chr = Character.valueOf(sourceChrs[i]);
        if (!((chr.charValue() == 95) || (47 <= chr.charValue() && chr.charValue() <= 57)
                || (65 <= chr.charValue() && chr.charValue() <= 90)
                || (97 <= chr.charValue() && chr.charValue() <= 122))) {
            return false;
        }
    }
    return true;
}