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

private static Class<?> getPrimitive(Class<?> argClass) {
    if (argClass == Boolean.class)
        return Boolean.TYPE;
    else if (argClass == Character.class)
        return Character.TYPE;
    else if (argClass == Byte.class)
        return Byte.TYPE;
    else if (argClass == Short.class)
        return Short.TYPE;
    else if (argClass == Integer.class)
        return Integer.TYPE;
    else if (argClass == Long.class)
        return Long.TYPE;
    else if (argClass == Float.class)
        return Float.TYPE;
    else if (argClass == Double.class)
        return Double.TYPE;
    else/*from ww  w .j a v a 2s .com*/
        return null;
}

From source file:io.amira.zen.layout.ZenViewProxy.java

private void _fill_classes() {
    class_convert = new HashMap<Class, Class>();
    class_convert.put(Integer.class, Integer.TYPE);
    class_convert.put(Float.class, Float.TYPE);
    class_convert.put(Double.class, Double.TYPE);
    class_convert.put(Boolean.class, Boolean.TYPE);
}

From source file:org.mule.util.ArrayUtils.java

/**
 * Like {@link #toString(Object)} but considers at most <code>maxElements</code>
 * values; overflow is indicated by an appended "[..]" ellipsis.
 *//* ww w.  j a  va2 s  . com*/
public static String toString(Object array, int maxElements) {
    String result;

    Class componentType = array.getClass().getComponentType();
    if (Object.class.isAssignableFrom(componentType)) {
        result = ArrayUtils.toString((ArrayUtils.subarray((Object[]) array, 0, maxElements)));
    } else if (componentType.equals(Boolean.TYPE)) {
        result = ArrayUtils.toString((ArrayUtils.subarray((boolean[]) array, 0, maxElements)));
    } else if (componentType.equals(Byte.TYPE)) {
        result = ArrayUtils.toString((ArrayUtils.subarray((byte[]) array, 0, maxElements)));
    } else if (componentType.equals(Character.TYPE)) {
        result = ArrayUtils.toString((ArrayUtils.subarray((char[]) array, 0, maxElements)));
    } else if (componentType.equals(Short.TYPE)) {
        result = ArrayUtils.toString((ArrayUtils.subarray((short[]) array, 0, maxElements)));
    } else if (componentType.equals(Integer.TYPE)) {
        result = ArrayUtils.toString((ArrayUtils.subarray((int[]) array, 0, maxElements)));
    } else if (componentType.equals(Long.TYPE)) {
        result = ArrayUtils.toString((ArrayUtils.subarray((long[]) array, 0, maxElements)));
    } else if (componentType.equals(Float.TYPE)) {
        result = ArrayUtils.toString((ArrayUtils.subarray((float[]) array, 0, maxElements)));
    } else if (componentType.equals(Double.TYPE)) {
        result = ArrayUtils.toString((ArrayUtils.subarray((double[]) array, 0, maxElements)));
    } else {
        throw new IllegalArgumentException("Unknown array service type: " + componentType.getName());
    }

    if (Array.getLength(array) > maxElements) {
        StringBuffer buf = new StringBuffer(result);
        buf.insert(buf.length() - 1, " [..]");
        result = buf.toString();
    }

    return result;

}

From source file:com.ms.commons.summer.web.util.json.JsonNumberMorpher.java

/**
 * Creates a new morpher for the target type.
 * //from   ww w  . j  a  v  a  2s .co  m
 * @param type must be a primitive or wrapper type. BigDecimal and BigInteger are also supported.
 */
public JsonNumberMorpher(Class<?> type) {
    super(false);

    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:Main.java

public static String getPrimitiveLetter(Class<?> paramClass) {
    if (Integer.TYPE.equals(paramClass)) {
        return "I";
    }// w w w  .  j a v  a  2 s.co  m
    if (Void.TYPE.equals(paramClass)) {
        return "V";
    }
    if (Boolean.TYPE.equals(paramClass)) {
        return "Z";
    }
    if (Character.TYPE.equals(paramClass)) {
        return "C";
    }
    if (Byte.TYPE.equals(paramClass)) {
        return "B";
    }
    if (Short.TYPE.equals(paramClass)) {
        return "S";
    }
    if (Float.TYPE.equals(paramClass)) {
        return "F";
    }
    if (Long.TYPE.equals(paramClass)) {
        return "J";
    }
    if (Double.TYPE.equals(paramClass)) {
        return "D";
    }
    throw new IllegalStateException("Type: " + paramClass.getCanonicalName() + " is not a primitive type");
}

From source file:org.wso2.carbon.analytics.spark.core.util.AnalyticsCommonUtils.java

public static DataType getDataType(Type returnType) throws AnalyticsUDFException {
    DataType udfReturnType = null;/*from ww w  .j  av  a2  s.co  m*/
    if (returnType == Integer.TYPE || returnType == Integer.class) {
        udfReturnType = DataTypes.IntegerType;
    } else if (returnType == Double.TYPE || returnType == Double.class) {
        udfReturnType = DataTypes.DoubleType;
    } else if (returnType == Float.TYPE || returnType == Float.class) {
        udfReturnType = DataTypes.FloatType;
    } else if (returnType == Long.TYPE || returnType == Long.class) {
        udfReturnType = DataTypes.LongType;
    } else if (returnType == Boolean.TYPE || returnType == Boolean.class) {
        udfReturnType = DataTypes.BooleanType;
    } else if (returnType == String.class) {
        udfReturnType = DataTypes.StringType;
    } else if (returnType == Short.TYPE || returnType == Short.class) {
        udfReturnType = DataTypes.ShortType;
    } else if (returnType == NullType.class) {
        udfReturnType = DataTypes.NullType;
    } else if (returnType == Byte.TYPE || returnType == Byte.class) {
        udfReturnType = DataTypes.ByteType;
    } else if (returnType == byte[].class || returnType == Byte[].class) {
        udfReturnType = DataTypes.BinaryType;
    } else if (returnType == Date.class) {
        udfReturnType = DataTypes.DateType;
    } else if (returnType == Timestamp.class) {
        udfReturnType = DataTypes.TimestampType;
    } else if (returnType == BigDecimal.class) {
        udfReturnType = DataTypes.createDecimalType();
    } else if (returnType instanceof ParameterizedType) {
        ParameterizedType type = (ParameterizedType) returnType;
        /*if return type is a List types will contain only 1 element, if return type is Map it will have
        2 elements types representing key and the value.*/
        Type[] types = type.getActualTypeArguments();
        if (types != null && types.length > 0) {
            switch (types.length) {
            case 1: {
                udfReturnType = DataTypes.createArrayType(getDataType(types[0]));
                break;
            }
            case 2: {
                udfReturnType = DataTypes.createMapType(getDataType(types[0]), getDataType(types[1]));
                break;
            }
            default:
                throw new AnalyticsUDFException("Cannot Map the return type either to ArrayType or MapType");
            }
        }
    } else {
        throw new AnalyticsUDFException("Cannot determine the return DataType");
    }
    return udfReturnType;
}

From source file:com.browseengine.bobo.serialize.JSONSerializer.java

private static void loadObject(Object array, Class type, int index, JSONArray jsonArray)
        throws JSONSerializationException, JSONException {
    if (type.isPrimitive()) {
        if (type == Integer.TYPE) {
            Array.setInt(array, index, jsonArray.getInt(index));
        } else if (type == Long.TYPE) {
            Array.setLong(array, index, jsonArray.getInt(index));
        } else if (type == Short.TYPE) {
            Array.setShort(array, index, (short) jsonArray.getInt(index));
        } else if (type == Boolean.TYPE) {
            Array.setBoolean(array, index, jsonArray.getBoolean(index));
        } else if (type == Double.TYPE) {
            Array.setDouble(array, index, jsonArray.getDouble(index));
        } else if (type == Float.TYPE) {
            Array.setFloat(array, index, (float) jsonArray.getDouble(index));
        } else if (type == Character.TYPE) {
            char ch = jsonArray.getString(index).charAt(0);
            Array.setChar(array, index, ch);
        } else if (type == Byte.TYPE) {
            Array.setByte(array, index, (byte) jsonArray.getInt(index));
        } else {/*  ww w.j  a  v  a  2s . com*/
            throw new JSONSerializationException("Unknown primitive: " + type);
        }
    } else if (type == String.class) {
        Array.set(array, index, jsonArray.getString(index));
    } else if (JSONSerializable.class.isAssignableFrom(type)) {
        JSONObject jObj = jsonArray.getJSONObject(index);
        JSONSerializable serObj = deSerialize(type, jObj);
        Array.set(array, index, serObj);
    } else if (type.isArray()) {
        Class componentClass = type.getComponentType();
        JSONArray subArray = jsonArray.getJSONArray(index);
        int len = subArray.length();

        Object newArray = Array.newInstance(componentClass, len);
        for (int k = 0; k < len; ++k) {
            loadObject(newArray, componentClass, k, subArray);
        }
    }
}

From source file:Main.java

/**
 * <p>Copies the given array and adds the given element at the end of the new array.</p>
 *
 * <p>The new array contains the same elements of the input
 * array plus the given element in the last position. The component type of 
 * the new array is the same as that of the input array.</p>
 *
 * <p>If the input array is <code>null</code>, a new one element array is returned
 *  whose component type is the same as the element.</p>
 * //  w  w  w .  j  a va 2  s.  c o m
 * <pre>
 * ArrayUtils.add(null, 0)   = [0]
 * ArrayUtils.add([1], 0)    = [1, 0]
 * ArrayUtils.add([1, 0], 1) = [1, 0, 1]
 * </pre>
 * 
 * @param array  the array to copy and add the element to, may be <code>null</code>
 * @param element  the object to add at the last index of the new array
 * @return A new array containing the existing elements plus the new element
 * @since 2.1
 */
public static double[] add(double[] array, double element) {
    double[] newArray = (double[]) copyArrayGrow1(array, Double.TYPE);
    newArray[newArray.length - 1] = element;
    return newArray;
}

From source file:org.impalaframework.spring.DebuggingInterceptor.java

public Object invoke(MethodInvocation invocation) throws Throwable {

    logger.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;/*  www.  j av  a2s. c  o  m*/
}

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

public static Comparable<?> convertTo(Class<?> clazz, Object obj) {
    if (obj == null) {
        return null;
    }/*from www.java2  s.c  om*/
    if (clazz.isAssignableFrom(obj.getClass())) {
        return (Comparable<?>) obj;
    }
    if (clazz.isPrimitive()) {
        if (clazz.equals(Long.TYPE)) {
            clazz = Long.class;
        } else if (clazz.equals(Integer.TYPE)) {
            clazz = Integer.class;
        } else if (clazz.equals(Float.TYPE)) {
            clazz = Float.class;
        } else if (clazz.equals(Double.TYPE)) {
            clazz = Double.class;
        } else if (clazz.equals(Boolean.TYPE)) {
            clazz = Boolean.class;
        }
    }
    if (Number.class.isAssignableFrom(clazz)) {
        if (obj.getClass().equals(String.class)) {
            obj = new Double((String) obj);
        }
        if (!Number.class.isAssignableFrom(obj.getClass())) {
            throw new RuntimeException(
                    "Cannot convert from " + obj.getClass().getName() + " to " + clazz.getName());
        }
        Number number = (Number) obj;
        if (clazz.equals(Long.class)) {
            return new Long(number.longValue());
        }
        if (clazz.equals(Integer.class)) {
            return new Integer(number.intValue());
        }
        if (clazz.equals(Float.class)) {
            return new Float(number.floatValue());
        }
        if (clazz.equals(Double.class)) {
            return new Double(number.doubleValue());
        }
        if (clazz.equals(BigDecimal.class)) {
            return new BigDecimal(number.doubleValue());
        }
    }
    final String oStr = String.valueOf(obj);
    if (clazz.equals(String.class)) {
        return 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);
    }
    if (clazz.equals(Boolean.class)) {
        return new Boolean(oStr);
    }
    throw new RuntimeException("Cannot convert from " + obj.getClass().getName() + " to " + clazz.getName());
}