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

/**
 * <p>Inserts the specified element at the specified position in the array.
 * Shifts the element currently at that position (if any) and any subsequent
 * elements to the right (adds one to their indices).</p>
 *
 * <p>This method returns a new array with the same elements of the input
 * array plus the given element on the specified position. The component
 * type of the returned array is always the same as that of the input
 * array.</p>/*w  w  w . j av  a2s  .  c  om*/
 *
 * <p>If the input array is {@code null}, a new one element array is returned
 *  whose component type is the same as the element.</p>
 *
 * <pre>
 * ArrayUtils.add([1.1f], 0, 2.2f)               = [2.2f, 1.1f]
 * ArrayUtils.add([2.3f, 6.4f], 2, 10.5f)        = [2.3f, 6.4f, 10.5f]
 * ArrayUtils.add([2.6f, 6.7f], 0, -4.8f)        = [-4.8f, 2.6f, 6.7f]
 * ArrayUtils.add([2.9f, 6.0f, 0.3f], 2, 1.0f)   = [2.9f, 6.0f, 1.0f, 0.3f]
 * </pre>
 *
 * @param array  the array to add the element to, may be {@code null}
 * @param index  the position of the new object
 * @param element  the object to add
 * @return A new array containing the existing elements and the new element
 * @throws IndexOutOfBoundsException if the index is out of range
 * (index < 0 || index > array.length).
 */
public static float[] add(float[] array, int index, float element) {
    return (float[]) add(array, index, Float.valueOf(element), Float.TYPE);
}

From source file:Main.java

/**
 * <p>Inserts the specified element at the specified position in the array.
 * Shifts the element currently at that position (if any) and any subsequent
 * elements to the right (adds one to their indices).</p>
 *
 * <p>This method returns a new array with the same elements of the input
 * array plus the given element on the specified position. The component
 * type of the returned array is always the same as that of the input
 * array.</p>/* www  . j  a  v a2s  . co m*/
 *
 * <p>If the input array is {@code null}, a new one element array is returned
 *  whose component type is the same as the element.</p>
 *
 * <pre>
 * ArrayUtils.add([1.1f], 0, 2.2f)               = [2.2f, 1.1f]
 * ArrayUtils.add([2.3f, 6.4f], 2, 10.5f)        = [2.3f, 6.4f, 10.5f]
 * ArrayUtils.add([2.6f, 6.7f], 0, -4.8f)        = [-4.8f, 2.6f, 6.7f]
 * ArrayUtils.add([2.9f, 6.0f, 0.3f], 2, 1.0f)   = [2.9f, 6.0f, 1.0f, 0.3f]
 * </pre>
 *
 * @param array  the array to add the element to, may be {@code null}
 * @param index  the position of the new object
 * @param element  the object to add
 * @return A new array containing the existing elements and the new element
 * @throws IndexOutOfBoundsException if the index is out of range
 * (index < 0 || index > array.length).
 */
public static float[] add(final float[] array, final int index, final float element) {
    return (float[]) add(array, index, Float.valueOf(element), Float.TYPE);
}

From source file:javadz.beanutils.ConvertUtilsBean.java

/**
 * Register the converters for primitive types.
 * </p>/*w ww.j  ava2  s  .c  o m*/
 * This method registers the following converters:
 * <ul>
 *     <li><code>Boolean.TYPE</code> - {@link BooleanConverter}</li>
 *     <li><code>Byte.TYPE</code> - {@link ByteConverter}</li>
 *     <li><code>Character.TYPE</code> - {@link CharacterConverter}</li>
 *     <li><code>Double.TYPE</code> - {@link DoubleConverter}</li>
 *     <li><code>Float.TYPE</code> - {@link FloatConverter}</li>
 *     <li><code>Integer.TYPE</code> - {@link IntegerConverter}</li>
 *     <li><code>Long.TYPE</code> - {@link LongConverter}</li>
 *     <li><code>Short.TYPE</code> - {@link ShortConverter}</li>
 * </ul>
 * @param throwException <code>true</code> if the converters should
 * throw an exception when a conversion error occurs, otherwise <code>
 * <code>false</code> if a default value should be used.
 */
private void registerPrimitives(boolean throwException) {
    register(Boolean.TYPE, throwException ? new BooleanConverter() : new BooleanConverter(Boolean.FALSE));
    register(Byte.TYPE, throwException ? new ByteConverter() : new ByteConverter(ZERO));
    register(Character.TYPE, throwException ? new CharacterConverter() : new CharacterConverter(SPACE));
    register(Double.TYPE, throwException ? new DoubleConverter() : new DoubleConverter(ZERO));
    register(Float.TYPE, throwException ? new FloatConverter() : new FloatConverter(ZERO));
    register(Integer.TYPE, throwException ? new IntegerConverter() : new IntegerConverter(ZERO));
    register(Long.TYPE, throwException ? new LongConverter() : new LongConverter(ZERO));
    register(Short.TYPE, throwException ? new ShortConverter() : new ShortConverter(ZERO));
}

From source file:org.apache.hadoop.hbase.io.HbaseObjectWritable.java

/**
 * Read a {@link Writable}, {@link String}, primitive type, or an array of
 * the preceding./*from  www  .  ja v a 2 s . c  o m*/
 * @param in
 * @param objectWritable
 * @param conf
 * @return the object
 * @throws IOException
 */
@SuppressWarnings("unchecked")
public static Object readObject(DataInput in, HbaseObjectWritable objectWritable, Configuration conf)
        throws IOException {
    Class<?> declaredClass = CODE_TO_CLASS.get(WritableUtils.readVInt(in));
    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
        if (declaredClass.equals(byte[].class)) {
            instance = Bytes.readByteArray(in);
        } else if (declaredClass.equals(Result[].class)) {
            instance = Result.readArray(in);
        } else {
            int length = in.readInt();
            instance = Array.newInstance(declaredClass.getComponentType(), length);
            for (int i = 0; i < length; i++) {
                Array.set(instance, i, readObject(in, conf));
            }
        }
    } else if (declaredClass.equals(Array.class)) { //an array not declared in CLASS_TO_CODE
        Class<?> componentType = readClass(conf, in);
        int length = in.readInt();
        instance = Array.newInstance(componentType, length);
        for (int i = 0; i < length; i++) {
            Array.set(instance, i, readObject(in, conf));
        }
    } else if (List.class.isAssignableFrom(declaredClass)) { // List
        int length = in.readInt();
        instance = new ArrayList(length);
        for (int i = 0; i < length; i++) {
            ((ArrayList) instance).add(readObject(in, conf));
        }
    } else if (declaredClass == String.class) { // String
        instance = Text.readString(in);
    } else if (declaredClass.isEnum()) { // enum
        instance = Enum.valueOf((Class<? extends Enum>) declaredClass, Text.readString(in));
    } else if (declaredClass == Message.class) {
        String className = Text.readString(in);
        try {
            declaredClass = getClassByName(conf, className);
            instance = tryInstantiateProtobuf(declaredClass, in);
        } catch (ClassNotFoundException e) {
            LOG.error("Can't find class " + className, e);
            throw new IOException("Can't find class " + className, e);
        }
    } else { // Writable or Serializable
        Class instanceClass = null;
        int b = (byte) WritableUtils.readVInt(in);
        if (b == NOT_ENCODED) {
            String className = Text.readString(in);
            try {
                instanceClass = getClassByName(conf, className);
            } catch (ClassNotFoundException e) {
                LOG.error("Can't find class " + className, e);
                throw new IOException("Can't find class " + className, e);
            }
        } else {
            instanceClass = CODE_TO_CLASS.get(b);
        }
        if (Writable.class.isAssignableFrom(instanceClass)) {
            Writable writable = WritableFactories.newInstance(instanceClass, conf);
            try {
                writable.readFields(in);
            } catch (Exception e) {
                LOG.error("Error in readFields", e);
                throw new IOException("Error in readFields", e);
            }
            instance = writable;
            if (instanceClass == NullInstance.class) { // null
                declaredClass = ((NullInstance) instance).declaredClass;
                instance = null;
            }
        } else {
            int length = in.readInt();
            byte[] objectBytes = new byte[length];
            in.readFully(objectBytes);
            ByteArrayInputStream bis = null;
            ObjectInputStream ois = null;
            try {
                bis = new ByteArrayInputStream(objectBytes);
                ois = new ObjectInputStream(bis);
                instance = ois.readObject();
            } catch (ClassNotFoundException e) {
                LOG.error("Class not found when attempting to deserialize object", e);
                throw new IOException("Class not found when attempting to " + "deserialize object", e);
            } finally {
                if (bis != null)
                    bis.close();
                if (ois != null)
                    ois.close();
            }
        }
    }
    if (objectWritable != null) { // store values
        objectWritable.declaredClass = declaredClass;
        objectWritable.instance = instance;
    }
    return instance;
}

From source file:org.apache.hadoop.hbase.security.access.HbaseObjectWritableFor96Migration.java

/**
 * Read a {@link Writable}, {@link String}, primitive type, or an array of
 * the preceding./*from   w  ww  . j  a v  a 2  s  .com*/
 * @param in
 * @param objectWritable
 * @param conf
 * @return the object
 * @throws IOException
 */
@SuppressWarnings("unchecked")
static Object readObject(DataInput in, HbaseObjectWritableFor96Migration objectWritable, Configuration conf)
        throws IOException {
    Class<?> declaredClass = CODE_TO_CLASS.get(WritableUtils.readVInt(in));
    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
        if (declaredClass.equals(byte[].class)) {
            instance = Bytes.readByteArray(in);
        } else {
            int length = in.readInt();
            instance = Array.newInstance(declaredClass.getComponentType(), length);
            for (int i = 0; i < length; i++) {
                Array.set(instance, i, readObject(in, conf));
            }
        }
    } else if (declaredClass.equals(Array.class)) { //an array not declared in CLASS_TO_CODE
        Class<?> componentType = readClass(conf, in);
        int length = in.readInt();
        instance = Array.newInstance(componentType, length);
        for (int i = 0; i < length; i++) {
            Array.set(instance, i, readObject(in, conf));
        }
    } else if (List.class.isAssignableFrom(declaredClass)) { // List
        int length = in.readInt();
        instance = new ArrayList(length);
        for (int i = 0; i < length; i++) {
            ((ArrayList) instance).add(readObject(in, conf));
        }
    } else if (declaredClass == String.class) { // String
        instance = Text.readString(in);
    } else if (declaredClass.isEnum()) { // enum
        instance = Enum.valueOf((Class<? extends Enum>) declaredClass, Text.readString(in));
    } else if (declaredClass == Message.class) {
        String className = Text.readString(in);
        try {
            declaredClass = getClassByName(conf, className);
            instance = tryInstantiateProtobuf(declaredClass, in);
        } catch (ClassNotFoundException e) {
            LOG.error("Can't find class " + className, e);
            throw new IOException("Can't find class " + className, e);
        }
    } else if (Scan.class.isAssignableFrom(declaredClass)) {
        int length = in.readInt();
        byte[] scanBytes = new byte[length];
        in.readFully(scanBytes);
        ClientProtos.Scan.Builder scanProto = ClientProtos.Scan.newBuilder();
        instance = ProtobufUtil.toScan(scanProto.mergeFrom(scanBytes).build());
    } else { // Writable or Serializable
        Class instanceClass = null;
        int b = (byte) WritableUtils.readVInt(in);
        if (b == NOT_ENCODED) {
            String className = Text.readString(in);
            try {
                instanceClass = getClassByName(conf, className);
            } catch (ClassNotFoundException e) {
                LOG.error("Can't find class " + className, e);
                throw new IOException("Can't find class " + className, e);
            }
        } else {
            instanceClass = CODE_TO_CLASS.get(b);
        }
        if (Writable.class.isAssignableFrom(instanceClass)) {
            Writable writable = WritableFactories.newInstance(instanceClass, conf);
            try {
                writable.readFields(in);
            } catch (Exception e) {
                LOG.error("Error in readFields", e);
                throw new IOException("Error in readFields", e);
            }
            instance = writable;
            if (instanceClass == NullInstance.class) { // null
                declaredClass = ((NullInstance) instance).declaredClass;
                instance = null;
            }
        } else {
            int length = in.readInt();
            byte[] objectBytes = new byte[length];
            in.readFully(objectBytes);
            ByteArrayInputStream bis = null;
            ObjectInputStream ois = null;
            try {
                bis = new ByteArrayInputStream(objectBytes);
                ois = new ObjectInputStream(bis);
                instance = ois.readObject();
            } catch (ClassNotFoundException e) {
                LOG.error("Class not found when attempting to deserialize object", e);
                throw new IOException("Class not found when attempting to " + "deserialize object", e);
            } finally {
                if (bis != null)
                    bis.close();
                if (ois != null)
                    ois.close();
            }
        }
    }
    if (objectWritable != null) { // store values
        objectWritable.declaredClass = declaredClass;
        objectWritable.instance = instance;
    }
    return instance;
}

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

/**
 * <p>Indicates if an object of the source class is assignable to the
 * destination class.</p>//w w w.  j  a v  a  2s .  com
 *
 * @param dest   Destination class
 * @param source Source class
 * @return <code>true</code> if the source is assignable to the
 *         destination; <code>false</code> otherwise.
 */
protected boolean isDynaAssignable(Class dest, Class source) {
    if (dest.isAssignableFrom(source) || ((dest == Boolean.TYPE) && (source == Boolean.class))
            || ((dest == Byte.TYPE) && (source == Byte.class))
            || ((dest == Character.TYPE) && (source == Character.class))
            || ((dest == Double.TYPE) && (source == Double.class))
            || ((dest == Float.TYPE) && (source == Float.class))
            || ((dest == Integer.TYPE) && (source == Integer.class))
            || ((dest == Long.TYPE) && (source == Long.class))
            || ((dest == Short.TYPE) && (source == Short.class))) {
        return (true);
    } else {
        return (false);
    }
}

From source file:ResultSetIterator.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  . ja  v  a  2s  . c  om
 * 
 * @param value The value to be passed into the setter method.
 * @param type The setter's parameter type.
 * @return boolean True if the value is compatible.
 */
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;

    } else {
        return false;
    }

}

From source file:com.sun.faces.config.ManagedBeanFactory.java

/**
 * <li><p> Call the property getter, if it exists.</p></li>
 * <p/>//  w w  w .  j  av  a 2  s. c  o m
 * <li><p>If the getter returns null or doesn't exist, create a
 * java.util.ArrayList(), otherwise use the returned Object (an array or
 * a java.util.List).</p></li>
 * <p/>
 * <li><p>If a List was returned or created in step 2), add all
 * elements defined by nested &lt;value&gt; elements in the order
 * they are listed, converting values defined by nested
 * &lt;value&gt; elements to the type defined by
 * &lt;value-class&gt;. If a &lt;value-class&gt; is not defined, use
 * the value as-is (i.e., as a java.lang.String). Add null for each
 * &lt;null-value&gt; element.</p></li>
 * <p/>
 * <li><p> If an array was returned in step 2), create a
 * java.util.ArrayList and copy all elements from the returned array to
 * the new List, auto-boxing elements of a primitive type. Add all
 * elements defined by nested &lt;value&gt; elements as described in step
 * 3).</p></li>
 * <p/>
 * <li><p> If a new java.util.List was created in step 2) and the
 * property is of type List, set the property by calling the setter
 * method, or log an error if there is no setter method.</p></li>
 * <p/>
 * <li><p> If a new java.util.List was created in step 4), convert
 * the * List to array of the same type as the property and set the
 * property by * calling the setter method, or log an error if there
 * is no setter * method.</p></li>
 */

private void setArrayOrListPropertiesIntoBean(Object bean, ManagedPropertyBean property) throws Exception {
    Object result = null;
    boolean getterIsNull = true, getterIsArray = false;
    List valuesForBean = null;
    Class valueType = java.lang.String.class, propertyType = null;

    String propertyName = property.getPropertyName();

    try {
        // see if there is a getter
        result = PropertyUtils.getProperty(bean, propertyName);
        getterIsNull = (null == result) ? true : false;

        propertyType = PropertyUtils.getPropertyType(bean, propertyName);
        getterIsArray = propertyType.isArray();

    } catch (NoSuchMethodException nsme) {
        // it's valid to not have a getter.
    }

    // the property has to be either a List or Array
    if (!getterIsArray) {
        if (null != propertyType && !java.util.List.class.isAssignableFrom(propertyType)) {
            throw new FacesException(
                    Util.getExceptionMessageString(Util.MANAGED_BEAN_CANNOT_SET_LIST_ARRAY_PROPERTY_ID,
                            new Object[] { propertyName, managedBean.getManagedBeanName() }));
        }
    }

    //
    // Deal with the possibility of the getter returning existing
    // values.
    //

    // if the getter returned non-null
    if (!getterIsNull) {
        // if what it returned was an array
        if (getterIsArray) {
            valuesForBean = new ArrayList();
            for (int i = 0, len = Array.getLength(result); i < len; i++) {
                // add the existing values
                valuesForBean.add(Array.get(result, i));
            }
        } else {
            // if what it returned was not a List
            if (!(result instanceof List)) {
                // throw an exception                    
                throw new FacesException(
                        Util.getExceptionMessageString(Util.MANAGED_BEAN_EXISTING_VALUE_NOT_LIST_ID,
                                new Object[] { propertyName, managedBean.getManagedBeanName() }));
            }
            valuesForBean = (List) result;
        }
    } else {

        // getter returned null
        result = valuesForBean = new ArrayList();
    }

    // at this point valuesForBean contains the existing values from
    // the bean, or no values if the bean had no values.  In any
    // case, we can proceed to add values from the config file.
    valueType = copyListEntriesFromConfigToList(property.getListEntries(), valuesForBean);

    // at this point valuesForBean has the values to be set into the
    // bean.

    if (getterIsArray) {
        // convert back to Array
        result = Array.newInstance(valueType, valuesForBean.size());
        for (int i = 0, len = valuesForBean.size(); i < len; i++) {
            if (valueType == Boolean.TYPE) {
                Array.setBoolean(result, i, ((Boolean) valuesForBean.get(i)).booleanValue());
            } else if (valueType == Byte.TYPE) {
                Array.setByte(result, i, ((Byte) valuesForBean.get(i)).byteValue());
            } else if (valueType == Double.TYPE) {
                Array.setDouble(result, i, ((Double) valuesForBean.get(i)).doubleValue());
            } else if (valueType == Float.TYPE) {
                Array.setFloat(result, i, ((Float) valuesForBean.get(i)).floatValue());
            } else if (valueType == Integer.TYPE) {
                Array.setInt(result, i, ((Integer) valuesForBean.get(i)).intValue());
            } else if (valueType == Character.TYPE) {
                Array.setChar(result, i, ((Character) valuesForBean.get(i)).charValue());
            } else if (valueType == Short.TYPE) {
                Array.setShort(result, i, ((Short) valuesForBean.get(i)).shortValue());
            } else if (valueType == Long.TYPE) {
                Array.setLong(result, i, ((Long) valuesForBean.get(i)).longValue());
            } else {
                Array.set(result, i, valuesForBean.get(i));
            }
        }
    } else {
        result = valuesForBean;
    }

    if (getterIsNull || getterIsArray) {
        PropertyUtils.setProperty(bean, propertyName, result);
    }

}

From source file:javadz.beanutils.LazyDynaBean.java

/**
 * Create a new Instance of a 'Primitive' Property.
 * @param name The name of the property// w  w  w. j a  v a 2s  .  c o  m
 * @param type The class of the property
 * @return The new value
 */
protected Object createPrimitiveProperty(String name, Class type) {

    if (type == Boolean.TYPE) {
        return Boolean.FALSE;
    } else if (type == Integer.TYPE) {
        return Integer_ZERO;
    } else if (type == Long.TYPE) {
        return Long_ZERO;
    } else if (type == Double.TYPE) {
        return Double_ZERO;
    } else if (type == Float.TYPE) {
        return Float_ZERO;
    } else if (type == Byte.TYPE) {
        return Byte_ZERO;
    } else if (type == Short.TYPE) {
        return Short_ZERO;
    } else if (type == Character.TYPE) {
        return Character_SPACE;
    } else {
        return null;
    }

}