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.ms.commons.summer.web.util.json.JsonNumberMorpher.java
/** * Creates a new morpher for the target type with a default value.<br> * The defaultValue should be of the same class as the target type. * /*from w ww .j a v a 2 s . c o m*/ * @param type must be a primitive or wrapper type. BigDecimal and BigInteger are also supported. * @param defaultValue return value if the value to be morphed is null */ public JsonNumberMorpher(Class<?> type, Number defaultValue) { super(true); if (type == null) { throw new MorphException("Must specify a type"); } if (type != Byte.TYPE && type != Short.TYPE && type != Integer.TYPE && type != Long.TYPE && type != Float.TYPE && type != Double.TYPE && !Byte.class.isAssignableFrom(type) && !Short.class.isAssignableFrom(type) && !Integer.class.isAssignableFrom(type) && !Long.class.isAssignableFrom(type) && !Float.class.isAssignableFrom(type) && !Double.class.isAssignableFrom(type) && !BigInteger.class.isAssignableFrom(type) && !BigDecimal.class.isAssignableFrom(type)) { throw new MorphException("Must specify a Number subclass"); } this.type = type; }
From source file:org.seasar.mayaa.impl.util.ObjectUtil.java
protected static Class loadPrimitiveClass(String className) { if (StringUtil.isEmpty(className)) { throw new IllegalArgumentException(); }/*from w ww. j a va 2s . c o m*/ if ("short".equals(className)) { return Short.TYPE; } else if ("int".equals(className)) { return Integer.TYPE; } else if ("long".equals(className)) { return Long.TYPE; } else if ("float".equals(className)) { return Float.TYPE; } else if ("double".equals(className)) { return Double.TYPE; } else if ("byte".equals(className)) { return Byte.TYPE; } else if ("char".equals(className)) { return Character.TYPE; } else if ("boolean".equals(className)) { return Boolean.TYPE; } else if ("void".equals(className)) { return Void.TYPE; } return null; }
From source file:foundation.stack.datamill.configuration.impl.Classes.java
public static boolean isAssignable(Class<?> clazz, final Class<?> toClass) { if (toClass == null) { return false; }/* w w w.j a v a2s . c om*/ if (clazz == null) { return !toClass.isPrimitive(); } if (clazz.isPrimitive() && !toClass.isPrimitive()) { clazz = primitiveToWrapper(clazz); if (clazz == null) { return false; } } if (toClass.isPrimitive() && !clazz.isPrimitive()) { clazz = wrapperToPrimitive(clazz); if (clazz == null) { return false; } } if (clazz.equals(toClass)) { return true; } if (clazz.isPrimitive()) { if (!toClass.isPrimitive()) { return false; } if (Integer.TYPE.equals(clazz)) { return Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Long.TYPE.equals(clazz)) { return Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Boolean.TYPE.equals(clazz)) { return false; } if (Double.TYPE.equals(clazz)) { return false; } if (Float.TYPE.equals(clazz)) { return Double.TYPE.equals(toClass); } if (Character.TYPE.equals(clazz)) { return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Short.TYPE.equals(clazz)) { return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Byte.TYPE.equals(clazz)) { return Short.TYPE.equals(toClass) || Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } // should never get here return false; } return toClass.isAssignableFrom(clazz); }
From source file:net.sf.qooxdoo.rpc.RemoteCallUtils.java
/** * Converts JSON types to "normal" java types. * * @param obj the object to convert (must not be * <code>null</code>, but can be * <code>JSONObject.NULL</code>). * @param targetType the desired target type (must not be * <code>null</code>). * * @return the converted object.// w w w . j a v a2s. c om * * @exception IllegalArgumentException thrown if the desired * conversion is not possible. */ public Object toJava(Object obj, Class targetType) { try { if (obj == JSONObject.NULL) { if (targetType == Integer.TYPE || targetType == Double.TYPE || targetType == Boolean.TYPE || targetType == Long.TYPE || targetType == Float.TYPE) { // null does not work for primitive types throw new Exception(); } return null; } if (obj instanceof JSONArray) { Class componentType; if (targetType == null || targetType == Object.class) { componentType = null; } else { componentType = targetType.getComponentType(); } JSONArray jsonArray = (JSONArray) obj; int length = jsonArray.length(); Object retVal = Array.newInstance((componentType == null ? Object.class : componentType), length); for (int i = 0; i < length; ++i) { Array.set(retVal, i, toJava(jsonArray.get(i), componentType)); } return retVal; } if (obj instanceof JSONObject) { JSONObject jsonObject = (JSONObject) obj; JSONArray names = jsonObject.names(); if (targetType == Map.class || targetType == HashMap.class || targetType == null || targetType == Object.class) { HashMap retVal = new HashMap(); if (names != null) { int length = names.length(); String name; for (int i = 0; i < length; ++i) { name = names.getString(i); retVal.put(name, toJava(jsonObject.get(name), null)); } } return retVal; } Object bean; String requestedTypeName = jsonObject.optString("class", null); if (requestedTypeName != null) { Class clazz = resolveClassHint(requestedTypeName, targetType); if (clazz == null || !targetType.isAssignableFrom(clazz)) { throw new Exception(); } bean = clazz.newInstance(); // TODO: support constructor parameters } else { bean = targetType.newInstance(); } if (names != null) { int length = names.length(); String name; PropertyDescriptor desc; for (int i = 0; i < length; ++i) { name = names.getString(i); if (!"class".equals(name)) { desc = PropertyUtils.getPropertyDescriptor(bean, name); if (desc != null && desc.getWriteMethod() != null) { PropertyUtils.setSimpleProperty(bean, name, toJava(jsonObject.get(name), desc.getPropertyType())); } } } } return bean; } if (targetType == null || targetType == Object.class) { return obj; } Class actualTargetType; Class sourceType = obj.getClass(); if (targetType == Integer.TYPE) { actualTargetType = Integer.class; } else if (targetType == Boolean.TYPE) { actualTargetType = Boolean.class; } else if ((targetType == Double.TYPE || targetType == Double.class) && Number.class.isAssignableFrom(sourceType)) { return new Double(((Number) obj).doubleValue()); // TODO: maybe return obj directly if it's a Double } else if ((targetType == Float.TYPE || targetType == Float.class) && Number.class.isAssignableFrom(sourceType)) { return new Float(((Number) obj).floatValue()); } else if ((targetType == Long.TYPE || targetType == Long.class) && Number.class.isAssignableFrom(sourceType)) { return new Long(((Number) obj).longValue()); } else { actualTargetType = targetType; } if (!actualTargetType.isAssignableFrom(sourceType)) { throw new Exception(); } return obj; } catch (IllegalArgumentException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Cannot convert " + (obj == null ? null : obj.getClass().getName()) + " to " + (targetType == null ? null : targetType.getName())); } }
From source file:Main.java
private static boolean isAssignableFrom(Class<?> parameterType, Object value) { if (parameterType.isPrimitive()) { if (value == null) { return false; }//from w ww . j av a2 s . com Class<?> valueClass = value.getClass(); if (parameterType == Boolean.TYPE) { return valueClass == Boolean.class; } else if (parameterType == Byte.TYPE) { return valueClass == Byte.class; } else if (parameterType == Character.TYPE) { return valueClass == Character.class; } else if (parameterType == Short.TYPE) { return valueClass == Short.class || valueClass == Byte.class; } else if (parameterType == Integer.TYPE) { return valueClass == Integer.class || valueClass == Character.class || valueClass == Short.class || valueClass == Byte.class; } else if (parameterType == Long.TYPE) { return valueClass == Long.class || valueClass == Integer.class || valueClass == Character.class || valueClass == Short.class || valueClass == Byte.class; } else if (parameterType == Float.TYPE) { return valueClass == Float.class || valueClass == Long.class || valueClass == Integer.class || valueClass == Character.class || valueClass == Short.class || valueClass == Byte.class; } else if (parameterType == Double.TYPE) { return valueClass == Double.class || valueClass == Float.class || valueClass == Long.class || valueClass == Integer.class || valueClass == Character.class || valueClass == Short.class || valueClass == Byte.class; } else { return false; } } else { return value == null || parameterType.isAssignableFrom(value.getClass()); } }
From source file:com.puppycrawl.tools.checkstyle.api.AutomaticBean.java
/** * Creates a BeanUtilsBean that is configured to use * type converters that throw a ConversionException * instead of using the default value when something * goes wrong./*from ww w. jav a2 s . c o m*/ * * @return a configured BeanUtilsBean */ private static BeanUtilsBean createBeanUtilsBean() { final ConvertUtilsBean cub = new ConvertUtilsBean(); cub.register(new BooleanConverter(), Boolean.TYPE); cub.register(new BooleanConverter(), Boolean.class); cub.register(new ArrayConverter(boolean[].class, new BooleanConverter()), boolean[].class); cub.register(new ByteConverter(), Byte.TYPE); cub.register(new ByteConverter(), Byte.class); cub.register(new ArrayConverter(byte[].class, new ByteConverter()), byte[].class); cub.register(new CharacterConverter(), Character.TYPE); cub.register(new CharacterConverter(), Character.class); cub.register(new ArrayConverter(char[].class, new CharacterConverter()), char[].class); cub.register(new DoubleConverter(), Double.TYPE); cub.register(new DoubleConverter(), Double.class); cub.register(new ArrayConverter(double[].class, new DoubleConverter()), double[].class); cub.register(new FloatConverter(), Float.TYPE); cub.register(new FloatConverter(), Float.class); cub.register(new ArrayConverter(float[].class, new FloatConverter()), float[].class); cub.register(new IntegerConverter(), Integer.TYPE); cub.register(new IntegerConverter(), Integer.class); cub.register(new ArrayConverter(int[].class, new IntegerConverter()), int[].class); cub.register(new LongConverter(), Long.TYPE); cub.register(new LongConverter(), Long.class); cub.register(new ArrayConverter(long[].class, new LongConverter()), long[].class); cub.register(new ShortConverter(), Short.TYPE); cub.register(new ShortConverter(), Short.class); cub.register(new ArrayConverter(short[].class, new ShortConverter()), short[].class); cub.register(new RelaxedStringArrayConverter(), String[].class); // BigDecimal, BigInteger, Class, Date, String, Time, TimeStamp // do not use defaults in the default configuration of ConvertUtilsBean return new BeanUtilsBean(cub, new PropertyUtilsBean()); }
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 w w w .java 2s.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; }
From source file:org.polymap.p4.process.CoordinateSupplier.java
@Override public boolean init(@SuppressWarnings("hiding") FieldViewerSite site) { if (super.init(site)) { Optional<UI> uiHint = site.fieldInfo.get().annotation(UI.class); if (uiHint.isPresent()) { String v = uiHint.get().value(); if (JGTConstants.EASTING_UI_HINT.equals(v) || JGTConstants.NORTHING_UI_HINT.equals(v)) { Class<?> fieldType = site.fieldInfo.get().type.get(); if (Double.class.isAssignableFrom(fieldType) || Double.TYPE.equals(fieldType)) { return true; }/*from w w w. jav a2 s .co m*/ } } } return false; }
From source file:org.apache.hadoop.metrics2.lib.MethodMetric.java
static boolean isDouble(Class<?> type) { return type == Double.TYPE || type == Double.class; }
From source file:org.briljantframework.data.vector.Convert.java
@SuppressWarnings("unchecked") private static <T> T convertNumber(Class<T> cls, Number num) { if (cls.equals(Double.class) || cls.equals(Double.TYPE)) { return (T) (Double) num.doubleValue(); } else if (cls.equals(Float.class) || cls.equals(Float.TYPE)) { return (T) (Float) num.floatValue(); } else if (cls.equals(Long.class) || cls.equals(Long.TYPE)) { return (T) (Long) num.longValue(); } else if (cls.equals(Integer.class) || cls.equals(Integer.TYPE)) { return (T) (Integer) num.intValue(); } else if (cls.equals(Short.class) || cls.equals(Short.TYPE)) { return (T) (Short) num.shortValue(); } else if (cls.equals(Byte.class) || cls.equals(Byte.TYPE)) { return (T) (Byte) num.byteValue(); } else if (Complex.class.equals(cls)) { return cls.cast(Complex.valueOf(num.doubleValue())); } else if (Logical.class.equals(cls)) { return cls.cast(num.intValue() == 1 ? Logical.TRUE : Logical.FALSE); } else if (Boolean.class.equals(cls)) { return cls.cast(num.intValue() == 1); } else {/* w w w. ja va2 s . co m*/ return Na.of(cls); } }