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:com.phoenixnap.oss.ramlapisync.naming.SchemaHelper.java

/**
 * Maps primitives and other simple Java types into simple types supported by RAML
 * //from w w w.j ava2 s. co m
 * @param clazz The Class to map
 * @return The Simple RAML ParamType which maps to this class or null if one is not found
 */
public static ParamType mapSimpleType(Class<?> clazz) {
    Class<?> targetClazz = clazz;
    if (targetClazz.isArray() && clazz.getComponentType() != null) {
        targetClazz = clazz.getComponentType();
    }
    if (targetClazz.equals(Long.TYPE) || targetClazz.equals(Long.class) || targetClazz.equals(Integer.TYPE)
            || targetClazz.equals(Integer.class) || targetClazz.equals(Short.TYPE)
            || targetClazz.equals(Short.class) || targetClazz.equals(Byte.TYPE)
            || targetClazz.equals(Byte.class)) {
        return ParamType.INTEGER;
    } else if (targetClazz.equals(Float.TYPE) || targetClazz.equals(Float.class)
            || targetClazz.equals(Double.TYPE) || targetClazz.equals(Double.class)
            || targetClazz.equals(BigDecimal.class)) {
        return ParamType.NUMBER;
    } else if (targetClazz.equals(Boolean.class) || targetClazz.equals(Boolean.TYPE)) {
        return ParamType.BOOLEAN;
    } else if (targetClazz.equals(String.class)) {
        return ParamType.STRING;
    }
    return null; // default to string
}

From source file:com.exadel.flamingo.flex.messaging.amf.io.AMF0Serializer.java

protected Object[] convertPrimitiveArrayToObjectArray(Object array) {
    Class<?> componentType = array.getClass().getComponentType();

    Object[] result = null;/*  www . j a v  a 2  s.c o  m*/

    if (componentType == null) {
        throw new NullPointerException("componentType is null");
    } else if (componentType == Character.TYPE) {
        char[] carray = (char[]) array;
        result = new Object[carray.length];
        for (int i = 0; i < carray.length; i++) {
            result[i] = new Character(carray[i]);
        }
    } else if (componentType == Byte.TYPE) {
        byte[] barray = (byte[]) array;
        result = new Object[barray.length];
        for (int i = 0; i < barray.length; i++) {
            result[i] = new Byte(barray[i]);
        }
    } else if (componentType == Short.TYPE) {
        short[] sarray = (short[]) array;
        result = new Object[sarray.length];
        for (int i = 0; i < sarray.length; i++) {
            result[i] = new Short(sarray[i]);
        }
    } else if (componentType == Integer.TYPE) {
        int[] iarray = (int[]) array;
        result = new Object[iarray.length];
        for (int i = 0; i < iarray.length; i++) {
            result[i] = Integer.valueOf(iarray[i]);
        }
    } else if (componentType == Long.TYPE) {
        long[] larray = (long[]) array;
        result = new Object[larray.length];
        for (int i = 0; i < larray.length; i++) {
            result[i] = new Long(larray[i]);
        }
    } else if (componentType == Double.TYPE) {
        double[] darray = (double[]) array;
        result = new Object[darray.length];
        for (int i = 0; i < darray.length; i++) {
            result[i] = new Double(darray[i]);
        }
    } else if (componentType == Float.TYPE) {
        float[] farray = (float[]) array;
        result = new Object[farray.length];
        for (int i = 0; i < farray.length; i++) {
            result[i] = new Float(farray[i]);
        }
    } else if (componentType == Boolean.TYPE) {
        boolean[] barray = (boolean[]) array;
        result = new Object[barray.length];
        for (int i = 0; i < barray.length; i++) {
            result[i] = new Boolean(barray[i]);
        }
    } else {
        throw new IllegalArgumentException("unexpected component type: " + componentType.getClass().getName());
    }

    return result;
}

From source file:org.brekka.stillingar.spring.bpp.ConfigurationBeanPostProcessorTest.java

@Test
public void primitiveDefaultFloat() {
    assertEquals(ConfigurationBeanPostProcessor.primitiveDefault(Float.TYPE), Float.valueOf(0f));
}

From source file:com.examples.with.different.packagename.testcarver.AbstractConverter.java

/**
 * Change primitve Class types to the associated wrapper class.
 * @param type The class type to check./*from   w w w . ja v  a2  s .  c  o  m*/
 * @return The converted type.
 */
Class primitive(Class type) {
    if (type == null || !type.isPrimitive()) {
        return type;
    }

    if (type == Integer.TYPE) {
        return Integer.class;
    } else if (type == Double.TYPE) {
        return Double.class;
    } else if (type == Long.TYPE) {
        return Long.class;
    } else if (type == Boolean.TYPE) {
        return Boolean.class;
    } else if (type == Float.TYPE) {
        return Float.class;
    } else if (type == Short.TYPE) {
        return Short.class;
    } else if (type == Byte.TYPE) {
        return Byte.class;
    } else if (type == Character.TYPE) {
        return Character.class;
    } else {
        return type;
    }
}

From source file:com.mawujun.util.AnnotationUtils.java

/**
 * Helper method for generating a hash code for an array.
 *
 * @param componentType the component type of the array
 * @param o the array//from  w  w w.  j  a  v a2 s.c o  m
 * @return a hash code for the specified array
 */
private static int arrayMemberHash(Class<?> componentType, Object o) {
    if (componentType.equals(Byte.TYPE)) {
        return Arrays.hashCode((byte[]) o);
    }
    if (componentType.equals(Short.TYPE)) {
        return Arrays.hashCode((short[]) o);
    }
    if (componentType.equals(Integer.TYPE)) {
        return Arrays.hashCode((int[]) o);
    }
    if (componentType.equals(Character.TYPE)) {
        return Arrays.hashCode((char[]) o);
    }
    if (componentType.equals(Long.TYPE)) {
        return Arrays.hashCode((long[]) o);
    }
    if (componentType.equals(Float.TYPE)) {
        return Arrays.hashCode((float[]) o);
    }
    if (componentType.equals(Double.TYPE)) {
        return Arrays.hashCode((double[]) o);
    }
    if (componentType.equals(Boolean.TYPE)) {
        return Arrays.hashCode((boolean[]) o);
    }
    return Arrays.hashCode((Object[]) o);
}

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

/**
 * DOCUMENT ME!/*from  ww w. j  av a2  s .co m*/
 *
 * @param clazz DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
private boolean isFloat(Class clazz) {
    return Float.class.isAssignableFrom(clazz) || (clazz == Float.TYPE);
}

From source file:at.alladin.rmbt.shared.hstoreparser.HstoreParser.java

/**
 * /*ww  w  .  ja  v a  2s . c o m*/
 * @param f
 * @param o
 * @return
 */
public static Object parseFieldValue(Field f, Object o) {
    if (o != JSONObject.NULL) {
        if (f.getType().equals(Integer.class) || f.getType().equals(Integer.TYPE)) {
            return Integer.parseInt(String.valueOf(o));
        } else if (f.getType().equals(String.class)) {
            return String.valueOf(o);
        } else if (f.getType().equals(Long.class) || f.getType().equals(Long.TYPE)) {
            return Long.parseLong(String.valueOf(o));
        } else if (f.getType().equals(Boolean.class) || f.getType().equals(Boolean.TYPE)) {
            return Boolean.parseBoolean(String.valueOf(o));
        } else if (f.getType().equals(Float.class) || f.getType().equals(Float.TYPE)) {
            return Float.parseFloat(String.valueOf(o));
        } else if (f.getType().equals(Double.class) || f.getType().equals(Double.TYPE)) {
            return Double.parseDouble(String.valueOf(o));
        } else if (f.getType().equals(Short.class) || f.getType().equals(Short.TYPE)) {
            return Short.parseShort(String.valueOf(o));
        } else {
            return o;
        }
    }

    return null;
}

From source file:javadz.beanutils.ConvertUtilsBean.java

/**
 * Sets the default value for Float conversions.
 * @param newDefaultFloat The default Float value
 * @deprecated Register replacement converters for Float.TYPE and
 *  Float.class instead/*  w  w  w .ja v  a2s .  co m*/
 */
public void setDefaultFloat(float newDefaultFloat) {
    defaultFloat = new Float(newDefaultFloat);
    register(new FloatConverter(defaultFloat), Float.TYPE);
    register(new FloatConverter(defaultFloat), Float.class);
}

From source file:com.gdcn.modules.db.jdbc.processor.CamelBeanProcessor.java

/**
 * ResultSet.getObject() returns an Integer object for an INT column.  The
 * setter method for the property might take an Integer or a primitive int.
 * This method returns true if the value can be successfully passed into
 * the setter method.  Remember, Method.invoke() handles the unwrapping
 * of Integer into an int.//from  w  ww.  j  a va 2  s .c  om
 *
 * @param value The value to be passed into the setter method.
 * @param type The setter's parameter type (non-null)
 * @return boolean True if the value is compatible (null => true)
 */
private boolean isCompatibleType(Object value, Class<?> type) {
    // Do object check first, then primitives
    if (value == null || type.isInstance(value)) {
        return true;

    } else if (type.equals(Integer.TYPE) && Integer.class.isInstance(value)) {
        return true;

    } else if (type.equals(Long.TYPE) && Long.class.isInstance(value)) {
        return true;

    } else if (type.equals(Double.TYPE) && Double.class.isInstance(value)) {
        return true;

    } else if (type.equals(Float.TYPE) && Float.class.isInstance(value)) {
        return true;

    } else if (type.equals(Short.TYPE) && Short.class.isInstance(value)) {
        return true;

    } else if (type.equals(Byte.TYPE) && Byte.class.isInstance(value)) {
        return true;

    } else if (type.equals(Character.TYPE) && Character.class.isInstance(value)) {
        return true;

    } else if (type.equals(Boolean.TYPE) && Boolean.class.isInstance(value)) {
        return true;

    }
    return false;

}

From source file:org.cloudata.core.common.io.CObjectWritable.java

/** Read a {@link CWritable}, {@link String}, primitive type, or an array of
 * the preceding. *//*ww  w  .  j a  va 2 s  . c o m*/
@SuppressWarnings("unchecked")
public static Object readObject(DataInput in, CObjectWritable objectWritable, CloudataConf conf,
        boolean arrayComponent, Class componentClass) throws IOException {
    String className;
    if (arrayComponent) {
        className = componentClass.getName();
    } else {
        className = CUTF8.readString(in);
        //SANGCHUL
        //   System.out.println("SANGCHUL] className:" + className);
    }

    Class<?> declaredClass = PRIMITIVE_NAMES.get(className);
    if (declaredClass == null) {
        try {
            declaredClass = conf.getClassByName(className);
        } catch (ClassNotFoundException e) {
            //SANGCHUL
            e.printStackTrace();
            throw new RuntimeException("readObject can't find class[className=" + className + "]", e);
        }
    }

    Object instance;

    if (declaredClass.isPrimitive()) { // primitive types

        if (declaredClass == Boolean.TYPE) { // boolean
            instance = Boolean.valueOf(in.readBoolean());
        } else if (declaredClass == Character.TYPE) { // char
            instance = Character.valueOf(in.readChar());
        } else if (declaredClass == Byte.TYPE) { // byte
            instance = Byte.valueOf(in.readByte());
        } else if (declaredClass == Short.TYPE) { // short
            instance = Short.valueOf(in.readShort());
        } else if (declaredClass == Integer.TYPE) { // int
            instance = Integer.valueOf(in.readInt());
        } else if (declaredClass == Long.TYPE) { // long
            instance = Long.valueOf(in.readLong());
        } else if (declaredClass == Float.TYPE) { // float
            instance = Float.valueOf(in.readFloat());
        } else if (declaredClass == Double.TYPE) { // double
            instance = Double.valueOf(in.readDouble());
        } else if (declaredClass == Void.TYPE) { // void
            instance = null;
        } else {
            throw new IllegalArgumentException("Not a primitive: " + declaredClass);
        }

    } else if (declaredClass.isArray()) { // array
        //System.out.println("SANGCHUL] is array");
        int length = in.readInt();
        //System.out.println("SANGCHUL] array length : " + length);
        //System.out.println("Read:in.readInt():" + length);
        if (declaredClass.getComponentType() == Byte.TYPE) {
            byte[] bytes = new byte[length];
            in.readFully(bytes);
            instance = bytes;
        } else if (declaredClass.getComponentType() == ColumnValue.class) {
            instance = readColumnValue(in, conf, declaredClass, length);
        } else {
            Class componentType = declaredClass.getComponentType();

            // SANGCHUL
            //System.out.println("SANGCHUL] componentType : " + componentType.getName());

            instance = Array.newInstance(componentType, length);
            for (int i = 0; i < length; i++) {
                Object arrayComponentInstance = readObject(in, null, conf, !componentType.isArray(),
                        componentType);
                Array.set(instance, i, arrayComponentInstance);
                //Array.set(instance, i, readObject(in, conf));
            }
        }
    } else if (declaredClass == String.class) { // String
        instance = CUTF8.readString(in);
    } else if (declaredClass.isEnum()) { // enum
        instance = Enum.valueOf((Class<? extends Enum>) declaredClass, CUTF8.readString(in));
    } else if (declaredClass == ColumnValue.class) {
        //ColumnValue?  ?? ?? ?  ? ?.
        //? ?   ? ? ? ? . 
        Class instanceClass = null;
        try {
            short typeDiff = in.readShort();
            if (typeDiff == TYPE_DIFF) {
                instanceClass = conf.getClassByName(CUTF8.readString(in));
            } else {
                instanceClass = declaredClass;
            }
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("readObject can't find class", e);
        }
        ColumnValue columnValue = new ColumnValue();
        columnValue.readFields(in);
        instance = columnValue;
    } else { // Writable

        Class instanceClass = null;
        try {
            short typeDiff = in.readShort();
            // SANGCHUL
            //System.out.println("SANGCHUL] typeDiff : " + typeDiff);
            //System.out.println("Read:in.readShort():" + typeDiff);
            if (typeDiff == TYPE_DIFF) {
                // SANGCHUL
                String classNameTemp = CUTF8.readString(in);
                //System.out.println("SANGCHUL] typeDiff : " + classNameTemp);
                instanceClass = conf.getClassByName(classNameTemp);
                //System.out.println("Read:UTF8.readString(in):" + instanceClass.getClass());
            } else {
                instanceClass = declaredClass;
            }
        } catch (ClassNotFoundException e) {

            // SANGCHUL
            e.printStackTrace();
            throw new RuntimeException("readObject can't find class", e);
        }

        CWritable writable = CWritableFactories.newInstance(instanceClass, conf);
        writable.readFields(in);
        //System.out.println("Read:writable.readFields(in)");
        instance = writable;

        if (instanceClass == NullInstance.class) { // null
            declaredClass = ((NullInstance) instance).declaredClass;
            instance = null;
        }
    }

    if (objectWritable != null) { // store values
        objectWritable.declaredClass = declaredClass;
        objectWritable.instance = instance;
    }

    return instance;
}