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:nz.co.senanque.validationengine.ValidationUtils.java

public static Comparable<?> convertTo(final Class<Comparable<?>> clazz, Object obj) {
    if (obj == null) {
        return null;
    }//from w  ww .j  a v a2 s  . com
    if (clazz.isAssignableFrom(obj.getClass())) {
        return (Comparable<?>) obj;
    }
    final String oStr = String.valueOf(obj);
    if (clazz.equals(String.class)) {
        return oStr;
    }
    if (clazz.equals(Long.class) || clazz.equals(Long.TYPE)) {
        if (Number.class.isAssignableFrom(obj.getClass())) {
            return new Long(((Number) obj).longValue());
        }
        return Long.valueOf(oStr);
    }
    if (clazz.equals(Integer.class) || clazz.equals(Integer.TYPE)) {
        if (Number.class.isAssignableFrom(obj.getClass())) {
            return new Integer(((Number) obj).intValue());
        }
        return Integer.valueOf(oStr);
    }
    if (clazz.equals(Double.class) || clazz.equals(Double.TYPE)) {
        if (Number.class.isAssignableFrom(obj.getClass())) {
            return new Double(((Number) obj).doubleValue());
        }
        return Double.valueOf(oStr);
    }
    if (clazz.equals(Float.class) || clazz.equals(Float.TYPE)) {
        if (Number.class.isAssignableFrom(obj.getClass())) {
            return new Float(((Number) obj).floatValue());
        }
        return Float.valueOf(oStr);
    }
    if (clazz.equals(BigDecimal.class)) {
        return new BigDecimal(oStr);
    }
    if (clazz.equals(java.util.Date.class)) {
        return java.sql.Date.valueOf(oStr);
    }
    if (clazz.equals(java.sql.Date.class)) {
        return java.sql.Date.valueOf(oStr);
    }
    return null;
}

From source file:org.romaframework.core.schema.SchemaHelper.java

public static Object assignDefaultValueToLiteral(SchemaClass type) {
    Object value;// w ww. j a v  a2 s  .c  o m
    if (type.isOfType(Integer.TYPE)) {
        value = Integer.valueOf(0);
    } else if (type.isOfType(Long.TYPE)) {
        value = Long.valueOf(0);
    } else if (type.isOfType(Short.TYPE)) {
        value = Short.valueOf((short) 0);
    } else if (type.isOfType(Byte.TYPE)) {
        value = Byte.valueOf((byte) 0);
    } else if (type.isOfType(Float.TYPE)) {
        value = Float.valueOf(0);
    } else if (type.isOfType(Double.TYPE)) {
        value = Double.valueOf(0);
    } else {
        value = null;
    }
    return value;
}

From source file:org.apache.struts.action.DynaActionForm.java

/**
 * <p>Return the value of a simple property with the specified name.</p>
 *
 * @param name Name of the property whose value is to be retrieved
 * @return The value of a simple property with the specified name.
 * @throws IllegalArgumentException if there is no property of the
 *                                  specified name
 * @throws NullPointerException     if the type specified for the property
 *                                  is invalid
 *//*from  ww  w.j a  v a 2 s  . c  o  m*/
public Object get(String name) {
    // Return any non-null value for the specified property
    Object value = dynaValues.get(name);

    if (value != null) {
        return (value);
    }

    // Return a null value for a non-primitive property
    Class type = getDynaProperty(name).getType();

    if (type == null) {
        throw new NullPointerException("The type for property " + name + " is invalid");
    }

    if (!type.isPrimitive()) {
        return (value);
    }

    // Manufacture default values for primitive properties
    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 == Double.TYPE) {
        return (new Double(0.0));
    } else if (type == Float.TYPE) {
        return (new Float((float) 0.0));
    } else if (type == Integer.TYPE) {
        return (new Integer(0));
    } else if (type == Long.TYPE) {
        return (new Long(0));
    } else if (type == Short.TYPE) {
        return (new Short((short) 0));
    } else {
        return (null);
    }
}

From source file:com.ryan.ryanreader.jsonwrap.JsonBufferedObject.java

public void populateObject(final Object o) throws InterruptedException, IOException, IllegalArgumentException,
        InstantiationException, NoSuchMethodException, InvocationTargetException {

    if (join() != Status.LOADED) {
        throwFailReasonException();/*from w  w  w  . jav  a2s  .com*/
    }

    final Field[] objectFields = o.getClass().getFields();

    try {

        for (final Field objectField : objectFields) {

            if ((objectField.getModifiers() & Modifier.TRANSIENT) != 0) {
                continue;
            }

            final JsonValue val;

            if (properties.containsKey(objectField.getName())) {
                val = properties.get(objectField.getName());

            } else if (objectField.getName().startsWith("_json_")) {
                val = properties.get(objectField.getName().substring("_json_".length()));
            } else {
                val = null;
            }

            if (val == null) {
                continue;
            }

            objectField.setAccessible(true);

            final Class<?> fieldType = objectField.getType();

            if (fieldType == Long.class || fieldType == Long.TYPE) {
                objectField.set(o, val.asLong());

            } else if (fieldType == Double.class || fieldType == Double.TYPE) {
                objectField.set(o, val.asDouble());

            } else if (fieldType == Integer.class || fieldType == Integer.TYPE) {
                objectField.set(o, val.isNull() ? null : val.asLong().intValue());

            } else if (fieldType == Float.class || fieldType == Float.TYPE) {
                objectField.set(o, val.isNull() ? null : val.asDouble().floatValue());

            } else if (fieldType == Boolean.class || fieldType == Boolean.TYPE) {
                objectField.set(o, val.asBoolean());

            } else if (fieldType == String.class) {
                objectField.set(o, val.asString());

            } else if (fieldType == JsonBufferedArray.class) {
                objectField.set(o, val.asArray());

            } else if (fieldType == JsonBufferedObject.class) {
                objectField.set(o, val.asObject());

            } else if (fieldType == JsonValue.class) {
                objectField.set(o, val);

            } else if (fieldType == Object.class) {

                final Object result;

                switch (val.getType()) {
                case BOOLEAN:
                    result = val.asBoolean();
                    break;
                case INTEGER:
                    result = val.asLong();
                    break;
                case STRING:
                    result = val.asString();
                    break;
                case FLOAT:
                    result = val.asDouble();
                    break;
                default:
                    result = val;
                }

                objectField.set(o, result);

            } else {
                objectField.set(o, val.asObject(fieldType));
            }
        }

    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.aol.one.patch.DefaultPatcher.java

private List<MethodData> generateMethodData(List<String> methodNames, JsonNode valueNode) {

    List<MethodData> dataList = new ArrayList<>();
    if (valueNode.isTextual()) {
        for (String methodName : methodNames) {
            dataList.add(new MethodData(methodName, String.class, valueNode.asText()));
        }//from   w ww  .  j  a va 2s . c o m
    } else if (valueNode.isNumber()) {
        for (String methodName : methodNames) {
            if (valueNode.isIntegralNumber()) {
                dataList.add(new MethodData(methodName, Long.TYPE, valueNode.asLong()));
                dataList.add(new MethodData(methodName, Long.class, valueNode.asLong()));
                dataList.add(new MethodData(methodName, Integer.TYPE, valueNode.asInt()));
                dataList.add(new MethodData(methodName, Integer.class, valueNode.asInt()));
                dataList.add(new MethodData(methodName, Short.TYPE, (short) valueNode.asInt()));
                dataList.add(new MethodData(methodName, Short.class, (short) valueNode.asInt()));
            } else {
                dataList.add(new MethodData(methodName, Double.TYPE, valueNode.asDouble()));
                dataList.add(new MethodData(methodName, Double.class, valueNode.asDouble()));
                dataList.add(new MethodData(methodName, Float.TYPE, valueNode.asDouble()));
                dataList.add(new MethodData(methodName, Float.class, valueNode.asDouble()));
            }
        }
    } else if (valueNode.isBoolean()) {
        for (String methodName : methodNames) {
            dataList.add(new MethodData(methodName, Boolean.TYPE, valueNode.asBoolean()));
            dataList.add(new MethodData(methodName, Boolean.class, valueNode.asBoolean()));
        }

    }

    // default
    for (String methodName : methodNames) {
        dataList.add(new MethodData(methodName, JsonNode.class, valueNode));
    }

    return dataList;
}

From source file:org.quantumbadger.redreader.jsonwrap.JsonBufferedObject.java

public void populateObject(final Object o) throws InterruptedException, IOException, IllegalArgumentException,
        InstantiationException, NoSuchMethodException, InvocationTargetException {

    if (join() != STATUS_LOADED) {
        throwFailReasonException();//from   ww w. j  a  v a 2  s.c o  m
    }

    final Field[] objectFields = o.getClass().getFields();

    try {

        for (final Field objectField : objectFields) {

            if ((objectField.getModifiers() & Modifier.TRANSIENT) != 0) {
                continue;
            }

            final JsonValue val;

            if (properties.containsKey(objectField.getName())) {
                val = properties.get(objectField.getName());

            } else if (objectField.getName().startsWith("_json_")) {
                val = properties.get(objectField.getName().substring("_json_".length()));
            } else {
                val = null;
            }

            if (val == null) {
                continue;
            }

            objectField.setAccessible(true);

            final Class<?> fieldType = objectField.getType();

            if (fieldType == Long.class || fieldType == Long.TYPE) {
                objectField.set(o, val.asLong());

            } else if (fieldType == Double.class || fieldType == Double.TYPE) {
                objectField.set(o, val.asDouble());

            } else if (fieldType == Integer.class || fieldType == Integer.TYPE) {
                objectField.set(o, val.isNull() ? null : val.asLong().intValue());

            } else if (fieldType == Float.class || fieldType == Float.TYPE) {
                objectField.set(o, val.isNull() ? null : val.asDouble().floatValue());

            } else if (fieldType == Boolean.class || fieldType == Boolean.TYPE) {
                objectField.set(o, val.asBoolean());

            } else if (fieldType == String.class) {
                objectField.set(o, val.asString());

            } else if (fieldType == JsonBufferedArray.class) {
                objectField.set(o, val.asArray());

            } else if (fieldType == JsonBufferedObject.class) {
                objectField.set(o, val.asObject());

            } else if (fieldType == JsonValue.class) {
                objectField.set(o, val);

            } else if (fieldType == Object.class) {

                final Object result;

                switch (val.getType()) {
                case JsonValue.TYPE_BOOLEAN:
                    result = val.asBoolean();
                    break;
                case JsonValue.TYPE_INTEGER:
                    result = val.asLong();
                    break;
                case JsonValue.TYPE_STRING:
                    result = val.asString();
                    break;
                case JsonValue.TYPE_FLOAT:
                    result = val.asDouble();
                    break;
                default:
                    result = val;
                }

                objectField.set(o, result);

            } else {
                objectField.set(o, val.asObject(fieldType));
            }
        }

    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.mina.statemachine.transition.MethodTransition.java

@SuppressWarnings("unchecked")
private boolean match(Class<?> paramType, Object arg, Class argType) {
    if (paramType.isPrimitive()) {
        if (paramType.equals(Boolean.TYPE)) {
            return arg instanceof Boolean;
        }//from   w ww  .ja  v  a 2  s.c  om
        if (paramType.equals(Integer.TYPE)) {
            return arg instanceof Integer;
        }
        if (paramType.equals(Long.TYPE)) {
            return arg instanceof Long;
        }
        if (paramType.equals(Short.TYPE)) {
            return arg instanceof Short;
        }
        if (paramType.equals(Byte.TYPE)) {
            return arg instanceof Byte;
        }
        if (paramType.equals(Double.TYPE)) {
            return arg instanceof Double;
        }
        if (paramType.equals(Float.TYPE)) {
            return arg instanceof Float;
        }
        if (paramType.equals(Character.TYPE)) {
            return arg instanceof Character;
        }
    }
    return argType.isAssignableFrom(paramType) && paramType.isAssignableFrom(arg.getClass());
}

From source file:org.kordamp.ezmorph.bean.MorphDynaBean.java

protected boolean isDynaAssignable(Class dest, Class src) {
    boolean assignable = dest.isAssignableFrom(src);
    if (assignable) {
        return true;
    }//from  w  ww.  ja  v a  2s  . co  m
    assignable = (dest == Boolean.TYPE && src == Boolean.class) || assignable;
    assignable = (dest == Byte.TYPE && src == Byte.class) || assignable;
    assignable = (dest == Character.TYPE && src == Character.class) || assignable;
    assignable = (dest == Short.TYPE && src == Short.class) || assignable;
    assignable = (dest == Integer.TYPE && src == Integer.class) || assignable;
    assignable = (dest == Long.TYPE && src == Long.class) || assignable;
    assignable = (dest == Float.TYPE && src == Float.class) || assignable;
    assignable = (dest == Double.TYPE && src == Double.class) || assignable;

    if (src == Double.TYPE || Double.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest) || isFloat(dest))
                || assignable;
    }
    if (src == Float.TYPE || Float.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest)) || assignable;
    }
    if (src == Long.TYPE || Long.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest)) || assignable;
    }
    if (src == Integer.TYPE || Integer.class.isAssignableFrom(src))
        assignable = (isByte(dest) || isShort(dest)) || assignable;
    if (src == Short.TYPE || Short.class.isAssignableFrom(src)) {
        assignable = (isByte(dest)) || assignable;
    }

    return assignable;
}

From source file:jp.terasoluna.fw.web.struts.reset.ResetterImpl.java

/**
 * ANVtH?[wv?peBZbg?B// w w w.jav  a  2s.  c om
 * v?peB^boolean^?ABoolean^??false??B
 * v~eBu^bp?[^???A0??B
 * v?peB^bp?[^OObject^??null??B<br>
 * ??A?entrynulln?B
 *
 * @param form ?NGXggpANVtH?[
 * @param entry Zbg?v?peB?lGg
 * @throws PropertyAccessException v?peBl?s??
 */
protected void resetValue(FormEx form, Entry<String, Object> entry) {
    if (log.isDebugEnabled()) {
        log.debug("resetValue(" + form + ", " + entry.getKey() + ") called.");
    }
    String propName = entry.getKey();
    try {
        Object value = entry.getValue();
        if (value == null) {
            return;
        }
        Class type = null;
        type = value.getClass();
        if (type != null) {
            // ^???B
            if (type == Boolean.TYPE || type == Boolean.class) {
                BeanUtil.setBeanProperty(form, propName, Boolean.FALSE);
            } else if (type == Byte.TYPE || type == Byte.class) {
                BeanUtil.setBeanProperty(form, propName, new Byte((byte) 0));
            } else if (type == Character.TYPE || type == Character.class) {
                BeanUtil.setBeanProperty(form, propName, new Character((char) 0));
            } else if (type == Double.TYPE || type == Double.class) {
                BeanUtil.setBeanProperty(form, propName, new Double(0.0));
            } else if (type == Float.TYPE || type == Float.class) {
                BeanUtil.setBeanProperty(form, propName, new Float((float) 0.0));
            } else if (type == Integer.TYPE || type == Integer.class) {
                BeanUtil.setBeanProperty(form, propName, new Integer(0));
            } else if (type == Long.TYPE || type == Long.class) {
                BeanUtil.setBeanProperty(form, propName, new Long(0));
            } else if (type == Short.TYPE || type == Short.class) {
                BeanUtil.setBeanProperty(form, propName, new Short((short) 0));
            } else {
                // v~eBu^?Abp?[^??null?
                BeanUtil.setBeanProperty(form, propName, null);
            }
        }
    } catch (PropertyAccessException e) {
        log.error("cannot access property " + form + "." + propName, e);
    }
}

From source file:org.pentaho.ui.xul.impl.AbstractXulDomContainer.java

private Class unBoxPrimative(Class clazz) {
    if (clazz == Boolean.class) {
        return Boolean.TYPE;
    } else if (clazz == Integer.class) {
        return Integer.TYPE;
    } else if (clazz == Float.class) {
        return Float.TYPE;
    } else if (clazz == Double.class) {
        return Double.TYPE;
    } else if (clazz == Short.class) {
        return Short.TYPE;
    } else if (clazz == Long.class) {
        return Long.TYPE;
    } else {//from   www. j a v a 2 s. c  o m
        return clazz;
    }
}