Example usage for java.lang Float TYPE

List of usage examples for java.lang Float TYPE

Introduction

In this page you can find the example usage for java.lang Float TYPE.

Prototype

Class TYPE

To view the source code for java.lang Float TYPE.

Click Source Link

Document

The Class instance representing the primitive type float .

Usage

From source file:org.seasar.mayaa.impl.util.ObjectUtil.java

protected static Class loadPrimitiveClass(String className) {
    if (StringUtil.isEmpty(className)) {
        throw new IllegalArgumentException();
    }/*  w  w w  .  ja v  a  2  s .  co 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: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.
 * //  w  w w .j  a v a 2s  .com
 * @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:foundation.stack.datamill.configuration.impl.Classes.java

public static boolean isAssignable(Class<?> clazz, final Class<?> toClass) {
    if (toClass == null) {
        return false;
    }//from   w  w  w.jav a  2  s .c o  m

    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:com.base.dao.sql.ReflectionUtils.java

public static Object convertValue(Object value, Class toType) {
    Object result = null;/*from   w  w  w.  ja v  a  2  s . 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:com.nfwork.dbfound.json.JSONDynaBean.java

public Object get(String name) {
    Object value = dynaValues.get(name);
    if (value != null) {
        return value;
    }//from   w  ww .  j a  va2s.co 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: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./*from  w  w  w .  j a  v a 2s .c  o  m*/
 *
 * @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:org.apache.hadoop.metrics2.lib.MethodMetric.java

static boolean isFloat(Class<?> type) {
    return type == Float.TYPE || type == Float.class;
}

From source file:org.wings.template.DefaultPropertyValueConverter.java

/**
 * Describe <code>convertPropertyValue</code> method here.
 *
 * @param value       an <code>Object</code> value
 * @param targetClass a <code>Class</code> value
 * @return <description>/*from  ww  w .  j  av  a 2 s . co  m*/
 * @throws UnsupportedOperationException if an error occurs
 * @throws java.lang.UnsupportedOperationException
 *                                       <description>
 */
public Object convertPropertyValue(String value, Class targetClass) throws UnsupportedOperationException {
    if (value == null || "null".equals(value)) {
        return null;
    } // end of if ()

    if (targetClass == String.class) {
        return value;
    } // end of if ()

    if (targetClass == Boolean.TYPE || targetClass == Boolean.class) {
        return Boolean.valueOf(value);
    }

    if (targetClass == Integer.TYPE || targetClass == Integer.class) {
        return Integer.valueOf(value);
    }
    if (targetClass == Long.TYPE || targetClass == Long.class) {
        return Long.valueOf(value);
    }
    if (targetClass == Short.TYPE || targetClass == Short.class) {
        return Short.valueOf(value);
    }
    if (targetClass == Byte.TYPE || targetClass == Byte.class) {
        return Byte.valueOf(value);
    }
    if (targetClass == Float.TYPE || targetClass == Float.class) {
        return Float.valueOf(value);
    }
    if (targetClass == Double.TYPE || targetClass == Double.class) {
        return Double.valueOf(value);
    }
    if (targetClass == Character.TYPE || targetClass == Character.class) {
        return new Character(value.charAt(0));
    }

    if (targetClass == StringBuffer.class) {
        return new StringBuffer(value);
    } // end of if ()

    if (SIcon.class.isAssignableFrom(targetClass)) {
        return ResourceFactory.makeIcon(value);
    }

    if (targetClass == Color.class) {
        return ResourceFactory.makeColor(value);
    }

    if (targetClass == SDimension.class) {
        return ResourceFactory.makeDimension(value);
    }

    if (targetClass == SFont.class) {
        return TemplateUtil.parseFont(value);
    }

    if (Resource.class.isAssignableFrom(targetClass)) {
        return new ClassPathResource(value);
    }

    if (CSSAttributeSet.class.isAssignableFrom(targetClass)) {
        return ResourceFactory.makeAttributeSet(value);
    }

    if (StyleSheet.class.isAssignableFrom(targetClass)) {
        StyleSheet result;
        try {
            CSSStyleSheet styleSheet = new CSSStyleSheet();
            InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(value);
            styleSheet.read(in);
            in.close();
            result = styleSheet;
        } catch (Exception e) {
            log.warn("Exception", e);
            result = null;
        }
        return result;
    }

    if (ComponentCG.class.isAssignableFrom(targetClass)) {
        return ResourceFactory.makeComponentCG(value);
    }

    throw new UnsupportedOperationException("cannot create object of type " + targetClass.getName());
}

From source file:org.batoo.common.reflect.ReflectHelper.java

/**
 * Converts the number into number Type/*from  w ww.j a v  a  2  s .  co  m*/
 * 
 * @param value
 *            the number value
 * @param numberType
 *            the number type
 * @return the converted number value
 * 
 * @since 2.0.1
 */
public static Number convertNumber(Number value, Class<?> numberType) {
    if (value == null) {
        return null;
    }

    if (numberType.isAssignableFrom(value.getClass())) {
        return value;
    }

    if ((numberType == Integer.class) || (numberType == Integer.TYPE)) {
        return value.intValue();
    }

    if ((numberType == Long.class) || (numberType == Long.TYPE)) {
        return value.longValue();
    }

    if ((numberType == Short.class) || (numberType == Short.TYPE)) {
        return value.shortValue();
    }

    if ((numberType == Byte.class) || (numberType == Byte.TYPE)) {
        return value.byteValue();
    }

    if ((numberType == Float.class) || (numberType == Float.TYPE)) {
        return value.floatValue();
    }

    if ((numberType == Double.class) || (numberType == Double.TYPE)) {
        return value.doubleValue();
    }

    if (numberType == BigDecimal.class) {
        return BigDecimal.valueOf(value.doubleValue());
    }

    if (numberType == BigInteger.class) {
        return BigInteger.valueOf(value.longValue());
    }

    throw new IllegalArgumentException(numberType + " not supported");
}

From source file:de.micromata.genome.util.bean.SoftCastPropertyUtilsBean.java

public Class<?> getWrappedClass(Class<?> target) {
    if (target.isPrimitive() == false) {
        return target;
    }/*from w  w w  .j av a  2 s  . c  o m*/
    if (target == Integer.TYPE) {
        return Integer.class;
    }
    if (target == Long.TYPE) {
        return Long.class;
    }
    if (target == Byte.TYPE) {
        return Byte.class;
    }
    if (target == Short.TYPE) {
        return Short.class;
    }
    if (target == Float.TYPE) {
        return Short.class;
    }
    if (target == Double.TYPE) {
        return Double.class;
    }
    if (target == Character.TYPE) {
        return Character.class;
    }
    if (target == Boolean.TYPE) {
        return Boolean.class;
    }
    throw new RuntimeException("Unmapped basic type: " + target);
}