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:org.kordamp.ezmorph.object.NumberMorpher.java

private boolean isDecimalNumber(Class type) {
    return (Double.class.isAssignableFrom(type) || Float.class.isAssignableFrom(type) || Double.TYPE == type
            || Float.TYPE == type || BigDecimal.class.isAssignableFrom(type));
}

From source file:org.impalaframework.spring.service.proxy.ServiceEndpointInterceptor.java

public Object invokeDummy(MethodInvocation invocation) throws Throwable {

    log.debug("Calling method " + invocation);
    Class<?> returnType = invocation.getMethod().getReturnType();

    if (Void.TYPE.equals(returnType))
        return null;
    if (Byte.TYPE.equals(returnType))
        return (byte) 0;
    if (Short.TYPE.equals(returnType))
        return (short) 0;
    if (Integer.TYPE.equals(returnType))
        return (int) 0;
    if (Long.TYPE.equals(returnType))
        return 0L;
    if (Float.TYPE.equals(returnType))
        return 0f;
    if (Double.TYPE.equals(returnType))
        return 0d;
    if (Boolean.TYPE.equals(returnType))
        return false;

    return null;/*from w w w . j a  v a 2s .co m*/
}

From source file:net.sf.json.JSONUtils.java

/**
 * Tests if obj is a primitive number or wrapper.<br>
 *//*from   w  ww.j  ava 2 s  . co m*/
public static boolean isNumber(Object obj) {
    if (((obj != null) && (obj.getClass() == Byte.TYPE)) || ((obj != null) && (obj.getClass() == Short.TYPE))
            || ((obj != null) && (obj.getClass() == Integer.TYPE))
            || ((obj != null) && (obj.getClass() == Long.TYPE))
            || ((obj != null) && (obj.getClass() == Float.TYPE))
            || ((obj != null) && (obj.getClass() == Double.TYPE))) {
        return true;
    }

    if ((obj instanceof Byte) || (obj instanceof Short) || (obj instanceof Integer) || (obj instanceof Long)
            || (obj instanceof Float) || (obj instanceof Double)) {
        return true;
    }

    return false;
}

From source file:nz.co.senanque.validationengine.ConvertUtils.java

public static Object getObjectForNull(Class<?> clazz) {
    if (clazz.equals(Long.TYPE)) {
        return new Long(0);
    } else if (clazz.equals(Integer.TYPE)) {
        return new Integer(0);
    } else if (clazz.equals(Float.TYPE)) {
        return new Float(0.0F);
    } else if (clazz.equals(Double.TYPE)) {
        return new Double(0.0D);
    } else if (clazz.equals(Boolean.TYPE)) {
        return new Boolean(false);
    }//  w w  w  . ja va  2 s.com
    return null;
}

From source file:com.nfwork.dbfound.json.JSONDynaBean.java

protected boolean isDynaAssignable(Class dest, Class src) {
    boolean assignable = dest.isAssignableFrom(src);
    assignable = (dest == Boolean.TYPE && src == Boolean.class) ? true : assignable;
    assignable = (dest == Byte.TYPE && src == Byte.class) ? true : assignable;
    assignable = (dest == Character.TYPE && src == Character.class) ? true : assignable;
    assignable = (dest == Short.TYPE && src == Short.class) ? true : assignable;
    assignable = (dest == Integer.TYPE && src == Integer.class) ? true : assignable;
    assignable = (dest == Long.TYPE && src == Long.class) ? true : assignable;
    assignable = (dest == Float.TYPE && src == Float.class) ? true : assignable;
    assignable = (dest == Double.TYPE && src == Double.class) ? true : assignable;

    if (src == Double.TYPE || Double.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest) || isFloat(dest)) ? true
                : assignable;//from   ww w.j  ava2  s.c o  m
    }
    if (src == Float.TYPE || Float.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest)) ? true : assignable;
    }
    if (src == Long.TYPE || Long.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest)) ? true : assignable;
    }
    if (src == Integer.TYPE || Integer.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest)) ? true : assignable;
    }
    if (src == Short.TYPE || Short.class.isAssignableFrom(src)) {
        assignable = (isByte(dest)) ? true : assignable;
    }

    return assignable;
}

From source file:org.commonreality.object.delta.DeltaTracker.java

@SuppressWarnings("unchecked")
private boolean isActualChange(String keyName, Object newValue) {
    if (newValue != null) {
        if (!_actualObject.hasProperty(keyName))
            return true;

        Object oldValue = null;/*w  w  w  .j  av a2  s .c o  m*/

        // if (checkOnlyActualObject)
        oldValue = _actualObject.getProperty(keyName);
        // else
        // oldValue = getProperty(keyName);

        if (newValue == oldValue)
            return false;

        if (newValue.equals(oldValue))
            return false;

        /*
         * now we need to see if they are arrays
         */
        Class newClass = newValue.getClass();
        Class oldClass = Object.class;
        if (oldValue != null)
            oldClass = oldValue.getClass();
        if (newClass != oldClass)
            return true;

        if (newClass.isArray() && oldClass.isArray()) {
            if (newClass.getComponentType() != oldClass.getComponentType())
                return true;

            /*
             * now we have to check the elements
             */
            if (newClass.getComponentType().isPrimitive()) {
                boolean rtn = true;
                if (newClass.getComponentType() == Float.TYPE)
                    rtn = compareFloats((float[]) newValue, (float[]) oldValue);
                else if (newClass.getComponentType() == Double.TYPE)
                    rtn = compareDoubles((double[]) newValue, (double[]) oldValue);
                else if (newClass.getComponentType() == Boolean.TYPE)
                    rtn = compareBooleans((boolean[]) newValue, (boolean[]) oldValue);
                else if (newClass.getComponentType() == Integer.TYPE)
                    rtn = compareInts((int[]) newValue, (int[]) oldValue);
                else if (LOGGER.isWarnEnabled())
                    LOGGER.warn("Cannot compare arrays of " + newClass.getComponentType().getName());
                return rtn;
            } else {
                Object[] newArray = (Object[]) newValue;
                Object[] oldArray = (Object[]) oldValue;

                if (newArray.length != oldArray.length)
                    return true;

                for (int i = 0; i < newArray.length; i++)
                    if (!newArray[i].equals(oldArray[i]))
                        return true;

                return false;
            }

        }
    } else // unsetting the property
    if (_actualObject.hasProperty(keyName))
        return true;

    return true;
}

From source file:org.seedstack.seed.core.internal.application.ConfigurationMembersInjector.java

@SuppressWarnings("unchecked")
private void writeArrayField(T instance) {
    ConfigurationConverter<?> converter;
    Class<?> componentType = field.getType().getComponentType();
    converter = findConverter(instance, componentType);
    String[] values = configuration.getStringArray(annotation.value());

    if ((values == null || values.length == 0) && annotation.defaultValue().length > 0) {
        values = annotation.defaultValue();
    }/*from   w w w  . j  av  a2s. co m*/

    if (values != null && values.length > 0) {
        if (componentType.isPrimitive()) {
            if (componentType == Short.TYPE) {
                writeField(instance, convertToShortValues(values, (ConfigurationConverter<Short>) converter));
            }
            if (componentType == Integer.TYPE) {
                writeField(instance,
                        convertToIntegerValues(values, (ConfigurationConverter<Integer>) converter));
            }
            if (componentType == Boolean.TYPE) {
                writeField(instance,
                        convertToBooleanValues(values, (ConfigurationConverter<Boolean>) converter));
            }
            if (componentType == Byte.TYPE) {
                writeField(instance, convertToByteValues(values, (ConfigurationConverter<Byte>) converter));
            }
            if (componentType == Long.TYPE) {
                writeField(instance, convertToLongValues(values, (ConfigurationConverter<Long>) converter));
            }
            if (componentType == Float.TYPE) {
                writeField(instance, convertToFloatValues(values, (ConfigurationConverter<Float>) converter));
            }
            if (componentType == Double.TYPE) {
                writeField(instance, convertToDoubleValues(values, (ConfigurationConverter<Double>) converter));
            }
            if (componentType == Character.TYPE) {
                writeField(instance,
                        convertToCharacterValues(values, (ConfigurationConverter<Character>) converter));
            }
        } else {
            Object[] convertedValues;
            try {
                convertedValues = (Object[]) Array.newInstance(field.getType().getComponentType(),
                        values.length);
            } catch (Exception e) {
                throw SeedException.wrap(e, ApplicationErrorCode.UNABLE_TO_INSTANTIATE_CONFIGURATION_ARRAY);
            }

            for (int i = 0; i < values.length; i++) {
                convertedValues[i] = converter.convert(values[i]);
            }
            writeField(instance, convertedValues);
        }
    } else {
        LOGGER.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, annotation.value());
    }
}

From source file:com.cyclopsgroup.waterview.utils.TypeUtils.java

private static synchronized Map getTypeMap() {
    if (typeMap == null) {
        typeMap = new Hashtable();
        typeMap.put("boolean", Boolean.TYPE);
        typeMap.put("byte", Byte.TYPE);
        typeMap.put("char", Character.TYPE);
        typeMap.put("short", Short.TYPE);
        typeMap.put("int", Integer.TYPE);
        typeMap.put("long", Long.TYPE);
        typeMap.put("float", Float.TYPE);
        typeMap.put("double", Double.TYPE);
        typeMap.put("string", String.class);
        typeMap.put("date", Date.class);
    }/*from w  ww .  ja v  a2  s. co m*/

    return typeMap;
}

From source file:org.getobjects.appserver.publisher.GoJavaMethod.java

@SuppressWarnings("unchecked")
public Object coerceFormValueToArgumentType(final Object[] _v, final Class<?> _argType) {
    // FIXME: All this isn't nice. Cleanup and do it properly.
    // FIXME: Cache all the dynamic lookup
    if (_v == null)
        return null;

    if (_argType.isAssignableFrom(_v.getClass()))
        return _v;

    int vCount = _v.length;

    /* check whether the argument is some array-ish thing */

    if (_argType.isArray()) {
        final Class<?> itemType = _argType.getComponentType();
        final Object typedArray = java.lang.reflect.Array.newInstance(itemType, vCount);
        for (int i = 0; i < vCount; i++) {
            Object[] v = { _v[i] };
            Object sv = this.coerceFormValueToArgumentType(v, itemType);
            java.lang.reflect.Array.set(typedArray, i, sv);
        }/*from   w w  w. j  a  v  a 2  s .  co  m*/
        return typedArray;
    }

    if (_argType.isAssignableFrom(List.class))
        return UList.asList(_v);
    if (_argType.isAssignableFrom(Set.class))
        return new HashSet(UList.asList(_v));
    if (_argType.isAssignableFrom(Collection.class))
        return UList.asList(_v);

    /* empty assignment */

    if (vCount == 0) {
        if (!_argType.isPrimitive())
            return null; // all objects, return null

        if (_argType == Boolean.TYPE)
            return new Boolean(false);
        if (_argType == Integer.TYPE)
            return new Integer(-1);
        if (_argType == Double.TYPE)
            return new Double(-1.0);
        if (_argType == Float.TYPE)
            return new Float(-1.0);
        if (_argType == Short.TYPE)
            return new Integer(-1);
        if (_argType == Long.TYPE)
            return new Long(-1);
        log.error("Unexpected primitive arg type: " + _argType);
        return new GoInternalErrorException("Unexpected primitive type!");
    }

    /* check whether it is a directly assignable type */

    if (vCount == 1) {
        /* some type coercion. Can we reuse anything from KVC here? */
        // Note: Go supports various Zope form value formats, e.g. 'age:int'
        //       Check WOServletRequest for more.
        final Object v = _v[0];

        if (_argType.isAssignableFrom(v.getClass()))
            return v;

        /* some basic coercion */

        if (_argType.isPrimitive()) {
            if (_argType == Boolean.TYPE)
                return new Boolean(UObject.boolValue(v));

            if (_argType == Integer.TYPE || _argType == Short.TYPE)
                return new Integer(UObject.intValue(v));

            if (_argType == Long.TYPE)
                return new Long(UObject.intOrLongValue(v).longValue());
        } else if (_argType.isAssignableFrom(String.class))
            return v.toString();

        return v; // might crash
    }

    /* error out, return exception as value */

    log.error("Cannot convert form value to Java argument " + _argType + ": " + _v);
    return new GoInternalErrorException("Cannot convert form value to Java parameter");
}

From source file:org.kuali.rice.krad.data.jpa.Filter.java

/**
 * Coerces the {@code attributeValue} using the given {@code type}.
 *
 * @param type the type to use to coerce the value.
 * @param attributeName the attribute name of the field to coerce.
 * @param attributeValue the value to coerce.
 * @return the coerced value./*from w  ww  .ja va 2  s  .  co  m*/
 */
private static Object coerceValue(Class<?> type, String attributeName, String attributeValue) {
    try {
        if (Character.TYPE.equals(type) || Character.class.isAssignableFrom(type)) {
            return Character.valueOf(attributeValue.charAt(0));
        } else if (Boolean.TYPE.equals(type) || Boolean.class.isAssignableFrom(type)) {
            return Boolean.valueOf(attributeValue);
        } else if (Short.TYPE.equals(type) || Short.class.isAssignableFrom(type)) {
            return Short.valueOf(attributeValue);
        } else if (Integer.TYPE.equals(type) || Integer.class.isAssignableFrom(type)) {
            return Integer.valueOf(attributeValue);
        } else if (Long.TYPE.equals(type) || Long.class.isAssignableFrom(type)) {
            return Long.valueOf(attributeValue);
        } else if (Double.TYPE.equals(type) || Double.class.isAssignableFrom(type)) {
            return Double.valueOf(attributeValue);
        } else if (Float.TYPE.equals(type) || Float.class.isAssignableFrom(type)) {
            return Float.valueOf(attributeValue);
        }
    } catch (NumberFormatException nfe) {
        LOG.error("Could not coerce the value " + attributeValue + " for the field " + attributeName, nfe);
    }

    return attributeValue;
}