List of usage examples for java.lang Character Character
@Deprecated(since = "9") public Character(char value)
From source file:org.apache.tika.parser.csv.CSVSnifferTest.java
@Test public void testAllowWhiteSpacesAroundAQuote() throws Exception { List<CSVResult> results = sniff(DELIMITERS, ALLOW_SPACES_BEFORE_QUOTE, StandardCharsets.UTF_8); assertEquals(2, results.size());/*from www. j a v a 2 s. com*/ assertEquals(new Character(','), results.get(0).getDelimiter()); results = sniff(DELIMITERS, ALLOW_SPACES_AFTER_QUOTE, StandardCharsets.UTF_8); assertEquals(2, results.size()); assertEquals(new Character(','), results.get(0).getDelimiter()); }
From source file:com.judoscript.jamaica.MyUtils.java
public static Object number2object(double val, String typeHint) { if (typeHint != null) { if (typeHint.equals("double")) return new Double(val); if (typeHint.equals("float")) return new Float((float) val); if (typeHint.equals("int")) return new Integer((int) val); if (typeHint.equals("long")) return new Long((long) val); if (typeHint.equals("short")) return new Short((short) val); if (typeHint.equals("char")) return new Character((char) val); if (typeHint.equals("byte")) return new Byte((byte) val); }//from w w w . jav a 2 s . c om return new Double(val); }
From source file:com.evolveum.midpoint.prism.xml.XmlTypeConverter.java
@SuppressWarnings("unchecked") public static <T> T toJavaValue(String stringContent, Class<T> type, boolean exceptionOnUnknown) { if (type.equals(String.class)) { return (T) stringContent; } else if (type.equals(char.class)) { return (T) (new Character(stringContent.charAt(0))); } else if (type.equals(File.class)) { return (T) new File(stringContent); } else if (type.equals(Integer.class)) { return (T) Integer.valueOf(stringContent); } else if (type.equals(int.class)) { return (T) Integer.valueOf(stringContent); } else if (type.equals(Short.class) || type.equals(short.class)) { return (T) Short.valueOf(stringContent); } else if (type.equals(Long.class)) { return (T) Long.valueOf(stringContent); } else if (type.equals(long.class)) { return (T) Long.valueOf(stringContent); } else if (type.equals(Byte.class)) { return (T) Byte.valueOf(stringContent); } else if (type.equals(byte.class)) { return (T) Byte.valueOf(stringContent); } else if (type.equals(float.class)) { return (T) Float.valueOf(stringContent); } else if (type.equals(Float.class)) { return (T) Float.valueOf(stringContent); } else if (type.equals(double.class)) { return (T) Double.valueOf(stringContent); } else if (type.equals(Double.class)) { return (T) Double.valueOf(stringContent); } else if (type.equals(BigInteger.class)) { return (T) new BigInteger(stringContent); } else if (type.equals(BigDecimal.class)) { return (T) new BigDecimal(stringContent); } else if (type.equals(byte[].class)) { byte[] decodedData = Base64.decodeBase64(stringContent); return (T) decodedData; } else if (type.equals(boolean.class) || Boolean.class.isAssignableFrom(type)) { // TODO: maybe we will need more inteligent conversion, e.g. to trim spaces, case insensitive, etc. return (T) Boolean.valueOf(stringContent); } else if (type.equals(GregorianCalendar.class)) { return (T) getDatatypeFactory().newXMLGregorianCalendar(stringContent).toGregorianCalendar(); } else if (XMLGregorianCalendar.class.isAssignableFrom(type)) { return (T) getDatatypeFactory().newXMLGregorianCalendar(stringContent); } else if (Duration.class.isAssignableFrom(type)) { return (T) getDatatypeFactory().newDuration(stringContent); } else if (type.equals(PolyString.class)) { return (T) new PolyString(stringContent); } else if (type.equals(ItemPath.class)) { throw new UnsupportedOperationException("Path conversion not supported yet"); } else {/*from w w w. j a v a 2 s . c o m*/ if (exceptionOnUnknown) { throw new IllegalArgumentException("Unknown conversion type " + type); } else { return null; } } }
From source file:org.openTwoFactor.clientExt.net.sf.ezmorph.array.CharacterObjectArrayMorpher.java
public Object morph(Object array) { if (array == null) { return null; }// w ww . j a va 2s . c o m if (CHARACTER_OBJECT_ARRAY_CLASS.isAssignableFrom(array.getClass())) { // no conversion needed return (Character[]) array; } if (array.getClass().isArray()) { int length = Array.getLength(array); int dims = getDimensions(array.getClass()); int[] dimensions = createDimensions(dims, length); Object result = Array.newInstance(Character.class, dimensions); if (dims == 1) { CharMorpher morpher = null; if (isUseDefault()) { if (defaultValue == null) { for (int index = 0; index < length; index++) { Array.set(result, index, null); } return result; } else { morpher = new CharMorpher(defaultValue.charValue()); } } else { morpher = new CharMorpher(); } for (int index = 0; index < length; index++) { Array.set(result, index, new Character(morpher.morph(Array.get(array, index)))); } } else { for (int index = 0; index < length; index++) { Array.set(result, index, morph(Array.get(array, index))); } } return result; } else { throw new MorphException("argument is not an array: " + array.getClass()); } }
From source file:org.jbpm.context.exe.VariableInstanceDbTest.java
public void testCharacter() { contextInstance.setVariable("a", new Character('c')); processInstance = saveAndReload(processInstance); contextInstance = processInstance.getContextInstance(); assertEquals(new Character('c'), contextInstance.getVariable("a")); }
From source file:Getopts.java
/** * Return an option or, if missing, a default value. * * @return option string, or defaultValue if error or option has no argument * @param c the option whose value is returned * @param defaultValue the value to return if there is no such option *//*from www . ja v a 2 s .c o m*/ public String option(char c, String defaultValue) { if (options == null) return defaultValue; String s; try { Object o = options.get(new Character(c)); if (o == null || !(o instanceof String)) s = defaultValue; else s = (String) o; } catch (Exception e) { s = defaultValue; } return s; }
From source file:Main.java
private static boolean processSubstituteChars(char currentChar, HashMap<?, ?> substituteChars, StringBuffer buffer) {//from w ww. j ava 2 s .c o m Character character = new Character(currentChar); if (substituteChars.containsKey(character)) { String value = (String) substituteChars.get(character); if (isDefined(value)) { // Append the value if defined buffer.append(value); } // If the value was not defined, then we will strip the character return true; } return false; }
From source file:org.docx4j.fonts.fop.fonts.Typeface.java
/** * Provide proper warning if a glyph is not available. * * @param c/*from w w w . ja v a2s . c o m*/ * the character which is missing. */ protected void warnMissingGlyph(char c) { // Give up, character is not available Character ch = new Character(c); if (warnedChars == null) { warnedChars = new java.util.HashSet(); } if (warnedChars.size() < 8 && !warnedChars.contains(ch)) { warnedChars.add(ch); if (this.eventListener != null) { this.eventListener.glyphNotAvailable(this, c, getFontName()); } else { if (warnedChars.size() == 8) { log.warn("Many requested glyphs are not available in font " + getFontName()); } else { log.warn("Glyph " + (int) c + " (0x" + Integer.toHexString(c) + ", " + Glyphs.charToGlyphName(c) + ") not available in font " + getFontName()); } } } }
From source file:org.romaframework.core.schema.SchemaClassElement.java
@SuppressWarnings({ "rawtypes", "unchecked" }) protected Object convertValue(Object iFieldValue, SchemaClassDefinition expectedType) { if (expectedType == null || expectedType.getSchemaClass().isArray()) return iFieldValue; SchemaClass typeClass = expectedType.getSchemaClass(); if (typeClass.equals(Roma.schema().getSchemaClass(iFieldValue))) return iFieldValue; String textValue = null;// w w w .j a va 2s . c om if (iFieldValue instanceof String) { textValue = (String) iFieldValue; } else if (iFieldValue != null) { textValue = iFieldValue.toString(); } Object value = null; if (textValue != null) { // TRY A SOFT CONVERSION if (typeClass.isOfType(Integer.class) || typeClass.isOfType(Integer.TYPE)) { try { value = textValue.equals("") ? null : Integer.parseInt(textValue); } catch (Exception e) { value = textValue.equals("") ? null : Double.valueOf(textValue).intValue(); } } else if (typeClass.isOfType(Long.class) || typeClass.isOfType(Long.TYPE)) { value = textValue.equals("") ? null : Long.parseLong(textValue); } else if (typeClass.isOfType(Short.class) || typeClass.isOfType(Short.TYPE)) { value = textValue.equals("") ? null : Short.parseShort(textValue); } else if (typeClass.isOfType(Byte.class) || typeClass.isOfType(Byte.TYPE)) { value = textValue.equals("") ? null : Byte.parseByte(textValue); } else if (typeClass.isOfType(Character.class) || typeClass.isOfType(Character.TYPE)) { if (textValue.length() > 0) { value = new Character(textValue.charAt(0)); } } else if (typeClass.isOfType(Float.class) || typeClass.isOfType(Float.TYPE)) { value = textValue.equals("") ? null : Float.parseFloat(textValue); } else if (typeClass.isOfType(Double.class) || typeClass.isOfType(Double.TYPE)) { value = textValue.equals("") ? null : Double.parseDouble(textValue); } else if (typeClass.isOfType(BigDecimal.class)) { value = textValue.equals("") ? null : new BigDecimal(textValue); } else if (iFieldValue != null && !typeClass.isArray() && iFieldValue.getClass().isArray()) { // DESTINATION VALUE IS NOT AN ARRAY: ASSIGN THE FIRST ONE ELEMENT value = ((Object[]) iFieldValue)[0]; } else if (typeClass.isEnum()) { value = Enum.valueOf((Class) typeClass.getLanguageType(), textValue.toUpperCase()); } else { value = iFieldValue; } } if (value != null) { // TODO is this the right place to do this...? Class<?> valueClass = value.getClass(); // SUCH A MONSTER!!! MOVE THIS LOGIC IN SchemaClass.isAssignableFrom... if (value instanceof VirtualObject && !(typeClass.getLanguageType() instanceof Class<?> && ((Class<?>) typeClass.getLanguageType()).isAssignableFrom(VirtualObject.class)) && ((VirtualObject) value).getSuperClassObject() != null) { if (ComposedEntity.class .isAssignableFrom(((VirtualObject) value).getSuperClassObject().getClass())) { value = ((VirtualObject) value).getSuperClassObject(); valueClass = value.getClass(); } } if (value instanceof ComposedEntity<?> && !typeClass.isAssignableFrom(valueClass)) { value = ((ComposedEntity<?>) value).getEntity(); } } if (value == null && typeClass.isPrimitive()) { log.warn("Cannot set the field value to null for primitive types! Field: " + getEntity() + "." + name + " of class " + expectedType.getName() + ". Setting value to 0."); // SET THE VALUE TO 0 value = SchemaHelper.assignDefaultValueToLiteral(typeClass); } return value; }
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 ww . ja va2 s .c om // 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(); }