List of usage examples for java.lang Character Character
@Deprecated(since = "9") public Character(char value)
From source file:Main.java
/** * Converts the raw characters to XML escape characters. * /* w ww .j av a 2 s . co m*/ * @param rawContent * @param charset Null when charset is not known, so we assume it's unicode * @param isNoLines * @return escape string */ public static String escapeXML(String rawContent, String charset, boolean isNoLines) { if (rawContent == null) return ""; //$NON-NLS-1$ else { StringBuffer sb = new StringBuffer(); for (int i = 0; i < rawContent.length(); i++) { char ch = rawContent.charAt(i); if (ch == '\'') sb.append("'"); //$NON-NLS-1$ else if (ch == '&') sb.append("&"); //$NON-NLS-1$ else if (ch == '"') sb.append("""); //$NON-NLS-1$ else if (ch == '<') sb.append("<"); //$NON-NLS-1$ else if (ch == '>') sb.append(">"); //$NON-NLS-1$ else if (ch > '~' && charset != null && charSetImpliesAscii(charset)) // TODO - why is hashcode the only way to get the unicode number for the character // in jre 5.0? sb.append("&#x" + Integer.toHexString(new Character(ch).hashCode()).toUpperCase() + ";"); //$NON-NLS-1$ //$NON-NLS-2$ else if (isNoLines) { if (ch == '\r') sb.append("
"); //$NON-NLS-1$ else if (ch != '\n') sb.append(ch); } else sb.append(ch); } return sb.toString(); } }
From source file:StringUtil.java
/** * <p> Converts a string to a Set. Breaks the string to characters and store * each character in a Set./*from ww w . j ava2 s. c o m*/ * * @param string the string to convert * @return a <code>Set</code> containing all characters in the text string parameter */ public static Set convertToSet(String string) { // Result hashset Set resultSet = new HashSet(); for (int i = 0; i < string.length(); i++) { resultSet.add(new Character(string.charAt(i))); } // Return result return resultSet; }
From source file:de.odysseus.calyxo.base.util.ParseUtils.java
private static Object nullValue(Class type) { if (type.isPrimitive()) { if (type == boolean.class) return Boolean.FALSE; if (type == byte.class) return new Byte((byte) 0); if (type == char.class) return new Character((char) 0); if (type == short.class) return new Short((short) 0); if (type == int.class) return new Integer(0); if (type == long.class) return new Long(0); if (type == float.class) return new Float(0); if (type == double.class) return new Double(0); }/*from w w w .j a v a 2 s . c o m*/ return null; }
From source file:StringUtil.java
/** * <p>Removes specified chars from a string.</p> * * @param aString the string that will be examined to remove chars * @param unWantedCharArray the char array containing the chars * that should be removed from a string//from www .j av a2 s. co m * @return the string after removing the specified chars */ public static String removeCharsFromString(String aString, char[] unWantedCharArray) { Character character = null; // Store unwanted chars in a hashset Set unWantedCharSet = new HashSet(); for (int i = 0; i < unWantedCharArray.length; i++) { character = new Character(unWantedCharArray[i]); unWantedCharSet.add(character); } // Create result String buffer StringBuffer result = new StringBuffer(aString.length()); // For each character in aString, append it to the result string buffer // if it is not in unWantedCharSet for (int i = 0; i < aString.length(); i++) { character = new Character(aString.charAt(i)); if (!unWantedCharSet.contains(character)) { result.append(aString.charAt(i)); } } // Return result return result.toString(); }
From source file:com.skilrock.lms.common.utility.AutoGenerate.java
public static String autoPassword() { Random r = new Random(); StringBuffer newString = new StringBuffer(); // No of Big letters in password int a1 = r.nextInt(6) + 1; // No of small letters in password int a2 = r.nextInt(7 - a1) + 1; // no on numbers int a3 = 8 - a1 - a2; for (int j = 0; j < a1; j++) { char c1 = (char) (r.nextInt(26) + 65); // AL.add(new Character(c1)); newString.append(new Character(c1)); }//from w w w . java 2s.co m for (int j = 0; j < a2; j++) { char c1 = (char) (r.nextInt(26) + 97); // AL.add(new Character(c1)); newString.append(new Character(c1)); } for (int j = 0; j < a3; j++) { char c1 = (char) (r.nextInt(9) + 48); // AL.add(new Character(c1)); newString.append(new Character(c1)); } //logger.debug("pwd = " + newString.toString()); return newString.toString(); }
From source file:Main.java
/** * Converts the given object to an object of the specified type. The object is * casted directly if possible, or else a new object is created using the * destination type's public constructor that takes the original object as * input (except when converting to {@link String}, which uses the * {@link Object#toString()} method instead). In the case of primitive types, * returns an object of the corresponding wrapped type. If the destination * type does not have an appropriate constructor, returns null. * /* ww w . ja v a 2s .c om*/ * @param <T> Type to which the object should be converted. * @param value The object to convert. * @param type Type to which the object should be converted. */ public static <T> T convert(final Object value, final Class<T> type) { if (value == null) return getNullValue(type); // ensure type is well-behaved, rather than a primitive type final Class<T> saneType = getNonprimitiveType(type); // cast the existing object, if possible if (canCast(value, saneType)) return cast(value, saneType); // special cases for strings if (value instanceof String) { // source type is String final String s = (String) value; if (s.isEmpty()) { // return null for empty strings return getNullValue(type); } // use first character when converting to Character if (saneType == Character.class) { final Character c = new Character(s.charAt(0)); @SuppressWarnings("unchecked") final T result = (T) c; return result; } } if (saneType == String.class) { // destination type is String; use Object.toString() method final String sValue = value.toString(); @SuppressWarnings("unchecked") final T result = (T) sValue; return result; } // wrap the original object with one of the new type, using a constructor try { final Constructor<T> ctor = saneType.getConstructor(value.getClass()); return ctor.newInstance(value); } catch (final Exception exc) { // no known way to convert return null; } }
From source file:com.judoscript.jamaica.MyUtils.java
public static Object parseCharLiteral(String lit, String typeHint) { lit = StringEscapeUtils.unescapeJava(lit); char ch = lit.charAt(1); return (typeHint != null) ? number2object(ch, typeHint) : new Character(ch); }
From source file:com.modcrafting.ultrabans.util.Formatting.java
public static String formatMessage(String str) { String funnyChar = new Character((char) 167).toString(); str = str.replaceAll("&", funnyChar); return str;//from w ww.j a va 2s .co m }
From source file:StringUtil.java
/** * <p> Converts a char array to a Set. Puts all characters in the array to a Set. * * @param charArray an array of <CODE>char</CODE>s * @return a <code>set</code> containing all characters in the char array *//*from www. j a va 2 s .c om*/ public static Set convertToSet(char[] charArray) { // Result hashset Set resultSet = new HashSet(); for (int i = 0; i < charArray.length; i++) { resultSet.add(new Character(charArray[i])); } // Return result return resultSet; }
From source file:Base64Decoder.java
private void printHex(int x) { int h = (x & 0xf0) >> 4; int l = (x & 0x0f); System.out.print((new Character((char) ((h > 9) ? 'A' + h - 10 : '0' + h))).toString() + (new Character((char) ((l > 9) ? 'A' + l - 10 : '0' + l))).toString()); }