List of usage examples for java.lang Character TYPE
Class TYPE
To view the source code for java.lang Character TYPE.
Click Source Link
From source file:com.browseengine.bobo.serialize.JSONSerializer.java
private static void loadObject(Object array, Class type, int index, JSONArray jsonArray) throws JSONSerializationException, JSONException { if (type.isPrimitive()) { if (type == Integer.TYPE) { Array.setInt(array, index, jsonArray.getInt(index)); } else if (type == Long.TYPE) { Array.setLong(array, index, jsonArray.getInt(index)); } else if (type == Short.TYPE) { Array.setShort(array, index, (short) jsonArray.getInt(index)); } else if (type == Boolean.TYPE) { Array.setBoolean(array, index, jsonArray.getBoolean(index)); } else if (type == Double.TYPE) { Array.setDouble(array, index, jsonArray.getDouble(index)); } else if (type == Float.TYPE) { Array.setFloat(array, index, (float) jsonArray.getDouble(index)); } else if (type == Character.TYPE) { char ch = jsonArray.getString(index).charAt(0); Array.setChar(array, index, ch); } else if (type == Byte.TYPE) { Array.setByte(array, index, (byte) jsonArray.getInt(index)); } else {//from ww w .j a v a 2 s.c om throw new JSONSerializationException("Unknown primitive: " + type); } } else if (type == String.class) { Array.set(array, index, jsonArray.getString(index)); } else if (JSONSerializable.class.isAssignableFrom(type)) { JSONObject jObj = jsonArray.getJSONObject(index); JSONSerializable serObj = deSerialize(type, jObj); Array.set(array, index, serObj); } else if (type.isArray()) { Class componentClass = type.getComponentType(); JSONArray subArray = jsonArray.getJSONArray(index); int len = subArray.length(); Object newArray = Array.newInstance(componentClass, len); for (int k = 0; k < len; ++k) { loadObject(newArray, componentClass, k, subArray); } } }
From source file:org.dhatim.javabean.BeanUtils.java
/** * Create the bean setter method instance for this visitor. * * @param setterName The setter method name. * @param setterParamType//from www. j ava2 s . c o m * @return The bean setter method. */ public static Method createSetterMethod(String setterName, Object bean, Class<?> setterParamType) { Method beanSetterMethod = ClassUtil.getSetterMethod(setterName, bean, setterParamType); // Try it as a list... if (beanSetterMethod == null && List.class.isAssignableFrom(setterParamType)) { String setterNamePlural = setterName + "s"; // Try it as a List using the plural name... beanSetterMethod = ClassUtil.getSetterMethod(setterNamePlural, bean, setterParamType); if (beanSetterMethod == null) { // Try it as an array using the non-plural name... } } // Try it as a primitive... if (beanSetterMethod == null && Integer.class.isAssignableFrom(setterParamType)) { beanSetterMethod = ClassUtil.getSetterMethod(setterName, bean, Integer.TYPE); } if (beanSetterMethod == null && Long.class.isAssignableFrom(setterParamType)) { beanSetterMethod = ClassUtil.getSetterMethod(setterName, bean, Long.TYPE); } if (beanSetterMethod == null && Float.class.isAssignableFrom(setterParamType)) { beanSetterMethod = ClassUtil.getSetterMethod(setterName, bean, Float.TYPE); } if (beanSetterMethod == null && Double.class.isAssignableFrom(setterParamType)) { beanSetterMethod = ClassUtil.getSetterMethod(setterName, bean, Double.TYPE); } if (beanSetterMethod == null && Character.class.isAssignableFrom(setterParamType)) { beanSetterMethod = ClassUtil.getSetterMethod(setterName, bean, Character.TYPE); } if (beanSetterMethod == null && Short.class.isAssignableFrom(setterParamType)) { beanSetterMethod = ClassUtil.getSetterMethod(setterName, bean, Short.TYPE); } if (beanSetterMethod == null && Byte.class.isAssignableFrom(setterParamType)) { beanSetterMethod = ClassUtil.getSetterMethod(setterName, bean, Byte.TYPE); } if (beanSetterMethod == null && Boolean.class.isAssignableFrom(setterParamType)) { beanSetterMethod = ClassUtil.getSetterMethod(setterName, bean, Boolean.TYPE); } return beanSetterMethod; }
From source file:Main.java
/** * <p>Inserts the specified element at the specified position in the array. * Shifts the element currently at that position (if any) and any subsequent * elements to the right (adds one to their indices).</p> * * <p>This method returns a new array with the same elements of the input * array plus the given element on the specified position. The component * type of the returned array is always the same as that of the input * array.</p>//ww w . ja va 2 s . c om * * <p>If the input array is <code>null</code>, a new one element array is returned * whose component type is the same as the element.</p> * * <pre> * ArrayUtils.add(null, 0, 'a') = ['a'] * ArrayUtils.add(['a'], 0, 'b') = ['b', 'a'] * ArrayUtils.add(['a', 'b'], 0, 'c') = ['c', 'a', 'b'] * ArrayUtils.add(['a', 'b'], 1, 'k') = ['a', 'k', 'b'] * ArrayUtils.add(['a', 'b', 'c'], 1, 't') = ['a', 't', 'b', 'c'] * </pre> * * @param array the array to add the element to, may be <code>null</code> * @param index the position of the new object * @param element the object to add * @return A new array containing the existing elements and the new element * @throws IndexOutOfBoundsException if the index is out of range * (index < 0 || index > array.length). */ public static char[] add(char[] array, int index, char element) { return (char[]) add(array, index, new Character(element), Character.TYPE); }
From source file:org.lunarray.model.descriptor.util.PrimitiveUtil.java
/** * Default constructor./*from www . j av a 2 s . c om*/ */ private PrimitiveUtil() { this.primitivesToClasses = new HashMap<Class<?>, Class<?>>(); this.primitivesToClasses.put(Byte.TYPE, Byte.class); this.primitivesToClasses.put(Integer.TYPE, Integer.class); this.primitivesToClasses.put(Double.TYPE, Double.class); this.primitivesToClasses.put(Float.TYPE, Float.class); this.primitivesToClasses.put(Long.TYPE, Long.class); this.primitivesToClasses.put(Short.TYPE, Short.class); this.primitivesToClasses.put(Character.TYPE, Character.class); this.primitivesToClasses.put(Boolean.TYPE, Boolean.class); }
From source file:com.bedatadriven.rebar.persistence.mapping.PrimitiveMapping.java
public PrimitiveMapping(MethodInfo getter) { super(getter); TypeInfo type = getter.getReturnType(); Class primitive = type.isPrimitive(); this.boxed = (primitive == null); if (primitive != null) { this.nullable = false; }//from w ww.j av a 2s .c om if (primitive == Integer.TYPE || type.getQualifiedName().equals(Integer.class.getName()) || primitive == Short.TYPE || type.getQualifiedName().equals(Short.class.getName()) || primitive == Long.TYPE || type.getQualifiedName().equals(Long.class.getName()) || primitive == Byte.TYPE || type.getQualifiedName().equals(Byte.class.getName()) || primitive == Boolean.TYPE || type.getQualifiedName().equals(Boolean.class.getName())) { sqlTypeName = SqliteTypes.integer; } else if (primitive == Float.TYPE || type.getQualifiedName().equals(Float.class.getName()) || primitive == Double.TYPE || type.getQualifiedName().equals(Double.class.getName())) { sqlTypeName = SqliteTypes.real; } else if (primitive == Character.TYPE || type.getQualifiedName().equals(Character.class.getName())) { sqlTypeName = SqliteTypes.text; } String suffix = type.getSimpleName(); if (suffix.equals("Integer")) { suffix = "Int"; } else if (suffix.equals("Character")) { suffix = "Char"; } suffix = suffix.substring(0, 1).toUpperCase() + suffix.substring(1); readerName = "Readers.read" + suffix; stmtSetter = "set" + suffix; }
From source file:Main.java
/** * This method converts a given number into a target class. This method does not change the value (except when * explicitly casting to a more general type, e.g. from double to int), just the internal type representation. While * this is unnecessary while using normal java code, reflection based access to method parameters is a bit more * difficult. As far as possible, this method will prevent the ArgumentMismatch error when passing numbers as * parameters./*from ww w. j ava 2 s . co m*/ * <p/> * If the value can not be converted to the given target class, it will be returned unchanged. * * @param targetClass Class to which the number should be converted, if possible. * @param value Number value to convert. * @return 'value' converted to an instance of 'targetClass'. */ public static Object convertNumber(final Class targetClass, final Number value) { if (targetClass.equals(Double.class) || targetClass.equals(Double.TYPE)) return value.doubleValue(); if (targetClass.equals(Integer.class) || targetClass.equals(Integer.TYPE)) return value.intValue(); if (targetClass.equals(Long.class) || targetClass.equals(Long.TYPE)) return value.longValue(); if (targetClass.equals(Short.class) || targetClass.equals(Short.TYPE)) return value.shortValue(); if (targetClass.equals(Byte.class) || targetClass.equals(Byte.TYPE)) return value.byteValue(); if (targetClass.equals(Character.class) || targetClass.equals(Character.TYPE)) return value.intValue(); if (targetClass.equals(Float.class) || targetClass.equals(Float.TYPE)) return value.floatValue(); return value; }
From source file:org.exolab.castor.xml.parsing.primitive.objects.PrimitiveObjectFactory.java
private PrimitiveObjectFactory() { typeHandlers.put(String.class, PrimitiveString.class); typeHandlers.put(Enum.class, PrimitiveEnum.class); typeHandlers.put(Integer.TYPE, PrimitiveInteger.class); typeHandlers.put(Integer.class, PrimitiveInteger.class); typeHandlers.put(Boolean.TYPE, PrimitiveBoolean.class); typeHandlers.put(Boolean.class, PrimitiveBoolean.class); typeHandlers.put(Double.TYPE, PrimitiveDouble.class); typeHandlers.put(Double.class, PrimitiveDouble.class); typeHandlers.put(Long.TYPE, PrimitiveLong.class); typeHandlers.put(Long.class, PrimitiveLong.class); typeHandlers.put(Character.TYPE, PrimitiveChar.class); typeHandlers.put(Character.class, PrimitiveChar.class); typeHandlers.put(Short.TYPE, PrimitiveShort.class); typeHandlers.put(Short.class, PrimitiveShort.class); typeHandlers.put(Float.TYPE, PrimitiveFloat.class); typeHandlers.put(Float.class, PrimitiveFloat.class); typeHandlers.put(Byte.TYPE, PrimitiveByte.class); typeHandlers.put(Byte.class, PrimitiveByte.class); typeHandlers.put(BigInteger.class, PrimitiveBigInteger.class); typeHandlers.put(BigDecimal.class, PrimitiveBigDecimal.class); }
From source file:com.base.dao.sql.ReflectionUtils.java
public static Object convertValue(Object value, Class toType) { Object result = null;//from w ww .j av a 2s. c o m if (value != null) { if (value.getClass().isArray() && toType.isArray()) { Class componentType = toType.getComponentType(); result = Array.newInstance(componentType, Array.getLength(value)); for (int i = 0, icount = Array.getLength(value); i < icount; i++) { Array.set(result, i, convertValue(Array.get(value, i), componentType)); } } else { if ((toType == Integer.class) || (toType == Integer.TYPE)) result = Integer.valueOf((int) longValue(value)); if ((toType == Double.class) || (toType == Double.TYPE)) result = new Double(doubleValue(value)); if ((toType == Boolean.class) || (toType == Boolean.TYPE)) result = booleanValue(value) ? Boolean.TRUE : Boolean.FALSE; if ((toType == Byte.class) || (toType == Byte.TYPE)) result = Byte.valueOf((byte) longValue(value)); if ((toType == Character.class) || (toType == Character.TYPE)) result = new Character((char) longValue(value)); if ((toType == Short.class) || (toType == Short.TYPE)) result = Short.valueOf((short) longValue(value)); if ((toType == Long.class) || (toType == Long.TYPE)) result = Long.valueOf(longValue(value)); if ((toType == Float.class) || (toType == Float.TYPE)) result = new Float(doubleValue(value)); if (toType == BigInteger.class) result = bigIntValue(value); if (toType == BigDecimal.class) result = bigDecValue(value); if (toType == String.class) result = stringValue(value); if (toType == Date.class) { result = DateUtils.toDate(stringValue(value)); } if (Enum.class.isAssignableFrom(toType)) result = enumValue((Class<Enum>) toType, value); } } else { if (toType.isPrimitive()) { result = primitiveDefaults.get(toType); } } return result; }
From source file:it.greenvulcano.gvesb.http.ProtocolFactory.java
/** * * @param objectClass/*from w ww . jav a 2 s . c om*/ * Object class to instantiate * @param node * The configuration of constructor parameters. * @return */ private static Object createObjectUsingConstructor(Class<?> objectClass, Node node) throws Exception { NodeList paramList = XMLConfig.getNodeList(node, "constructor-param"); Class<?>[] types = new Class[paramList.getLength()]; Object[] params = new Object[types.length]; for (int i = 0; i < types.length; ++i) { Node paramNode = paramList.item(i); String type = XMLConfig.get(paramNode, "@type"); String value = XMLConfig.getDecrypted(paramNode, "@value"); Class<?> cls = null; if (type.equals("byte")) { cls = Byte.TYPE; } else if (type.equals("boolean")) { cls = Boolean.TYPE; } else if (type.equals("char")) { cls = Character.TYPE; } else if (type.equals("double")) { cls = Double.TYPE; } else if (type.equals("float")) { cls = Float.TYPE; } else if (type.equals("int")) { cls = Integer.TYPE; } else if (type.equals("long")) { cls = Long.TYPE; } else if (type.equals("short")) { cls = Short.TYPE; } else if (type.equals("String")) { cls = String.class; } types[i] = cls; params[i] = cast(value, cls); } Constructor<?> constr = objectClass.getConstructor(types); return constr.newInstance(params); }
From source file:com.nfwork.dbfound.json.JSONDynaBean.java
public Object get(String name) { Object value = dynaValues.get(name); if (value != null) { return value; }//from ww w . ja v a 2 s.c o m Class type = getDynaProperty(name).getType(); if (type == null) { throw new NullPointerException("Unspecified property type for " + name); } if (!type.isPrimitive()) { return value; } if (type == Boolean.TYPE) { return Boolean.FALSE; } else if (type == Byte.TYPE) { return new Byte((byte) 0); } else if (type == Character.TYPE) { return new Character((char) 0); } else if (type == Short.TYPE) { return new Short((short) 0); } else if (type == Integer.TYPE) { return new Integer(0); } else if (type == Long.TYPE) { return new Long(0); } else if (type == Float.TYPE) { return new Float(0.0); } else if (type == Double.TYPE) { return new Double(0); } return null; }