List of usage examples for java.lang Character charValue
@HotSpotIntrinsicCandidate public char charValue()
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 ww. j a v a 2 s . c o m * <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(final Character ch, final int defaultValue) { if (ch == null) { return defaultValue; } return toIntValue(ch.charValue(), defaultValue); }
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 www. j a va2s .c o m * <p>This method coverts the char '1' to the int 1 and so on.</p> * * <pre> * CharUtils.toIntValue('3') = 3 * CharUtils.toIntValue(null) throws IllegalArgumentException * CharUtils.toIntValue('A') throws IllegalArgumentException * </pre> * * @param ch the character to convert, not null * @return the int value of the character * @throws IllegalArgumentException if the Character is not ASCII numeric or is null */ public static int toIntValue(Character ch) { if (ch == null) { throw new IllegalArgumentException("The character must not be null"); } return toIntValue(ch.charValue()); }
From source file:Main.java
/** * <p>Converts the character to the Integer it represents, throwing an * exception if the character is not numeric.</p> * // w w w . ja v a 2s . co m * <p>This method coverts the char '1' to the int 1 and so on.</p> * * <pre> * CharUtils.toIntValue('3') = 3 * CharUtils.toIntValue(null) throws IllegalArgumentException * CharUtils.toIntValue('A') throws IllegalArgumentException * </pre> * * @param ch the character to convert, not null * @return the int value of the character * @throws IllegalArgumentException if the Character is not ASCII numeric or is null */ public static int toIntValue(final Character ch) { if (ch == null) { throw new IllegalArgumentException("The character must not be null"); } return toIntValue(ch.charValue()); }
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(' '); }//from w ww . ja va2 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(); }
From source file:com.meetup.memcached.NativeHandler.java
protected static byte[] encode(Character value) { return encode(value.charValue()); }
From source file:org.sakaiproject.imagegallery.springutil.SqlScriptParser.java
/** * Parse the SQL script to produce an array of database statements. * @param sqlScriptReader A reader that reads the SQL script text. * @return An array of strings, each containing a single statement. * @throws RuntimeException-wrapped IOException if the script cannot be read. * @throws RuntimeException-wrapped ParseException if the script cannot be parsed. *///from ww w. j av a2 s . c om public static String[] parse(Reader sqlScriptReader) { char statementDelimiter = ';'; List<String> statements = new ArrayList<String>(); StringBuffer sql = new StringBuffer(1024); String line = ""; BufferedReader in = new BufferedReader(sqlScriptReader); int lineNumber = 0; // Read each line and build up statements. try { while ((line = in.readLine()) != null) { lineNumber++; // Trim line = cleanLine(line); // Check for statement delimiter change. Character newDelimiter = parseForNewStatementDelimiter(line); if (newDelimiter != null) { statementDelimiter = newDelimiter.charValue(); continue; } // Validate and strip comments parseLine(line, sql, lineNumber, statementDelimiter); if (sql.length() > 0) { if (sql.charAt(sql.length() - 1) == statementDelimiter) { // This line terminates the statement. // Lose the delimiter. String statement = sql.toString().substring(0, sql.length() - 1).trim(); if (statement.length() > 0) { statements.add(statement); s_log.debug("Found statement: " + statement); } // Clear buffer for the next statement. sql.replace(0, sql.length(), ""); } else { // This line does not terminate the statement. Add a // space and go on to the next one. sql.append(" "); } } } } catch (IOException e) { throw new RuntimeException(e); } // Catch any statements not followed by delimiter. String orphanStatement = sql.toString().trim(); if (orphanStatement.length() > 0) { statements.add(orphanStatement); s_log.debug("Found statement: " + orphanStatement); } String[] result = new String[statements.size()]; statements.toArray(result); return result; }
From source file:Main.java
/** * <p>Converts an array of object Character to primitives handling {@code null}.</p> * * <p>This method returns {@code null} for a {@code null} input array.</p> * * @param array a {@code Character} array, may be {@code null} * @param valueForNull the value to insert if {@code null} found * @return a {@code char} array, {@code null} if null array input */// w w w.j a v a 2 s.co m public static char[] toPrimitive(Character[] array, char valueForNull) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_CHAR_ARRAY; } final char[] result = new char[array.length]; for (int i = 0; i < array.length; i++) { Character b = array[i]; result[i] = (b == null ? valueForNull : b.charValue()); } return result; }
From source file:Main.java
/** * <p>Converts an array of object Character to primitives handling {@code null}.</p> * * <p>This method returns {@code null} for a {@code null} input array.</p> * * @param array a {@code Character} array, may be {@code null} * @param valueForNull the value to insert if {@code null} found * @return a {@code char} array, {@code null} if null array input */// ww w. j a v a 2 s.co m public static char[] toPrimitive(final Character[] array, final char valueForNull) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_CHAR_ARRAY; } final char[] result = new char[array.length]; for (int i = 0; i < array.length; i++) { final Character b = array[i]; result[i] = (b == null ? valueForNull : b.charValue()); } return result; }
From source file:Util.java
/** * Replace all the occurences of HTML escape strings with the * respective characters.//from w w w . jav a 2s . c o m * * @param s a <code>String</code> value * @return a <code>String</code> value */ public static final String unescapeHTML(String s) { char[] chars = s.toCharArray(); char[] escaped = new char[chars.length]; // Note: escaped[pos] = end of the escaped char array. int pos = 0; for (int i = 0; i < chars.length;) { if (chars[i] != '&') { escaped[pos++] = chars[i++]; continue; } // Allow e.g. { int j = i + 1; if (j < chars.length && chars[j] == '#') j++; // Scan until we find a char that is not letter or digit. for (; j < chars.length; j++) { if (!Character.isLetterOrDigit(chars[j])) break; } boolean replaced = false; if (j < chars.length && chars[j] == ';') { if (s.charAt(i + 1) == '#') { // Check for &#D; and 
 pattern try { long charcode = 0; char ch = s.charAt(i + 2); if (ch == 'x' || ch == 'X') { charcode = Long.parseLong(new String(chars, i + 3, j - i - 3), 16); } else if (Character.isDigit(ch)) { charcode = Long.parseLong(new String(chars, i + 2, j - i - 2)); } if (charcode > 0 && charcode < 65536) { escaped[pos++] = (char) charcode; replaced = true; } } catch (NumberFormatException ex) { // Failed, not replaced. } } else { String key = new String(chars, i, j - i + 1); Character repl = escapeStrings.get(key); if (repl != null) { escaped[pos++] = repl.charValue(); replaced = true; } } j++; // Skip over ';' } if (!replaced) { // Not a recognized escape sequence, leave as-is System.arraycopy(chars, i, escaped, pos, j - i); pos += j - i; } i = j; } return new String(escaped, 0, pos); }
From source file:pl.edu.icm.coansys.commons.java.DiacriticsRemover.java
/** * Generates a sort key for a given text. This key is useful in environments * where only basic Latin characters are reliably sorted (for example, a * RDBMS with unknown collation settings). * * @param text Text to process.//from ww w . j a v a 2 s .com * @param idempotent Whether the conversion should be idempotent. This is * guaranteed to be true: * <code>alphaSortable(s, true).equals(alphaSortable(alphaSortable(s, true), true)</code>, * while this is not necessarily true: * <code>alphaSortable(s, false).equals(alphaSortable(alphaSortable(s, false), false)</code>. * @return */ public static String alphaSortable(String text, boolean idempotent) { if (text == null) { return null; } if (idempotent && text.startsWith(MAGIC)) { return text; } String tmp = text.toLowerCase(Locale.ENGLISH); tmp = Normalizer.normalize(tmp, Normalizer.Form.NFKD); StringBuilder builder = new StringBuilder(); if (idempotent) { builder.append(MAGIC); } boolean wasSpaceSeparator = false; for (int i = 0; i < tmp.length(); i++) { Character ch = tmp.charAt(i); if (!ArrayUtils.contains(INTERESTING_TYPES, Character.getType(ch)) && !ArrayUtils.contains(INTERESTING_CHARACTERS, ch)) { continue; } String s; // TODO quick fix of mantis 3231 if (isSpaceSeparator(ch)) { if (wasSpaceSeparator) { continue; } wasSpaceSeparator = true; } else { wasSpaceSeparator = false; } if (alphaSortableMapping.containsKey(ch)) { s = alphaSortableMapping.get(ch); } else if (lookup.containsKey(ch)) { s = lookup.get(ch); } else { s = ch.toString(); } for (int j = 0; j < s.length(); j++) { Character c = s.charAt(j); // TODO Very ugly workaround of the problem described in 0002643 if (ArrayUtils.contains(INTERESTING_CHARACTERS, c)) { builder.append(c); } else { builder.append(StringUtils.leftPad(Integer.toHexString(c.charValue()), 4, '0')); } } } return builder.toString(); }