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.l2jfree.config.L2Properties.java

@SuppressWarnings("unchecked")
public Object getProperty(Class<?> expectedType, ConfigProperty configProperty) {
    final String name = configProperty.name();
    final String defaultValue = configProperty.value();

    if (expectedType == Boolean.class || expectedType == Boolean.TYPE) {
        return getBool(name, defaultValue);
    } else if (expectedType == Long.class || expectedType == Long.TYPE) {
        return getLong(name, defaultValue);
    } else if (expectedType == Integer.class || expectedType == Integer.TYPE) {
        return getInteger(name, defaultValue);
    } else if (expectedType == Short.class || expectedType == Short.TYPE) {
        return getShort(name, defaultValue);
    } else if (expectedType == Byte.class || expectedType == Byte.TYPE) {
        return getByte(name, defaultValue);
    } else if (expectedType == Double.class || expectedType == Double.TYPE) {
        return getDouble(name, defaultValue);
    } else if (expectedType == Float.class || expectedType == Float.TYPE) {
        return getFloat(name, defaultValue);
    } else if (expectedType == String.class) {
        return getString(name, defaultValue);
    } else if (expectedType.isEnum()) {
        return getEnum(name, (Class<? extends Enum>) expectedType, defaultValue);
    } else {/*from   ww  w .j  ava2 s. c o  m*/
        throw new IllegalStateException();
    }
}

From source file:org.apache.struts2.s1.DynaBeanPropertyAccessorTest.java

/**
 * Create and return a <code>DynaClass</code> instance for our test
 * <code>DynaBean</code>./* ww w . j ava2s  .  com*/
 */
protected DynaClass createDynaClass() {

    int intArray[] = new int[0];
    String stringArray[] = new String[0];

    DynaClass dynaClass = new BasicDynaClass("TestDynaClass", null, new DynaProperty[] {
            new DynaProperty("booleanProperty", Boolean.TYPE), new DynaProperty("booleanSecond", Boolean.TYPE),
            new DynaProperty("doubleProperty", Double.TYPE), new DynaProperty("floatProperty", Float.TYPE),
            new DynaProperty("intArray", intArray.getClass()),
            new DynaProperty("intIndexed", intArray.getClass()), new DynaProperty("intProperty", Integer.TYPE),
            new DynaProperty("listIndexed", List.class), new DynaProperty("longProperty", Long.TYPE),
            new DynaProperty("mappedProperty", Map.class), new DynaProperty("mappedIntProperty", Map.class),
            new DynaProperty("nullProperty", String.class), new DynaProperty("shortProperty", Short.TYPE),
            new DynaProperty("stringArray", stringArray.getClass()),
            new DynaProperty("stringIndexed", stringArray.getClass()),
            new DynaProperty("stringProperty", String.class), });
    return (dynaClass);

}

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

public Object morph(Object value) {
    if (value != null && type.isAssignableFrom(value.getClass())) {
        // no conversion needed
        return value;
    }/*from  ww  w  .  j a  v a2  s.  c o m*/

    String str = String.valueOf(value).trim();

    if (!type.isPrimitive() && (value == null || str.length() == 0 || "null".equalsIgnoreCase(str))) {
        // if empty string and class != primitive treat it like null
        return null;
    }

    try {
        if (isDecimalNumber(type)) {
            if (Float.class.isAssignableFrom(type) || Float.TYPE == type) {
                return morphToFloat(str);
            } else if (Double.class.isAssignableFrom(type) || Double.TYPE == type) {
                return morphToDouble(str);
            } else {
                return morphToBigDecimal(str);
            }
        } else {
            if (Byte.class.isAssignableFrom(type) || Byte.TYPE == type) {
                return morphToByte(str);
            } else if (Short.class.isAssignableFrom(type) || Short.TYPE == type) {
                return morphToShort(str);
            } else if (Integer.class.isAssignableFrom(type) || Integer.TYPE == type) {
                return morphToInteger(str);
            } else if (Long.class.isAssignableFrom(type) || Long.TYPE == type) {
                return morphToLong(str);
            } else {
                return morphToBigInteger(str);
            }
        }
    } catch (ConvertErrorException e) {
        // JsonPropertyConvertContext.setConvertError((ConvertErrorException) e);
        return null;
    }
}

From source file:org.apache.pig.builtin.Invoker.java

private static Class<?> unPrimitivize(Class<?> klass) {
    if (klass.equals(Integer.TYPE)) {
        return Integer.class;
    }//from   w  w  w .j  a  va 2 s . c  o m
    if (klass.equals(Long.TYPE)) {
        return Long.class;
    } else if (klass.equals(Float.TYPE)) {
        return Float.class;
    } else if (klass.equals(Double.TYPE)) {
        return Double.class;
    } else {
        return klass;
    }
}

From source file:org.apache.click.util.RequestTypeConverter.java

/**
 * Return the converted value for the given value object and target type.
 *
 * @param value the value object to convert
 * @param toType the target class type to convert the value to
 * @return a converted value into the specified type
 *///from w ww.ja va2  s.  c om
protected Object convertValue(Object value, Class<?> toType) {
    Object result = null;

    if (value != null) {

        // If array -> array then convert components of array individually
        if (value.getClass().isArray() && toType.isArray()) {
            Class<?> componentType = toType.getComponentType();

            result = Array.newInstance(componentType, Array.getLength(value));

            for (int i = 0, icount = Array.getLength(value); i < icount; i++) {
                Array.set(result, i, convertValue(Array.get(value, i), componentType));
            }

        } else {
            if ((toType == Integer.class) || (toType == Integer.TYPE)) {
                result = Integer.valueOf((int) OgnlOps.longValue(value));

            } else if ((toType == Double.class) || (toType == Double.TYPE)) {
                result = new Double(OgnlOps.doubleValue(value));

            } else if ((toType == Boolean.class) || (toType == Boolean.TYPE)) {
                result = Boolean.valueOf(value.toString());

            } else if ((toType == Byte.class) || (toType == Byte.TYPE)) {
                result = Byte.valueOf((byte) OgnlOps.longValue(value));

            } else if ((toType == Character.class) || (toType == Character.TYPE)) {
                result = Character.valueOf((char) OgnlOps.longValue(value));

            } else if ((toType == Short.class) || (toType == Short.TYPE)) {
                result = Short.valueOf((short) OgnlOps.longValue(value));

            } else if ((toType == Long.class) || (toType == Long.TYPE)) {
                result = Long.valueOf(OgnlOps.longValue(value));

            } else if ((toType == Float.class) || (toType == Float.TYPE)) {
                result = new Float(OgnlOps.doubleValue(value));

            } else if (toType == BigInteger.class) {
                result = OgnlOps.bigIntValue(value);

            } else if (toType == BigDecimal.class) {
                result = bigDecValue(value);

            } else if (toType == String.class) {
                result = OgnlOps.stringValue(value);

            } else if (toType == java.util.Date.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.util.Date(time);
                }

            } else if (toType == java.sql.Date.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.sql.Date(time);
                }

            } else if (toType == java.sql.Time.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.sql.Time(time);
                }

            } else if (toType == java.sql.Timestamp.class) {
                long time = getTimeFromDateString(value.toString());
                if (time > Long.MIN_VALUE) {
                    result = new java.sql.Timestamp(time);
                }
            }
        }

    } else {
        if (toType.isPrimitive()) {
            result = OgnlRuntime.getPrimitiveDefaultValue(toType);
        }
    }
    return result;
}

From source file:Main.java

/**
 * renderArray returns an array similar to a List. If the array type is an
 * object they are rendered with "render(object)" for each. If the array
 * type is a primitive each element is added directly to the string buffer
 * collecting the result./*  w ww . j av a  2 s.c o  m*/
 * 
 * @param o
 * @param objectClass
 * @return
 */
private static StringBuffer renderArray(Object o, Class<?> objectClass) {
    Class<?> componentType = objectClass.getComponentType();
    StringBuffer sb = new StringBuffer(ARRAY_PREFIX);

    if (componentType.isPrimitive() == false) {
        Object[] oa = (Object[]) o;
        for (int i = 0; i < oa.length; i++) {
            if (i > 0) {
                sb.append(ELEMENT_SEPARATOR);
            }
            sb.append(render(oa[i]));
        }
    } else {
        if (Boolean.TYPE.equals(componentType)) {
            boolean[] ba = (boolean[]) o;
            for (int i = 0; i < ba.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ba[i]);
            }
        } else if (Integer.TYPE.equals(componentType)) {
            int[] ia = (int[]) o;
            for (int i = 0; i < ia.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ia[i]);
            }

        } else if (Long.TYPE.equals(componentType)) {
            long[] ia = (long[]) o;
            for (int i = 0; i < ia.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ia[i]);
            }
        } else if (Double.TYPE.equals(componentType)) {
            double[] ia = (double[]) o;
            for (int i = 0; i < ia.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ia[i]);
            }
        } else if (Float.TYPE.equals(componentType)) {
            float[] ia = (float[]) o;
            for (int i = 0; i < ia.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ia[i]);
            }
        } else if (Character.TYPE.equals(componentType)) {
            char[] ia = (char[]) o;
            for (int i = 0; i < ia.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ia[i]);
            }
        } else if (Short.TYPE.equals(componentType)) {
            short[] ia = (short[]) o;
            for (int i = 0; i < ia.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ia[i]);
            }
        } else if (Byte.TYPE.equals(componentType)) {
            byte[] ia = (byte[]) o;
            for (int i = 0; i < ia.length; i++) {
                if (i > 0) {
                    sb.append(ELEMENT_SEPARATOR);
                }
                sb.append(ia[i]);
            }
        }
    }
    sb.append(ARRAY_SUFFIX);
    return sb;
}

From source file:org.trianacode.taskgraph.tool.ClassLoaders.java

public static Class forName(String className) throws ClassNotFoundException {
    className = getTextClassName(className);
    boolean isArray = false;
    int dims = 0;
    if (className.endsWith("[]")) {
        isArray = true;//from  w w  w  . j  a  va2s .  c o  m
        dims = className.substring(className.indexOf("[]"), className.length()).length() / 2;
        className = className.substring(0, className.indexOf("[]"));

    }
    Class cls;
    if (className.equals("boolean")) {
        cls = Boolean.TYPE;
    } else if (className.equals("char")) {
        cls = Character.TYPE;
    } else if (className.equals("byte")) {
        cls = Byte.TYPE;
    } else if (className.equals("short")) {
        cls = Short.TYPE;
    } else if (className.equals("int")) {
        cls = Integer.TYPE;
    } else if (className.equals("long")) {
        cls = Long.TYPE;
    } else if (className.equals("float")) {
        cls = Float.TYPE;
    } else if (className.equals("double")) {
        cls = Double.TYPE;
    } else if (className.equals("void")) {
        cls = void.class;
    } else {
        cls = loadClass(className);
    }
    if (isArray) {
        Object arr = Array.newInstance(cls, new int[dims]);
        cls = arr.getClass();
    }
    return cls;
}

From source file:net.sf.jrf.domain.PersistentObjectDynaProperty.java

/** Constructs instance and property name and class.
* @param name property name./*from  www  . j ava 2  s  .c  o  m*/
* @param cls value object <code>Class</code>.
* @param readMethodName name of the read <code>Method</code>
* @param writeMethodName name of the write <code>Method</code>
*/
public PersistentObjectDynaProperty(String name, Class cls, String readMethodName, String writeMethodName) {
    super(name, cls);
    this.readMethodName = readMethodName;
    this.writeMethodName = writeMethodName;
    if (cls.isPrimitive()) {
        if (cls.equals(Boolean.TYPE))
            primitiveWrapperClass = Boolean.class;
        else if (cls.equals(Byte.TYPE))
            primitiveWrapperClass = Byte.class;
        else if (cls.equals(Character.TYPE))
            primitiveWrapperClass = Character.class;
        else if (cls.equals(Double.TYPE))
            primitiveWrapperClass = Double.class;
        else if (cls.equals(Float.TYPE))
            primitiveWrapperClass = Float.class;
        else if (cls.equals(Integer.TYPE))
            primitiveWrapperClass = Integer.class;
        else if (cls.equals(Long.TYPE))
            primitiveWrapperClass = Long.class;
        else if (cls.equals(Short.TYPE))
            primitiveWrapperClass = Short.class;

    } else if (java.util.List.class.isAssignableFrom(cls) || cls.isArray()) {
        indexed = true;
    } else if (java.util.Map.class.isAssignableFrom(cls)) {
        mapped = true;
    }
}

From source file:org.quartz.jobs.ee.jmx.JMXInvokerJob.java

public void execute(JobExecutionContext context) throws JobExecutionException {
    try {// w  w  w .  j  ava  2 s .  c o  m
        Object[] params = null;
        String[] types = null;
        String objName = null;
        String objMethod = null;

        JobDataMap jobDataMap = context.getMergedJobDataMap();

        String[] keys = jobDataMap.getKeys();
        for (int i = 0; i < keys.length; i++) {
            String value = jobDataMap.getString(keys[i]);
            if ("JMX_OBJECTNAME".equalsIgnoreCase(keys[i])) {
                objName = value;
            } else if ("JMX_METHOD".equalsIgnoreCase(keys[i])) {
                objMethod = value;
            } else if ("JMX_PARAMDEFS".equalsIgnoreCase(keys[i])) {
                String[] paramdefs = split(value, ",");
                params = new Object[paramdefs.length];
                types = new String[paramdefs.length];
                for (int k = 0; k < paramdefs.length; k++) {
                    String parts[] = split(paramdefs[k], ":");
                    if (parts.length < 2) {
                        throw new Exception(
                                "Invalid parameter definition: required parts missing " + paramdefs[k]);
                    }
                    switch (parts[0].charAt(0)) {
                    case 'i':
                        params[k] = new Integer(jobDataMap.getString(parts[1]));
                        types[k] = Integer.TYPE.getName();
                        break;
                    case 'I':
                        params[k] = new Integer(jobDataMap.getString(parts[1]));
                        types[k] = Integer.class.getName();
                        break;
                    case 'l':
                        params[k] = new Long(jobDataMap.getString(parts[1]));
                        types[k] = Long.TYPE.getName();
                        break;
                    case 'L':
                        params[k] = new Long(jobDataMap.getString(parts[1]));
                        types[k] = Long.class.getName();
                        break;
                    case 'f':
                        params[k] = new Float(jobDataMap.getString(parts[1]));
                        types[k] = Float.TYPE.getName();
                        break;
                    case 'F':
                        params[k] = new Float(jobDataMap.getString(parts[1]));
                        types[k] = Float.class.getName();
                        break;
                    case 'd':
                        params[k] = new Double(jobDataMap.getString(parts[1]));
                        types[k] = Double.TYPE.getName();
                        break;
                    case 'D':
                        params[k] = new Double(jobDataMap.getString(parts[1]));
                        types[k] = Double.class.getName();
                        break;
                    case 's':
                        params[k] = jobDataMap.getString(parts[1]);
                        types[k] = String.class.getName();
                        break;
                    case 'b':
                        params[k] = new Boolean(jobDataMap.getString(parts[1]));
                        types[k] = Boolean.TYPE.getName();
                        break;
                    case 'B':
                        params[k] = new Boolean(jobDataMap.getString(parts[1]));
                        types[k] = Boolean.class.getName();
                        break;
                    }
                }
            }
        }

        if (objName == null || objMethod == null) {
            throw new Exception("Required parameters missing");
        }

        context.setResult(invoke(objName, objMethod, params, types));
    } catch (Exception e) {
        String m = "Caught a " + e.getClass().getName() + " exception : " + e.getMessage();
        getLog().error(m, e);
        throw new JobExecutionException(m, e, false);
    }
}

From source file:com.manydesigns.elements.util.Util.java

public static boolean isNumericType(Class type) {
    return Number.class.isAssignableFrom(type) || type == Integer.TYPE || type == Byte.TYPE
            || type == Short.TYPE || type == Long.TYPE || type == Float.TYPE || type == Double.TYPE;
}