Example usage for java.lang Double TYPE

List of usage examples for java.lang Double TYPE

Introduction

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

Prototype

Class TYPE

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

Click Source Link

Document

The Class instance representing the primitive type double .

Usage

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  .ja  v a  2s . c o  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:com.csipsimple.utils.Columns.java

public Columns(String[] names, Class<?>[] classes) {
    this.names = names;
    types = new Type[names.length];
    for (int i = 0; i < names.length; i++) {

        if (classes[i] == String.class) {
            types[i] = Type.STRING;
        } else if (classes[i] == Integer.TYPE || classes[i] == Integer.class) {
            types[i] = Type.INT;/* ww w.ja va2 s  .  co  m*/
        } else if (classes[i] == Long.TYPE || classes[i] == Long.class) {
            types[i] = Type.LONG;
        } else if (classes[i] == Float.TYPE || classes[i] == Float.class) {
            types[i] = Type.FLOAT;
        } else if (classes[i] == Double.TYPE || classes[i] == Double.class) {
            types[i] = Type.DOUBLE;
        } else if (classes[i] == Boolean.TYPE || classes[i] == Boolean.class) {
            types[i] = Type.BOOLEAN;
        }
    }
}

From source file:org.jtwig.util.ArrayUtil.java

public static Object[] toArray(Object obj) {
    if (!obj.getClass().isArray()) {
        throw new IllegalArgumentException("Argument is not an array");
    }//  ww w.  j  a  v  a 2 s.co m

    Class<?> type = obj.getClass().getComponentType();
    if (!type.isPrimitive()) {
        return (Object[]) obj;
    }

    if (Byte.TYPE.isAssignableFrom(type)) {
        return toArray((byte[]) obj);
    }
    if (Short.TYPE.isAssignableFrom(type)) {
        return toArray((short[]) obj);
    }
    if (Integer.TYPE.isAssignableFrom(obj.getClass().getComponentType())) {
        return toArray((int[]) obj);
    }
    if (Long.TYPE.isAssignableFrom(obj.getClass().getComponentType())) {
        return toArray((long[]) obj);
    }
    if (Boolean.TYPE.isAssignableFrom(obj.getClass().getComponentType())) {
        return toArray((boolean[]) obj);
    }
    if (Character.TYPE.isAssignableFrom(obj.getClass().getComponentType())) {
        return toArray((char[]) obj);
    }
    if (Float.TYPE.isAssignableFrom(obj.getClass().getComponentType())) {
        return toArray((float[]) obj);
    }
    if (Double.TYPE.isAssignableFrom(obj.getClass().getComponentType())) {
        return toArray((double[]) obj);
    }

    throw new IllegalArgumentException("Unsupported argument type: " + type.getName());
}

From source file:com.github.steveash.typedconfig.resolver.type.simple.DoubleValueResolverFactory.java

@Override
public boolean canResolveFor(ConfigBinding configBinding) {
    return configBinding.getDataType().isAssignableFrom(Double.class)
            || configBinding.getDataType().isAssignableFrom(Double.TYPE);
}

From source file:com.textuality.lifesaver.Columns.java

public Columns(String[] names, Class<?>[] classes, String key1, String key2) {
    this.names = names;
    types = new Type[names.length];
    this.key1 = key1;
    this.key2 = key2;
    for (int i = 0; i < names.length; i++) {

        if (classes[i] == String.class)
            types[i] = Type.STRING;
        else if (classes[i] == Integer.TYPE || classes[i] == Integer.class)
            types[i] = Type.INT;/*  w  w w.  j  a  v a  2  s  .  c om*/
        else if (classes[i] == Long.TYPE || classes[i] == Long.class)
            types[i] = Type.LONG;
        else if (classes[i] == Float.TYPE || classes[i] == Float.class)
            types[i] = Type.FLOAT;
        else if (classes[i] == Double.TYPE || classes[i] == Double.class)
            types[i] = Type.DOUBLE;
    }
}

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  w  ww .ja v  a  2 s .  co  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:org.lunarray.model.descriptor.util.PrimitiveUtil.java

/**
 * Default constructor.//  w  w  w  . ja v  a  2s. co m
 */
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.base.dao.sql.ReflectionUtils.java

public static Object convertValue(Object value, Class toType) {
    Object result = null;//from ww w.j  a  v a2  s  .  c  om
    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:clientapi.command.executor.parser.impl.NumberParser.java

@Override
public final boolean isTarget(Type type) {
    if (!(type instanceof Class)) {
        return false;
    }/* ww  w  .  j  ava2  s .  c om*/

    Class c = (Class) type;
    // Check all NumberUtils#createNumber(String) supported types
    // Integer -> BigInteger
    // Float -> BigDecimal
    return Integer.class.isAssignableFrom(c) || Long.class.isAssignableFrom(c)
            || BigInteger.class.isAssignableFrom(c) || Float.class.isAssignableFrom(c)
            || Double.class.isAssignableFrom(c) || BigDecimal.class.isAssignableFrom(c)
            || Integer.TYPE.isAssignableFrom(c) || Long.TYPE.isAssignableFrom(c)
            || Float.TYPE.isAssignableFrom(c) || Double.TYPE.isAssignableFrom(c);
}

From source file:org.ralasafe.db.JavaBeanColumnAdapter.java

private void initSetterMethod(Object o) throws Exception {
    Class valueClass;/*w ww  . j a v a  2  s  . c om*/
    Class clas = o.getClass();

    if (className.equals("int"))
        valueClass = Integer.TYPE;
    else if (className.equals("float"))
        valueClass = Float.TYPE;
    else if (className.equals("long"))
        valueClass = Long.TYPE;
    else if (className.equals("double"))
        valueClass = Double.TYPE;
    else if (className.equals("boolean"))
        valueClass = Boolean.TYPE;
    else
        valueClass = Class.forName(className);

    setter = clas.getMethod(setterStr, new Class[] { valueClass });
}