Example usage for java.lang Float TYPE

List of usage examples for java.lang Float TYPE

Introduction

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

Prototype

Class TYPE

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

Click Source Link

Document

The Class instance representing the primitive type float .

Usage

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;/*from w  ww . ja  v a  2 s  .c o m*/
}

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;/*  w  ww. jav  a  2s . 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");
    }//from   ww  w. j  a va 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:org.wso2.carbon.analytics.spark.core.util.AnalyticsCommonUtils.java

public static DataType getDataType(Type returnType) throws AnalyticsUDFException {
    DataType udfReturnType = null;//from   ww w. ja v a 2s.  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 {// w  w  w .  j av 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:org.dhatim.javabean.BeanUtils.java

/**
 * Create the bean setter method instance for this visitor.
 *
 * @param setterName The setter method name.
 * @param setterParamType//  ww w. ja  va2s. 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: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 .ja  v a  2  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;
    }
}

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

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

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

private void initSetterMethod(Object o) throws Exception {
    Class valueClass;//from   ww  w.jav 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 });
}

From source file:com.bedatadriven.rebar.persistence.mapping.PrimitiveMapping.java

public PrimitiveMapping(MethodInfo getter) {
    super(getter);

    TypeInfo type = getter.getReturnType();
    Class primitive = type.isPrimitive();

    this.boxed = (primitive == null);

    if (primitive != null) {
        this.nullable = false;
    }/*from  w w w  .jav  a 2  s  . c om*/

    if (primitive == Integer.TYPE || type.getQualifiedName().equals(Integer.class.getName())
            || primitive == Short.TYPE || type.getQualifiedName().equals(Short.class.getName())
            || primitive == Long.TYPE || type.getQualifiedName().equals(Long.class.getName())
            || primitive == Byte.TYPE || type.getQualifiedName().equals(Byte.class.getName())
            || primitive == Boolean.TYPE || type.getQualifiedName().equals(Boolean.class.getName())) {

        sqlTypeName = SqliteTypes.integer;

    } else if (primitive == Float.TYPE || type.getQualifiedName().equals(Float.class.getName())
            || primitive == Double.TYPE || type.getQualifiedName().equals(Double.class.getName())) {

        sqlTypeName = SqliteTypes.real;

    } else if (primitive == Character.TYPE || type.getQualifiedName().equals(Character.class.getName())) {

        sqlTypeName = SqliteTypes.text;
    }

    String suffix = type.getSimpleName();

    if (suffix.equals("Integer")) {
        suffix = "Int";
    } else if (suffix.equals("Character")) {
        suffix = "Char";
    }
    suffix = suffix.substring(0, 1).toUpperCase() + suffix.substring(1);

    readerName = "Readers.read" + suffix;
    stmtSetter = "set" + suffix;

}