List of usage examples for java.lang Character valueOf
@HotSpotIntrinsicCandidate public static Character valueOf(char c)
From source file:Main.java
public static Object getObject(String type, String value) throws Exception { type = type.toLowerCase();//from w ww. ja v a2 s . c om if ("boolean".equals(type)) return Boolean.valueOf(value); if ("byte".equals(type)) return Byte.valueOf(value); if ("short".equals(type)) return Short.valueOf(value); if ("char".equals(type)) if (value.length() != 1) throw new NumberFormatException("Argument is not a character!"); else return Character.valueOf(value.toCharArray()[0]); if ("int".equals(type)) return Integer.valueOf(value); if ("long".equals(type)) return Long.valueOf(value); if ("float".equals(type)) return Float.valueOf(value); if ("double".equals(type)) return Double.valueOf(value); if ("string".equals(type)) return value; else { Object objs[] = new String[] { value }; return Class.forName(type).getConstructor(new Class[] { java.lang.String.class }).newInstance(objs); } }
From source file:Main.java
/** * Converts to object array.//from w ww.j av a 2 s .c o m */ public static Character[] valuesOf(char[] array) { Character[] dest = new Character[array.length]; for (int i = 0; i < array.length; i++) { dest[i] = Character.valueOf(array[i]); } return dest; }
From source file:org.evosuite.utils.NumberFormatter.java
/** * <p>//from w w w. j ava2 s . c o m * getNumberString * </p> * * @param value * a {@link java.lang.Object} object. * @return a {@link java.lang.String} object. */ public static String getNumberString(Object value) { if (value == null) return "null"; else if (value.getClass().equals(char.class) || value.getClass().equals(Character.class)) { // StringEscapeUtils fails to escape a single quote char if (Character.valueOf('\'').equals(value)) { return "'\\\''"; } else { return "'" + StringEscapeUtils.escapeJava(Character.toString((Character) value)) + "'"; } } else if (value.getClass().equals(String.class)) { return "\"" + StringEscapeUtils.escapeJava((String) value) + "\""; } else if (value.getClass().equals(float.class) || value.getClass().equals(Float.class)) { if (value.toString().equals("" + Float.NaN)) return "Float.NaN"; else if (value.toString().equals("" + Float.NEGATIVE_INFINITY)) return "Float.NEGATIVE_INFINITY"; else if (value.toString().equals("" + Float.POSITIVE_INFINITY)) return "Float.POSITIVE_INFINITY"; else if (((Float) value) < 0F) return "(" + value + "F)"; else return value + "F"; } else if (value.getClass().equals(double.class) || value.getClass().equals(Double.class)) { if (value.toString().equals("" + Double.NaN)) return "Double.NaN"; else if (value.toString().equals("" + Double.NEGATIVE_INFINITY)) return "Double.NEGATIVE_INFINITY"; else if (value.toString().equals("" + Double.POSITIVE_INFINITY)) return "Double.POSITIVE_INFINITY"; else if (((Double) value) < 0.0) return "(" + value + ")"; else return value.toString(); } else if (value.getClass().equals(long.class) || value.getClass().equals(Long.class)) { if (((Long) value) < 0) return "(" + value + "L)"; else return value + "L"; } else if (value.getClass().equals(byte.class) || value.getClass().equals(Byte.class)) { if (((Byte) value) < 0) return "(byte) (" + value + ")"; else return "(byte)" + value; } else if (value.getClass().equals(short.class) || value.getClass().equals(Short.class)) { if (((Short) value) < 0) return "(short) (" + value + ")"; else return "(short)" + value; } else if (value.getClass().equals(int.class) || value.getClass().equals(Integer.class)) { int val = ((Integer) value).intValue(); if (val == Integer.MAX_VALUE) return "Integer.MAX_VALUE"; else if (val == Integer.MIN_VALUE) return "Integer.MIN_VALUE"; else if (((Integer) value) < 0) return "(" + value + ")"; else return "" + val; } else if (value.getClass().isEnum() || value instanceof Enum) { // java.util.concurrent.TimeUnit is an example where the enum // elements are anonymous inner classes, and then isEnum does // not return true apparently? So we check using instanceof as well. Class<?> clazz = value.getClass(); String className = clazz.getSimpleName(); while (clazz.getEnclosingClass() != null) { String enclosingName = clazz.getEnclosingClass().getSimpleName(); className = enclosingName + "." + className; clazz = clazz.getEnclosingClass(); } // We have to do this here to avoid a double colon in the TimeUnit example if (!className.endsWith(".")) className += "."; try { if (value.getClass().getField(value.toString()) != null) return className + value; else if (((Enum<?>) value).name() != null) return className + ((Enum<?>) value).name(); else return "Enum.valueOf(" + className + "class, \"" + value + "\")"; } catch (Exception e) { if (((Enum<?>) value).name() != null) return className + ((Enum<?>) value).name(); else return "Enum.valueOf(" + className + "class /* " + e + " */, \"" + value + "\")"; // return className + "valueOf(\"" + value + "\")"; } } else if (value.getClass().equals(Boolean.class)) { return value.toString(); } else { // This should not happen assert (false); return value.toString(); } }
From source file:org.exolab.castor.xml.parsing.primitive.objects.PrimitiveChar.java
@Override public Object getObject(Class<?> type, String value) { if (StringUtils.isNotEmpty(value)) { return Character.valueOf(value.charAt(0)); }// w ww .j av a 2s.c o m return Character.valueOf('\0'); }
From source file:com.alibaba.doris.admin.service.impl.ValueParseUtil.java
/** * ?,?,//from w w w .jav a2 s. c om * * @param clazz * @return */ @SuppressWarnings("unchecked") private static <T> T getInternalDefaultValue(Class<T> clazz) { if (!clazz.isPrimitive()) { return null; } if (Short.TYPE.equals(clazz)) { return (T) Short.valueOf((short) 0); } if (Integer.TYPE.equals(clazz)) { return (T) Integer.valueOf(0); } if (Long.TYPE.equals(clazz)) { return (T) Long.valueOf(0); } if (Boolean.TYPE.equals(clazz)) { return (T) Boolean.valueOf(false); } if (Float.TYPE.equals(clazz)) { return (T) Float.valueOf(0); } if (Double.TYPE.equals(clazz)) { return (T) Double.valueOf(0); } if (Byte.TYPE.equals(clazz)) { return (T) Byte.valueOf((byte) 0); } if (Character.TYPE.equals(clazz)) { return (T) Character.valueOf('\0'); } return null; }
From source file:org.ext4spring.parameter.converter.simple.CharacterConverter.java
@Override public <T> T toTypedValue(String stringValue, Class<T> type) { return (stringValue != null) ? type.cast(Character.valueOf(stringValue.charAt(0))) : null; }
From source file:com.glaf.jbpm.util.CustomFieldInstantiator.java
public static Object getValue(Class<?> type, Element propertyElement) { Object value = null;//from w w w.ja v a 2 s . c o m if (type == String.class) { value = propertyElement.getText(); } else if ((type == Integer.class) || (type == int.class)) { value = Integer.parseInt(propertyElement.getTextTrim()); } else if ((type == Long.class) || (type == long.class)) { value = Long.parseLong(propertyElement.getTextTrim()); } else if ((type == Float.class) || (type == float.class)) { value = new Float(propertyElement.getTextTrim()); } else if ((type == Double.class) || (type == double.class)) { value = Double.parseDouble(propertyElement.getTextTrim()); } else if ((type == Boolean.class) || (type == boolean.class)) { value = Boolean.valueOf(propertyElement.getTextTrim()); } else if ((type == Character.class) || (type == char.class)) { value = Character.valueOf(propertyElement.getTextTrim().charAt(0)); } else if ((type == Short.class) || (type == short.class)) { value = Short.valueOf(propertyElement.getTextTrim()); } else if ((type == Byte.class) || (type == byte.class)) { value = Byte.valueOf(propertyElement.getTextTrim()); } else if (type.isAssignableFrom(java.util.Date.class)) { value = DateUtils.toDate(propertyElement.getTextTrim()); } else if (type.isAssignableFrom(List.class)) { value = getCollectionValue(propertyElement, new java.util.ArrayList<Object>()); } else if (type.isAssignableFrom(Set.class)) { value = getCollectionValue(propertyElement, new LinkedHashSet<Object>()); } else if (type.isAssignableFrom(Collection.class)) { value = getCollectionValue(propertyElement, new java.util.ArrayList<Object>()); } else if (type.isAssignableFrom(Map.class)) { value = getMapValue(propertyElement, new LinkedHashMap<Object, Object>()); } else if (type == Element.class) { value = propertyElement; } else { try { Constructor<?> constructor = type.getConstructor(new Class[] { String.class }); if ((propertyElement.isTextOnly()) && (constructor != null)) { value = constructor.newInstance(new Object[] { propertyElement.getTextTrim() }); } } catch (Exception ex) { logger.error("couldn't parse the bean property value '" + propertyElement.asXML() + "' to a '" + type.getName() + "'"); throw new RuntimeException(ex); } } return value; }
From source file:org.talend.components.processing.runtime.filterrow.TypeConverterUtils.java
public static Character parseToCharacter(Object value) { if (value == null) { return null; }//from ww w. ja v a 2 s . com if (value instanceof Character) { return (Character) value; } else { return Character.valueOf(value.toString().charAt(0)); } }
From source file:Main.java
/** * <p>Converts an array of primitive chars to objects.</p> * * <p>This method returns {@code null} for a {@code null} input array.</p> * * @param array a {@code char} array/*w ww.j a v a 2 s. c o m*/ * @return a {@code Character} array, {@code null} if null array input */ public static Character[] toObject(char[] array) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_CHARACTER_OBJECT_ARRAY; } final Character[] result = new Character[array.length]; for (int i = 0; i < array.length; i++) { result[i] = Character.valueOf(array[i]); } return result; }
From source file:Main.java
/** * <p>Converts an array of primitive chars to objects.</p> * * <p>This method returns {@code null} for a {@code null} input array.</p> * * @param array a {@code char} array/*from w w w .j a v a 2 s .c o m*/ * @return a {@code Character} array, {@code null} if null array input */ public static Character[] toObject(final char[] array) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_CHARACTER_OBJECT_ARRAY; } final Character[] result = new Character[array.length]; for (int i = 0; i < array.length; i++) { result[i] = Character.valueOf(array[i]); } return result; }