List of usage examples for java.lang Double TYPE
Class TYPE
To view the source code for java.lang Double TYPE.
Click Source Link
From source file:com.examples.with.different.packagename.testcarver.AbstractConverter.java
/** * Change primitve Class types to the associated wrapper class. * @param type The class type to check./*from w w w .j a v a2s.co m*/ * @return The converted type. */ Class primitive(Class type) { if (type == null || !type.isPrimitive()) { return type; } if (type == Integer.TYPE) { return Integer.class; } else if (type == Double.TYPE) { return Double.class; } else if (type == Long.TYPE) { return Long.class; } else if (type == Boolean.TYPE) { return Boolean.class; } else if (type == Float.TYPE) { return Float.class; } else if (type == Short.TYPE) { return Short.class; } else if (type == Byte.TYPE) { return Byte.class; } else if (type == Character.TYPE) { return Character.class; } else { return type; } }
From source file:org.openlegacy.db.mvc.rest.DefaultDbRestController.java
private static Object toObject(Class<?> clazz, String value) { if (Boolean.class == clazz || Boolean.TYPE == clazz) { return Boolean.parseBoolean(value); }//from www .j a v a 2s .c o m if (Byte.class == clazz || Byte.TYPE == clazz) { return Byte.parseByte(value); } if (Short.class == clazz || Short.TYPE == clazz) { return Short.parseShort(value); } if (Integer.class == clazz || Integer.TYPE == clazz) { return Integer.parseInt(value); } if (Long.class == clazz || Long.TYPE == clazz) { return Long.parseLong(value); } if (Float.class == clazz || Float.TYPE == clazz) { return Float.parseFloat(value); } if (Double.class == clazz || Double.TYPE == clazz) { return Double.parseDouble(value); } return value; }
From source file:com.phoenixnap.oss.ramlapisync.naming.SchemaHelper.java
/** * Maps primitives and other simple Java types into simple types supported by RAML * /* ww w. ja v a 2 s .c om*/ * @param clazz The Class to map * @return The Simple RAML ParamType which maps to this class or null if one is not found */ public static ParamType mapSimpleType(Class<?> clazz) { Class<?> targetClazz = clazz; if (targetClazz.isArray() && clazz.getComponentType() != null) { targetClazz = clazz.getComponentType(); } if (targetClazz.equals(Long.TYPE) || targetClazz.equals(Long.class) || targetClazz.equals(Integer.TYPE) || targetClazz.equals(Integer.class) || targetClazz.equals(Short.TYPE) || targetClazz.equals(Short.class) || targetClazz.equals(Byte.TYPE) || targetClazz.equals(Byte.class)) { return ParamType.INTEGER; } else if (targetClazz.equals(Float.TYPE) || targetClazz.equals(Float.class) || targetClazz.equals(Double.TYPE) || targetClazz.equals(Double.class) || targetClazz.equals(BigDecimal.class)) { return ParamType.NUMBER; } else if (targetClazz.equals(Boolean.class) || targetClazz.equals(Boolean.TYPE)) { return ParamType.BOOLEAN; } else if (targetClazz.equals(String.class)) { return ParamType.STRING; } return null; // default to string }
From source file:org.brekka.stillingar.spring.bpp.ConfigurationBeanPostProcessorTest.java
@Test public void primitiveDefaultDouble() { assertEquals(ConfigurationBeanPostProcessor.primitiveDefault(Double.TYPE), Double.valueOf(0d)); }
From source file:android.reflect.ClazzLoader.java
/** * ????//w w w. j a v a 2s . c o m */ public static <O, V> void setFieldValue(O o, Field field, V v) { if (field != null) { try { field.setAccessible(true); if (v == null) { field.set(o, null); } else { Class<?> vType = v.getClass(); if (vType == Integer.TYPE) { field.setInt(o, (Integer) v); } else if (vType == Long.TYPE) { field.setLong(o, (Long) v); } else if (vType == Boolean.TYPE) { field.setBoolean(o, (Boolean) v); } else if (vType == Float.TYPE) { field.setFloat(o, (Float) v); } else if (vType == Short.TYPE) { field.setShort(o, (Short) v); } else if (vType == Byte.TYPE) { field.setByte(o, (Byte) v); } else if (vType == Double.TYPE) { field.setDouble(o, (Double) v); } else if (vType == Character.TYPE) { field.setChar(o, (Character) v); } else { field.set(o, v); } } } catch (Throwable t) { Log.e(TAG, t); } } }
From source file:com.gdcn.modules.db.jdbc.processor.CamelBeanProcessor.java
/** * ResultSet.getObject() returns an Integer object for an INT column. The * setter method for the property might take an Integer or a primitive int. * This method returns true if the value can be successfully passed into * the setter method. Remember, Method.invoke() handles the unwrapping * of Integer into an int.//w ww . j a v a2 s . c o m * * @param value The value to be passed into the setter method. * @param type The setter's parameter type (non-null) * @return boolean True if the value is compatible (null => true) */ private boolean isCompatibleType(Object value, Class<?> type) { // Do object check first, then primitives if (value == null || type.isInstance(value)) { return true; } else if (type.equals(Integer.TYPE) && Integer.class.isInstance(value)) { return true; } else if (type.equals(Long.TYPE) && Long.class.isInstance(value)) { return true; } else if (type.equals(Double.TYPE) && Double.class.isInstance(value)) { return true; } else if (type.equals(Float.TYPE) && Float.class.isInstance(value)) { return true; } else if (type.equals(Short.TYPE) && Short.class.isInstance(value)) { return true; } else if (type.equals(Byte.TYPE) && Byte.class.isInstance(value)) { return true; } else if (type.equals(Character.TYPE) && Character.class.isInstance(value)) { return true; } else if (type.equals(Boolean.TYPE) && Boolean.class.isInstance(value)) { return true; } return false; }
From source file:com.mawujun.util.AnnotationUtils.java
/** * Helper method for generating a hash code for an array. * * @param componentType the component type of the array * @param o the array//from www. j a v a2s. co m * @return a hash code for the specified array */ private static int arrayMemberHash(Class<?> componentType, Object o) { if (componentType.equals(Byte.TYPE)) { return Arrays.hashCode((byte[]) o); } if (componentType.equals(Short.TYPE)) { return Arrays.hashCode((short[]) o); } if (componentType.equals(Integer.TYPE)) { return Arrays.hashCode((int[]) o); } if (componentType.equals(Character.TYPE)) { return Arrays.hashCode((char[]) o); } if (componentType.equals(Long.TYPE)) { return Arrays.hashCode((long[]) o); } if (componentType.equals(Float.TYPE)) { return Arrays.hashCode((float[]) o); } if (componentType.equals(Double.TYPE)) { return Arrays.hashCode((double[]) o); } if (componentType.equals(Boolean.TYPE)) { return Arrays.hashCode((boolean[]) o); } return Arrays.hashCode((Object[]) o); }
From source file:at.alladin.rmbt.shared.hstoreparser.HstoreParser.java
/** * //from w w w. jav a 2s .c o m * @param f * @param o * @return */ public static Object parseFieldValue(Field f, Object o) { if (o != JSONObject.NULL) { if (f.getType().equals(Integer.class) || f.getType().equals(Integer.TYPE)) { return Integer.parseInt(String.valueOf(o)); } else if (f.getType().equals(String.class)) { return String.valueOf(o); } else if (f.getType().equals(Long.class) || f.getType().equals(Long.TYPE)) { return Long.parseLong(String.valueOf(o)); } else if (f.getType().equals(Boolean.class) || f.getType().equals(Boolean.TYPE)) { return Boolean.parseBoolean(String.valueOf(o)); } else if (f.getType().equals(Float.class) || f.getType().equals(Float.TYPE)) { return Float.parseFloat(String.valueOf(o)); } else if (f.getType().equals(Double.class) || f.getType().equals(Double.TYPE)) { return Double.parseDouble(String.valueOf(o)); } else if (f.getType().equals(Short.class) || f.getType().equals(Short.TYPE)) { return Short.parseShort(String.valueOf(o)); } else { return o; } } return null; }
From source file:org.lunarray.model.descriptor.scanner.AnnotationMetaModelProcessor.java
/** * Copy array values.//from w ww.j a va 2 s . c o m * * @param values * The array values. * @param name * The property name. * @param obj * The object value. * @param type * The array type. * @param compType * The component type. * @throws MappingException * Thrown if the mapping was unsuccessful. */ private void copyNonDiscreteNumbers(final AnnotationMetaValues values, final String name, final Object obj, final Class<?> type, final Class<?> compType) throws MappingException { try { if (Double.TYPE.equals(compType)) { final double[] array = double[].class.cast(obj); for (final double a : array) { values.getMetaValueList(name).add(this.converterTool.convertToString(Double.TYPE, a)); } } else if (Float.TYPE.equals(compType)) { final float[] array = float[].class.cast(obj); for (final float a : array) { values.getMetaValueList(name).add(this.converterTool.convertToString(Float.TYPE, a)); } } else { this.extractNonFloats(values, name, obj, type, compType); } } catch (final ConverterException e) { throw new MappingException(e); } }
From source file:org.cloudata.core.common.io.CObjectWritable.java
/** Read a {@link CWritable}, {@link String}, primitive type, or an array of * the preceding. *//*from w w w. j a v a2 s . co m*/ @SuppressWarnings("unchecked") public static Object readObject(DataInput in, CObjectWritable objectWritable, CloudataConf conf, boolean arrayComponent, Class componentClass) throws IOException { String className; if (arrayComponent) { className = componentClass.getName(); } else { className = CUTF8.readString(in); //SANGCHUL // System.out.println("SANGCHUL] className:" + className); } Class<?> declaredClass = PRIMITIVE_NAMES.get(className); if (declaredClass == null) { try { declaredClass = conf.getClassByName(className); } catch (ClassNotFoundException e) { //SANGCHUL e.printStackTrace(); throw new RuntimeException("readObject can't find class[className=" + className + "]", e); } } Object instance; if (declaredClass.isPrimitive()) { // primitive types if (declaredClass == Boolean.TYPE) { // boolean instance = Boolean.valueOf(in.readBoolean()); } else if (declaredClass == Character.TYPE) { // char instance = Character.valueOf(in.readChar()); } else if (declaredClass == Byte.TYPE) { // byte instance = Byte.valueOf(in.readByte()); } else if (declaredClass == Short.TYPE) { // short instance = Short.valueOf(in.readShort()); } else if (declaredClass == Integer.TYPE) { // int instance = Integer.valueOf(in.readInt()); } else if (declaredClass == Long.TYPE) { // long instance = Long.valueOf(in.readLong()); } else if (declaredClass == Float.TYPE) { // float instance = Float.valueOf(in.readFloat()); } else if (declaredClass == Double.TYPE) { // double instance = Double.valueOf(in.readDouble()); } else if (declaredClass == Void.TYPE) { // void instance = null; } else { throw new IllegalArgumentException("Not a primitive: " + declaredClass); } } else if (declaredClass.isArray()) { // array //System.out.println("SANGCHUL] is array"); int length = in.readInt(); //System.out.println("SANGCHUL] array length : " + length); //System.out.println("Read:in.readInt():" + length); if (declaredClass.getComponentType() == Byte.TYPE) { byte[] bytes = new byte[length]; in.readFully(bytes); instance = bytes; } else if (declaredClass.getComponentType() == ColumnValue.class) { instance = readColumnValue(in, conf, declaredClass, length); } else { Class componentType = declaredClass.getComponentType(); // SANGCHUL //System.out.println("SANGCHUL] componentType : " + componentType.getName()); instance = Array.newInstance(componentType, length); for (int i = 0; i < length; i++) { Object arrayComponentInstance = readObject(in, null, conf, !componentType.isArray(), componentType); Array.set(instance, i, arrayComponentInstance); //Array.set(instance, i, readObject(in, conf)); } } } else if (declaredClass == String.class) { // String instance = CUTF8.readString(in); } else if (declaredClass.isEnum()) { // enum instance = Enum.valueOf((Class<? extends Enum>) declaredClass, CUTF8.readString(in)); } else if (declaredClass == ColumnValue.class) { //ColumnValue? ?? ?? ? ? ?. //? ? ? ? ? ? . Class instanceClass = null; try { short typeDiff = in.readShort(); if (typeDiff == TYPE_DIFF) { instanceClass = conf.getClassByName(CUTF8.readString(in)); } else { instanceClass = declaredClass; } } catch (ClassNotFoundException e) { throw new RuntimeException("readObject can't find class", e); } ColumnValue columnValue = new ColumnValue(); columnValue.readFields(in); instance = columnValue; } else { // Writable Class instanceClass = null; try { short typeDiff = in.readShort(); // SANGCHUL //System.out.println("SANGCHUL] typeDiff : " + typeDiff); //System.out.println("Read:in.readShort():" + typeDiff); if (typeDiff == TYPE_DIFF) { // SANGCHUL String classNameTemp = CUTF8.readString(in); //System.out.println("SANGCHUL] typeDiff : " + classNameTemp); instanceClass = conf.getClassByName(classNameTemp); //System.out.println("Read:UTF8.readString(in):" + instanceClass.getClass()); } else { instanceClass = declaredClass; } } catch (ClassNotFoundException e) { // SANGCHUL e.printStackTrace(); throw new RuntimeException("readObject can't find class", e); } CWritable writable = CWritableFactories.newInstance(instanceClass, conf); writable.readFields(in); //System.out.println("Read:writable.readFields(in)"); instance = writable; if (instanceClass == NullInstance.class) { // null declaredClass = ((NullInstance) instance).declaredClass; instance = null; } } if (objectWritable != null) { // store values objectWritable.declaredClass = declaredClass; objectWritable.instance = instance; } return instance; }