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.alibaba.doris.admin.service.impl.ValueParseUtil.java

/**
 * ?,?,/*from   ww w. ja v  a 2s.c o m*/
 * 
 * @param clazz
 * @return
 */
@SuppressWarnings("unchecked")
private static <T> T getInternalDefaultValue(Class<T> clazz) {
    if (!clazz.isPrimitive()) {
        return null;
    }
    if (Short.TYPE.equals(clazz)) {
        return (T) Short.valueOf((short) 0);
    }
    if (Integer.TYPE.equals(clazz)) {
        return (T) Integer.valueOf(0);
    }
    if (Long.TYPE.equals(clazz)) {
        return (T) Long.valueOf(0);
    }
    if (Boolean.TYPE.equals(clazz)) {
        return (T) Boolean.valueOf(false);
    }
    if (Float.TYPE.equals(clazz)) {
        return (T) Float.valueOf(0);
    }
    if (Double.TYPE.equals(clazz)) {
        return (T) Double.valueOf(0);
    }
    if (Byte.TYPE.equals(clazz)) {
        return (T) Byte.valueOf((byte) 0);
    }
    if (Character.TYPE.equals(clazz)) {
        return (T) Character.valueOf('\0');
    }
    return null;
}

From source file:Main.java

public static String getTypeForField(Field field) {
    Class type = field.getType();
    // Animation//from   w  w  w. java2s  .c  o  m
    if (type.isAssignableFrom(Animation.class))
        return "anim";
    // Color State List
    else if (type.isAssignableFrom(ColorStateList.class))
        return "color";
    // Drawable
    else if (type.isAssignableFrom(Drawable.class))
        return "drawable";
    // String
    else if (type.isAssignableFrom(String.class))
        return "string";
    // String Array
    else if (type.isArray())
        return "array";
    // TODO: Recognize plural strings if possible
    //        else if (type.isAssignableFrom(String.class))
    //            return "plural";
    // Boolean
    else if (type.isAssignableFrom(Boolean.TYPE) || type.isAssignableFrom(Boolean.class))
        return "bool";
    // Integer
    else if (type.isAssignableFrom(Integer.TYPE) || type.isAssignableFrom(Integer.class))
        return "integer";
    // Dimen
    else if (type.isAssignableFrom(Float.TYPE) || type.isAssignableFrom(Float.class))
        return "dimen";

    throw new RuntimeException("No suitable type found for " + field.getName() + "of class " + type.getName());
}

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.
 *///  w  w  w .  j  av  a2s.c  o  m
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: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  av a  2s .c  o  m*/
        return null;
}

From source file:Util.java

/**
 * Is the given {@code object} a primitive type or wrapper for a primitive
 * type?/* www  .  jav a  2 s.c  o  m*/
 * 
 * @param object
 *            The object to check for primitive-ness.
 * @return {@code true} if {@code object} is a primitive type or wrapper for
 *         a primitive type, {@code false} otherwise.
 */
public static boolean isPrimitive(Object object) {
    if (object == null)
        return false;

    Class<?> type = object.getClass();

    return object instanceof String || (object instanceof Integer || Integer.TYPE.equals(type))
            || (object instanceof Boolean || Boolean.TYPE.equals(type))
            || (object instanceof Long || Long.TYPE.equals(type))
            || (object instanceof Double || Double.TYPE.equals(type))
            || (object instanceof Float || Float.TYPE.equals(type))
            || (object instanceof Byte || Byte.TYPE.equals(type))
            || (object instanceof Short || Short.TYPE.equals(type))
            || (object instanceof Character || Character.TYPE.equals(type));
}

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

public static String getPrimitiveLetter(Class<?> paramClass) {
    if (Integer.TYPE.equals(paramClass)) {
        return "I";
    }//from   w  w  w. j ava 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:com.autonomy.aci.client.annotations.ConversionServiceImpl.java

public ConversionServiceImpl() {
    registerConverter(new StringToDoubleConverter(), String.class, Double.class);
    registerConverter(new StringToDoubleConverter(), String.class, Double.TYPE);

    registerConverter(new StringToByteConverter(), String.class, Byte.class);
    registerConverter(new StringToByteConverter(), String.class, Byte.TYPE);

    registerConverter(new StringToIntegerConverter(), String.class, Integer.class);
    registerConverter(new StringToIntegerConverter(), String.class, Integer.TYPE);

    registerConverter(new StringToFloatConverter(), String.class, Float.class);
    registerConverter(new StringToFloatConverter(), String.class, Float.TYPE);

    registerConverter(new StringToShortConverter(), String.class, Short.class);
    registerConverter(new StringToShortConverter(), String.class, Short.TYPE);

    registerConverter(new StringToCharacterConverter(), String.class, Character.class);
    registerConverter(new StringToCharacterConverter(), String.class, Character.TYPE);

    registerConverter(new StringToBooleanConverter(), String.class, Boolean.class);
    registerConverter(new StringToBooleanConverter(), String.class, Boolean.TYPE);

    registerConverter(new StringToLongConverter(), String.class, Long.class);
    registerConverter(new StringToLongConverter(), String.class, Long.TYPE);
}

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

/**
 * Creates a new morpher for the target type.
 * /*from  ww w.ja  va  2 s.c  o 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:nz.co.senanque.validationengine.ConvertUtils.java

public static Comparable<?> convertTo(Class<?> clazz, Object obj) {
    if (obj == null) {
        return null;
    }/*from   ww w .j  a v a2  s.c  o  m*/
    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());
}