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.service.proxy.ServiceEndpointInterceptor.java

public Object invokeDummy(MethodInvocation invocation) throws Throwable {

    log.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 w w .ja va  2  s  .co m*/
}

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

public static Object getObjectForNull(Class<?> clazz) {
    if (clazz.equals(Long.TYPE)) {
        return new Long(0);
    } else if (clazz.equals(Integer.TYPE)) {
        return new Integer(0);
    } else if (clazz.equals(Float.TYPE)) {
        return new Float(0.0F);
    } else if (clazz.equals(Double.TYPE)) {
        return new Double(0.0D);
    } else if (clazz.equals(Boolean.TYPE)) {
        return new Boolean(false);
    }/* www.  j a va  2  s .c  o  m*/
    return null;
}

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

/**
 * Tests if obj is a primitive number or wrapper.<br>
 *///from ww  w.  ja v  a 2 s . c  o m
public static boolean isNumber(Object obj) {
    if (((obj != null) && (obj.getClass() == Byte.TYPE)) || ((obj != null) && (obj.getClass() == Short.TYPE))
            || ((obj != null) && (obj.getClass() == Integer.TYPE))
            || ((obj != null) && (obj.getClass() == Long.TYPE))
            || ((obj != null) && (obj.getClass() == Float.TYPE))
            || ((obj != null) && (obj.getClass() == Double.TYPE))) {
        return true;
    }

    if ((obj instanceof Byte) || (obj instanceof Short) || (obj instanceof Integer) || (obj instanceof Long)
            || (obj instanceof Float) || (obj instanceof Double)) {
        return true;
    }

    return false;
}

From source file:org.seedstack.seed.core.internal.application.ConfigurationMembersInjector.java

@SuppressWarnings("unchecked")
private void writeArrayField(T instance) {
    ConfigurationConverter<?> converter;
    Class<?> componentType = field.getType().getComponentType();
    converter = findConverter(instance, componentType);
    String[] values = configuration.getStringArray(annotation.value());

    if ((values == null || values.length == 0) && annotation.defaultValue().length > 0) {
        values = annotation.defaultValue();
    }//ww w .j a  v  a2  s . c  o  m

    if (values != null && values.length > 0) {
        if (componentType.isPrimitive()) {
            if (componentType == Short.TYPE) {
                writeField(instance, convertToShortValues(values, (ConfigurationConverter<Short>) converter));
            }
            if (componentType == Integer.TYPE) {
                writeField(instance,
                        convertToIntegerValues(values, (ConfigurationConverter<Integer>) converter));
            }
            if (componentType == Boolean.TYPE) {
                writeField(instance,
                        convertToBooleanValues(values, (ConfigurationConverter<Boolean>) converter));
            }
            if (componentType == Byte.TYPE) {
                writeField(instance, convertToByteValues(values, (ConfigurationConverter<Byte>) converter));
            }
            if (componentType == Long.TYPE) {
                writeField(instance, convertToLongValues(values, (ConfigurationConverter<Long>) converter));
            }
            if (componentType == Float.TYPE) {
                writeField(instance, convertToFloatValues(values, (ConfigurationConverter<Float>) converter));
            }
            if (componentType == Double.TYPE) {
                writeField(instance, convertToDoubleValues(values, (ConfigurationConverter<Double>) converter));
            }
            if (componentType == Character.TYPE) {
                writeField(instance,
                        convertToCharacterValues(values, (ConfigurationConverter<Character>) converter));
            }
        } else {
            Object[] convertedValues;
            try {
                convertedValues = (Object[]) Array.newInstance(field.getType().getComponentType(),
                        values.length);
            } catch (Exception e) {
                throw SeedException.wrap(e, ApplicationErrorCode.UNABLE_TO_INSTANTIATE_CONFIGURATION_ARRAY);
            }

            for (int i = 0; i < values.length; i++) {
                convertedValues[i] = converter.convert(values[i]);
            }
            writeField(instance, convertedValues);
        }
    } else {
        LOGGER.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, annotation.value());
    }
}

From source file:org.commonreality.object.delta.DeltaTracker.java

@SuppressWarnings("unchecked")
private boolean isActualChange(String keyName, Object newValue) {
    if (newValue != null) {
        if (!_actualObject.hasProperty(keyName))
            return true;

        Object oldValue = null;/*w w  w . j  a v  a2  s  .c o m*/

        // if (checkOnlyActualObject)
        oldValue = _actualObject.getProperty(keyName);
        // else
        // oldValue = getProperty(keyName);

        if (newValue == oldValue)
            return false;

        if (newValue.equals(oldValue))
            return false;

        /*
         * now we need to see if they are arrays
         */
        Class newClass = newValue.getClass();
        Class oldClass = Object.class;
        if (oldValue != null)
            oldClass = oldValue.getClass();
        if (newClass != oldClass)
            return true;

        if (newClass.isArray() && oldClass.isArray()) {
            if (newClass.getComponentType() != oldClass.getComponentType())
                return true;

            /*
             * now we have to check the elements
             */
            if (newClass.getComponentType().isPrimitive()) {
                boolean rtn = true;
                if (newClass.getComponentType() == Float.TYPE)
                    rtn = compareFloats((float[]) newValue, (float[]) oldValue);
                else if (newClass.getComponentType() == Double.TYPE)
                    rtn = compareDoubles((double[]) newValue, (double[]) oldValue);
                else if (newClass.getComponentType() == Boolean.TYPE)
                    rtn = compareBooleans((boolean[]) newValue, (boolean[]) oldValue);
                else if (newClass.getComponentType() == Integer.TYPE)
                    rtn = compareInts((int[]) newValue, (int[]) oldValue);
                else if (LOGGER.isWarnEnabled())
                    LOGGER.warn("Cannot compare arrays of " + newClass.getComponentType().getName());
                return rtn;
            } else {
                Object[] newArray = (Object[]) newValue;
                Object[] oldArray = (Object[]) oldValue;

                if (newArray.length != oldArray.length)
                    return true;

                for (int i = 0; i < newArray.length; i++)
                    if (!newArray[i].equals(oldArray[i]))
                        return true;

                return false;
            }

        }
    } else // unsetting the property
    if (_actualObject.hasProperty(keyName))
        return true;

    return true;
}

From source file:org.kordamp.ezmorph.object.NumberMorpher.java

private boolean isDecimalNumber(Class type) {
    return (Double.class.isAssignableFrom(type) || Float.class.isAssignableFrom(type) || Double.TYPE == type
            || Float.TYPE == type || BigDecimal.class.isAssignableFrom(type));
}

From source file:org.briljantframework.data.resolver.Resolve.java

private static Resolver<Integer> initializeIntegerResolver() {
    Resolver<Integer> resolver = new Resolver<>(Integer.class);
    resolver.put(Number.class, Number::intValue);
    resolver.put(Double.class, Number::intValue);
    resolver.put(Double.TYPE, Number::intValue);
    resolver.put(Float.class, Number::intValue);
    resolver.put(Float.TYPE, Number::intValue);
    resolver.put(Long.class, Number::intValue);
    resolver.put(Long.TYPE, Number::intValue);
    resolver.put(Integer.class, Number::intValue);
    resolver.put(Integer.TYPE, Number::intValue);
    resolver.put(Short.class, Number::intValue);
    resolver.put(Short.TYPE, Number::intValue);
    resolver.put(Byte.class, Number::intValue);
    resolver.put(Byte.TYPE, Number::intValue);
    resolver.put(String.class, s -> {
        try {//  w  w w  . j  a va2 s . c o m
            return NumberUtils.createNumber(s).intValue();
        } catch (Exception e) {
            return null;
        }
    });
    return resolver;
}

From source file:com.nfwork.dbfound.json.JSONDynaBean.java

protected boolean isDynaAssignable(Class dest, Class src) {
    boolean assignable = dest.isAssignableFrom(src);
    assignable = (dest == Boolean.TYPE && src == Boolean.class) ? true : assignable;
    assignable = (dest == Byte.TYPE && src == Byte.class) ? true : assignable;
    assignable = (dest == Character.TYPE && src == Character.class) ? true : assignable;
    assignable = (dest == Short.TYPE && src == Short.class) ? true : assignable;
    assignable = (dest == Integer.TYPE && src == Integer.class) ? true : assignable;
    assignable = (dest == Long.TYPE && src == Long.class) ? true : assignable;
    assignable = (dest == Float.TYPE && src == Float.class) ? true : assignable;
    assignable = (dest == Double.TYPE && src == Double.class) ? true : assignable;

    if (src == Double.TYPE || Double.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest) || isFloat(dest)) ? true
                : assignable;//from w  w  w .j a  v  a 2s  . c  om
    }
    if (src == Float.TYPE || Float.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest)) ? true : assignable;
    }
    if (src == Long.TYPE || Long.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest) || isInteger(dest)) ? true : assignable;
    }
    if (src == Integer.TYPE || Integer.class.isAssignableFrom(src)) {
        assignable = (isByte(dest) || isShort(dest)) ? true : assignable;
    }
    if (src == Short.TYPE || Short.class.isAssignableFrom(src)) {
        assignable = (isByte(dest)) ? true : assignable;
    }

    return assignable;
}

From source file:com.cyclopsgroup.waterview.utils.TypeUtils.java

private static synchronized Map getTypeMap() {
    if (typeMap == null) {
        typeMap = new Hashtable();
        typeMap.put("boolean", Boolean.TYPE);
        typeMap.put("byte", Byte.TYPE);
        typeMap.put("char", Character.TYPE);
        typeMap.put("short", Short.TYPE);
        typeMap.put("int", Integer.TYPE);
        typeMap.put("long", Long.TYPE);
        typeMap.put("float", Float.TYPE);
        typeMap.put("double", Double.TYPE);
        typeMap.put("string", String.class);
        typeMap.put("date", Date.class);
    }/*from w  w w. j av a2 s  .c o  m*/

    return typeMap;
}

From source file:org.acmsl.commons.utils.ConversionUtils.java

/**
 * Converts given String to float, if given value is not null.
 * @param value the value to convert./*  w w  w  .j  a v  a  2s  .  c o  m*/
 * @return the converted value.
 */
@Nullable
public Float toFloatIfNotNull(@Nullable final String value) {
    Float result = null;

    @Nullable
    final Converter t_Converter = ConvertUtils.lookup(Float.TYPE);

    if (t_Converter != null) {
        @Nullable
        final Object t_Result = t_Converter.convert(Float.TYPE, value);

        if (t_Result instanceof Float) {
            result = (Float) t_Result;
        }
    }

    return result;
}