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.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>// w  w  w  .  ja va  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:de.micromata.genome.util.bean.SoftCastPropertyUtilsBean.java

public Class<?> getWrappedClass(Class<?> target) {
    if (target.isPrimitive() == false) {
        return target;
    }//from w  w  w . j a  v a 2s .  com
    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);
}

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

/**
 * Converts the number into number Type/*from ww w  .j  a  v  a 2  s  .c  o  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:org.kordamp.ezmorph.primitive.DoubleMorpher.java

public Class<?> morphsTo() {
    return Double.TYPE;
}

From source file:org.thingsplode.synapse.serializers.jackson.adapters.ParameterWrapperDeserializer.java

@Override
public ParameterWrapper deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    JsonNode node = jp.readValueAsTree();
    if (node != null && node.size() > 0 && node.isContainerNode()) {
        ParameterWrapper pw = ParameterWrapper.create();
        ArrayNode paramsNode = (ArrayNode) node.get("params");
        Iterator<JsonNode> elemIterator = paramsNode.elements();
        while (elemIterator.hasNext()) {
            JsonNode currentNode = elemIterator.next();
            if (currentNode.getNodeType() == JsonNodeType.OBJECT) {
                try {
                    String paramid = ((ObjectNode) currentNode).get("paramid").asText();
                    String typeName = ((ObjectNode) currentNode).get("type").asText();
                    Class paramType = null;
                    if (null != typeName)
                        switch (typeName) {
                        case "long":
                            paramType = Long.TYPE;
                            break;
                        case "byte":
                            paramType = Byte.TYPE;
                            break;
                        case "short":
                            paramType = Short.TYPE;
                            break;
                        case "int":
                            paramType = Integer.TYPE;
                            break;
                        case "float":
                            paramType = Float.TYPE;
                            break;
                        case "double":
                            paramType = Double.TYPE;
                            break;
                        case "boolean":
                            paramType = Boolean.TYPE;
                            break;
                        case "char":
                            paramType = Character.TYPE;
                            break;
                        default:
                            paramType = Class.forName(typeName);
                            break;
                        }//w w  w.  jav  a 2  s.com
                    Object parameterObject = jp.getCodec().treeToValue(currentNode.get("value"), paramType);
                    pw.add(paramid, paramType, parameterObject);
                } catch (ClassNotFoundException ex) {
                    throw new JsonParseException(jp, ex.getMessage());
                }
            }
        }
        return pw;
    } else {
        return null;
    }
}

From source file:org.hyperic.hq.agent.server.monitor.AgentMonitorSimple.java

/**
 * Go through all the methods that we define to find ones which
 * match the signature we're looking for
 *//*from   www.  j  a v  a 2s  .c o m*/
private void setupMethodMap() {
    Method[] methods;
    Class asClass = String[].class, aiClass = int[].class;
    int j;

    methods = this.getClass().getMethods();
    for (int i = 0; i < methods.length; i++) {
        Method m = methods[i];
        Class[] exceptions;
        Class retType;

        if (m.getName().startsWith("get") == false || m.getParameterTypes().length != 0) {
            continue;
        }

        exceptions = m.getExceptionTypes();
        if (exceptions.length != 1 || exceptions[0].equals(AgentMonitorException.class) == false) {
            continue;
        }

        retType = m.getReturnType();
        if (retType.equals(String.class) == false && retType.equals(Double.TYPE) == false
                && retType.equals(asClass) == false && retType.equals(aiClass) == false) {
            continue;
        }

        this.methodMap.put(m.getName().substring(3), m);
    }

    this.methodKeys = new String[this.methodMap.size()];
    this.methodTypes = new int[this.methodKeys.length];

    j = 0;
    for (Iterator i = this.methodMap.keySet().iterator(); i.hasNext(); j++) {
        String key = (String) i.next();
        Method m = (Method) this.methodMap.get(key);
        Class retType = m.getReturnType();
        int type;

        this.methodKeys[j] = key;
        if (retType.equals(String.class))
            type = AgentMonitorValue.TYPE_STRING;
        else if (retType.equals(Double.TYPE))
            type = AgentMonitorValue.TYPE_DOUBLE;
        else if (retType.equals(asClass))
            type = AgentMonitorValue.TYPE_ASTRING;
        else if (retType.equals(aiClass))
            type = AgentMonitorValue.TYPE_AINT;
        else
            throw new IllegalStateException("Should never get here");

        this.methodTypes[j] = type;
    }
}

From source file:ClassUtils.java

/**
 * Helper for invoking an instance method that takes a single parameter.
 * This method also handles parameters of primitive type.
 * /*from   w  w w. j  av  a 2  s.  c o  m*/
 * @param cl
 *            The class that the instance belongs to
 * @param instance
 *            The object on which we will invoke the method
 * @param methodName
 *            The method name
 * @param param
 *            The parameter
 * @throws Throwable
 */
public static Object invokeMethod(Class cl, Object instance, String methodName, Object param) throws Throwable {
    Class paramClass;
    if (param instanceof Integer)
        paramClass = Integer.TYPE;
    else if (param instanceof Long)
        paramClass = Long.TYPE;
    else if (param instanceof Short)
        paramClass = Short.TYPE;
    else if (param instanceof Boolean)
        paramClass = Boolean.TYPE;
    else if (param instanceof Double)
        paramClass = Double.TYPE;
    else if (param instanceof Float)
        paramClass = Float.TYPE;
    else if (param instanceof Character)
        paramClass = Character.TYPE;
    else if (param instanceof Byte)
        paramClass = Byte.TYPE;
    else
        paramClass = param.getClass();
    Method method = cl.getMethod(methodName, new Class[] { paramClass });
    try {
        return method.invoke(instance, new Object[] { param });
    } catch (InvocationTargetException e) {
        throw e.getCause();
    }
}

From source file:org.kordamp.ezmorph.object.NumberMorpher.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.
 *
 * @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
 *///from   ww w  . j  a  va2  s . c  o  m
public NumberMorpher(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");
    }

    if (defaultValue != null && !type.isInstance(defaultValue)) {
        throw new MorphException("Default value must be of type " + type);
    }

    this.type = type;
    setDefaultValue(defaultValue);
}

From source file:org.primeframework.mvc.parameter.convert.converters.NumberConverterTest.java

/**
 * Test the conversion from Strings./*from w  w  w . j a v  a 2s . com*/
 */
@Test
public void fromStrings() {
    GlobalConverter converter = new NumberConverter(new MockConfiguration());
    Byte bw = (Byte) converter.convertFromStrings(Byte.class, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertNull(bw);

    Short sw = (Short) converter.convertFromStrings(Short.class, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertNull(sw);

    Integer iw = (Integer) converter.convertFromStrings(Integer.class, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertNull(iw);

    Long lw = (Long) converter.convertFromStrings(Long.class, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertNull(lw);

    Float fw = (Float) converter.convertFromStrings(Float.class, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertNull(fw);

    Double dw = (Double) converter.convertFromStrings(Double.class, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertNull(dw);

    byte b = (Byte) converter.convertFromStrings(Byte.TYPE, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertEquals(b, 0);

    short s = (Short) converter.convertFromStrings(Short.TYPE, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertEquals(s, 0);

    int i = (Integer) converter.convertFromStrings(Integer.TYPE, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertEquals(i, 0);

    long l = (Long) converter.convertFromStrings(Long.TYPE, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertEquals(l, 0);

    float f = (Float) converter.convertFromStrings(Float.TYPE, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertEquals(f, 0, 0);

    double d = (Double) converter.convertFromStrings(Double.TYPE, null, "testExpr",
            ArrayUtils.toArray((String) null));
    assertEquals(d, 0, 0);

    bw = (Byte) converter.convertFromStrings(Byte.class, null, "testExpr", ArrayUtils.toArray("1"));
    assertEquals((byte) bw, 1);

    sw = (Short) converter.convertFromStrings(Short.class, null, "testExpr", ArrayUtils.toArray("1"));
    assertEquals((short) sw, 1);

    iw = (Integer) converter.convertFromStrings(Integer.class, null, "testExpr", ArrayUtils.toArray("1"));
    assertEquals((int) iw, 1);

    lw = (Long) converter.convertFromStrings(Long.class, null, "testExpr", ArrayUtils.toArray("1"));
    assertEquals((long) lw, 1l);

    fw = (Float) converter.convertFromStrings(Float.class, null, "testExpr", ArrayUtils.toArray("1"));
    assertEquals(1f, fw, 0);

    dw = (Double) converter.convertFromStrings(Double.class, null, "testExpr", ArrayUtils.toArray("1"));
    assertEquals(1d, dw, 0);

    bw = (Byte) converter.convertFromStrings(Byte.class, null, "testExpr", ArrayUtils.toArray("   "));
    assertNull(bw);

    sw = (Short) converter.convertFromStrings(Short.class, null, "testExpr", ArrayUtils.toArray("   "));
    assertNull(sw);

    iw = (Integer) converter.convertFromStrings(Integer.class, null, "testExpr", ArrayUtils.toArray("   "));
    assertNull(iw);

    lw = (Long) converter.convertFromStrings(Long.class, null, "testExpr", ArrayUtils.toArray("   "));
    assertNull(lw);

    fw = (Float) converter.convertFromStrings(Float.class, null, "testExpr", ArrayUtils.toArray("   "));
    assertNull(fw);

    dw = (Double) converter.convertFromStrings(Double.class, null, "testExpr", ArrayUtils.toArray("   "));
    assertNull(dw);

    b = (Byte) converter.convertFromStrings(Byte.TYPE, null, "testExpr", ArrayUtils.toArray("   "));
    assertEquals(b, 0);

    s = (Short) converter.convertFromStrings(Short.TYPE, null, "testExpr", ArrayUtils.toArray("   "));
    assertEquals(s, 0);

    i = (Integer) converter.convertFromStrings(Integer.TYPE, null, "testExpr", ArrayUtils.toArray("   "));
    assertEquals(i, 0);

    l = (Long) converter.convertFromStrings(Long.TYPE, null, "testExpr", ArrayUtils.toArray("   "));
    assertEquals(l, 0);

    f = (Float) converter.convertFromStrings(Float.TYPE, null, "testExpr", ArrayUtils.toArray("   "));
    assertEquals(0, f, 0);

    d = (Double) converter.convertFromStrings(Double.TYPE, null, "testExpr", ArrayUtils.toArray("   "));
    assertEquals(d, 0, 0);

    try {
        converter.convertFromStrings(Byte.class, null, "testExpr", ArrayUtils.toArray("bad"));
        fail("Should have failed");
    } catch (ConversionException ce) {
        // Expected
    }

    try {
        converter.convertFromStrings(Short.class, null, "testExpr", ArrayUtils.toArray("bad"));
        fail("Should have failed");
    } catch (ConversionException ce) {
        // Expected
    }

    try {
        converter.convertFromStrings(Integer.class, null, "testExpr", ArrayUtils.toArray("bad"));
        fail("Should have failed");
    } catch (ConversionException ce) {
        // Expected
    }

    try {
        converter.convertFromStrings(Long.class, null, "testExpr", ArrayUtils.toArray("bad"));
        fail("Should have failed");
    } catch (ConversionException ce) {
        // Expected
    }

    try {
        converter.convertFromStrings(Float.class, null, "testExpr", ArrayUtils.toArray("bad"));
        fail("Should have failed");
    } catch (ConversionException ce) {
        // Expected
    }

    try {
        converter.convertFromStrings(Double.class, null, "testExpr", ArrayUtils.toArray("bad"));
        fail("Should have failed");
    } catch (ConversionException ce) {
        // Expected
    }
}

From source file:org.openTwoFactor.clientExt.net.sf.ezmorph.primitive.DoubleMorpher.java

public Class morphsTo() {
    return Double.TYPE;
}