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.cyclopsgroup.waterview.utils.TypeUtils.java

private static Map getNonePrimitiveTypeMap() {
    if (nonePrimitiveTypeMap == null) {
        nonePrimitiveTypeMap = new Hashtable();
        nonePrimitiveTypeMap.put(Boolean.TYPE, Boolean.class);
        nonePrimitiveTypeMap.put(Byte.TYPE, Byte.class);
        nonePrimitiveTypeMap.put(Character.TYPE, Character.class);
        nonePrimitiveTypeMap.put(Short.TYPE, Short.class);
        nonePrimitiveTypeMap.put(Integer.TYPE, Integer.class);
        nonePrimitiveTypeMap.put(Long.TYPE, Long.class);
        nonePrimitiveTypeMap.put(Float.TYPE, Float.class);
        nonePrimitiveTypeMap.put(Double.TYPE, Double.class);
    }//from   w w  w  .j a va 2 s.  com

    return nonePrimitiveTypeMap;
}

From source file:com.link_intersystems.lang.Conversions.java

/**
 * <em>java language specification - 5.1.3 Narrowing Primitive Conversions</em>
 * ./*from   w w  w .j  ava  2  s . c  o  m*/
 *
 * <code>
 * <blockquote>The following 22 specific conversions on primitive types
 *  are called the narrowing primitive conversions:
 * <ul>
 * <li>short to byte or char</li>
 * <li>char to byte or short</li>
 * <li>int to byte, short, or char</li>
 * <li>long to byte, short, char, or int</li>
 * <li>float to byte, short, char, int, or long</li>
 * <li>double to byte, short, char, int, long, or float </li>
 * </blockquote>
 * </code>
 *
 * @param from
 *            the base type
 * @param to
 *            the widening type
 * @return true if from to to is a primitive widening.
 * @since 1.0.0.0
 */
public static boolean isPrimitiveNarrowing(Class<?> from, Class<?> to) {
    Assert.isTrue(Primitives.isPrimitive(from), "mustBeAPrimitive", "form");
    Assert.isTrue(Primitives.isPrimitive(to), "mustBeAPrimitive", "to");
    boolean isPrimitiveNarrowing = false;

    if (isIdentity(from, Double.TYPE)) {
        isPrimitiveNarrowing = isPrimitiveDoubleNarrowing(to);
    } else if (isIdentity(from, Short.TYPE)) {
        isPrimitiveNarrowing = isPrimitiveShortNarrowing(to);
    } else if (isIdentity(from, Character.TYPE)) {
        isPrimitiveNarrowing = isPrimitiveCharacterNarrowing(to);
    } else if (isIdentity(from, Integer.TYPE)) {
        isPrimitiveNarrowing = isPrimitiveIntegerNarrowing(to);
    } else if (isIdentity(from, Long.TYPE)) {
        isPrimitiveNarrowing = isPrimitiveLongNarrowing(to);
    } else if (isIdentity(from, Float.TYPE)) {
        isPrimitiveNarrowing = isPrimitiveFloatNarrowing(to);
    }
    /*
     * must be a byte
     */
    return isPrimitiveNarrowing;
}

From source file:com.projity.util.ClassUtils.java

/**
 * Given a type, return a value that signifies that there are multiple values.  This can occur in a dialog which works on multile objects at once.  If type is unknown, a new one is constructed
 * @param clazz/*from   ww w  .j  a v a  2 s .com*/
 * @return
 */
public static Object getMultipleValueForType(Class clazz) {
    if (clazz == String.class)
        return STRING_MULTIPLE_VALUES;
    else if (clazz == Double.class || clazz == Double.TYPE)
        return DOUBLE_MULTIPLE_VALUES;
    else if (clazz == Integer.class || clazz == Integer.TYPE)
        return INTEGER_MULTIPLE_VALUES;
    else if (clazz == Long.class || clazz == Long.TYPE)
        return LONG_MULTIPLE_VALUES;
    else if (clazz == Float.class || clazz == Float.TYPE)
        return FLOAT_MULTIPLE_VALUES;
    else if (clazz == Boolean.class)
        return BOOLEAN_MULTIPLE_VALUES;
    else if (clazz == Rate.class)
        return RATE_MULTIPLE_VALUES;
    else {
        try {
            return clazz.newInstance();
        } catch (InstantiationException e) {
        } catch (IllegalAccessException e) {
        }
        return null;
    }
}

From source file:nz.ac.otago.psyanlab.common.designer.program.stage.EditPropPropertiesFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Bundle args = getArguments();//from w w  w  .ja v  a 2 s . co m
    if (args.containsKey(ARG_PROP)) {
        mProp = args.getParcelable(ARG_PROP);
    } else {
        mProp = mCallbacks.getProp(args.getInt(ARG_PROP_ID)).getProp();
    }

    mFieldMap = new HashMap<String, Field>();
    mViewMap = new HashMap<String, View>();

    // Run through the fields of the prop and build groups and mappings for
    // the fields and views to allow the user to change the property values.
    Field[] fields = mProp.getClass().getFields();
    for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        PALEPropProperty annotation = field.getAnnotation(PALEPropProperty.class);
        if (annotation != null) {
            String fieldName = annotation.value();
            View view;
            if (field.getType().isAssignableFrom(Integer.TYPE)) {
                try {
                    view = newIntegerInputView(annotation.isSigned(), field.getInt(mProp));
                } catch (IllegalArgumentException e) {
                    throw new RuntimeException("Should never get here.", e);
                } catch (IllegalAccessException e) {
                    throw new RuntimeException("Should never get here.", e);
                }
            } else if (field.getType().isAssignableFrom(Float.TYPE)) {
                try {
                    view = newFloatInputView(annotation.isSigned(), field.getFloat(mProp));
                } catch (IllegalArgumentException e) {
                    throw new RuntimeException("Should never get here.", e);
                } catch (IllegalAccessException e) {
                    throw new RuntimeException("Should never get here.", e);
                }
            } else if (field.getType().isAssignableFrom(String.class)) {
                try {
                    view = newStringInputView((String) field.get(mProp));
                } catch (IllegalArgumentException e) {
                    throw new RuntimeException("Should never get here.", e);
                } catch (IllegalAccessException e) {
                    throw new RuntimeException("Should never get here.", e);
                }
            } else {
                continue;
            }
            mFieldMap.put(fieldName, field);
            mViewMap.put(fieldName, view);

            if (mGroupings.containsKey(annotation.group())) {
                mGroupings.get(annotation.group()).add(fieldName);
            } else {
                ArrayList<String> list = new ArrayList<String>();
                list.add(fieldName);
                mGroupings.put(annotation.group(), list);
            }
        }
    }

    // Initialise grid layout.
    GridLayout grid = new GridLayout(getActivity());
    grid.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    grid.setAlignmentMode(GridLayout.ALIGN_BOUNDS);
    grid.setColumnCount(2);
    grid.setUseDefaultMargins(true);

    // Run through groupings of properties adding the created views to the
    // GridLayout in sections.
    for (String group : mGroupings.keySet()) {
        if (!TextUtils.isEmpty(group) && !TextUtils.equals(group, "")) {
            TextView sectionBreak = (TextView) inflater.inflate(R.layout.prop_property_section_break, grid,
                    false);
            sectionBreak.setText(group);
            GridLayout.LayoutParams sectionBreakParams = new GridLayout.LayoutParams();
            sectionBreakParams.columnSpec = GridLayout.spec(0, 2);
            sectionBreak.setLayoutParams(sectionBreakParams);
            grid.addView(sectionBreak);
        }

        for (String name : mGroupings.get(group)) {
            TextView propertyLabel = (TextView) inflater.inflate(R.layout.prop_property_label, grid, false);
            GridLayout.LayoutParams params = new GridLayout.LayoutParams();
            propertyLabel.setLayoutParams(params);
            propertyLabel.setText(getResources().getString(R.string.format_property_label, name));

            View propertyView = mViewMap.get(name);
            params = new GridLayout.LayoutParams();
            params.setGravity(Gravity.FILL_HORIZONTAL);
            propertyView.setLayoutParams(params);

            grid.addView(propertyLabel);
            grid.addView(propertyView);
        }
    }

    return grid;
}

From source file:org.apache.sling.models.impl.model.AbstractInjectableElement.java

private static Object getDefaultValue(AnnotatedElement element, Type type,
        InjectAnnotationProcessor2 annotationProcessor) {
    if (annotationProcessor != null && annotationProcessor.hasDefault()) {
        return annotationProcessor.getDefault();
    }/*from   ww w.j  a v a  2  s . c  o  m*/

    Default defaultAnnotation = element.getAnnotation(Default.class);
    if (defaultAnnotation == null) {
        return null;
    }

    Object value = null;

    if (type instanceof Class) {
        Class<?> injectedClass = (Class<?>) type;
        if (injectedClass.isArray()) {
            Class<?> componentType = injectedClass.getComponentType();
            if (componentType == String.class) {
                value = defaultAnnotation.values();
            } else if (componentType == Integer.TYPE) {
                value = defaultAnnotation.intValues();
            } else if (componentType == Integer.class) {
                value = ArrayUtils.toObject(defaultAnnotation.intValues());
            } else if (componentType == Long.TYPE) {
                value = defaultAnnotation.longValues();
            } else if (componentType == Long.class) {
                value = ArrayUtils.toObject(defaultAnnotation.longValues());
            } else if (componentType == Boolean.TYPE) {
                value = defaultAnnotation.booleanValues();
            } else if (componentType == Boolean.class) {
                value = ArrayUtils.toObject(defaultAnnotation.booleanValues());
            } else if (componentType == Short.TYPE) {
                value = defaultAnnotation.shortValues();
            } else if (componentType == Short.class) {
                value = ArrayUtils.toObject(defaultAnnotation.shortValues());
            } else if (componentType == Float.TYPE) {
                value = defaultAnnotation.floatValues();
            } else if (componentType == Float.class) {
                value = ArrayUtils.toObject(defaultAnnotation.floatValues());
            } else if (componentType == Double.TYPE) {
                value = defaultAnnotation.doubleValues();
            } else if (componentType == Double.class) {
                value = ArrayUtils.toObject(defaultAnnotation.doubleValues());
            } else {
                log.warn("Default values for {} are not supported", componentType);
            }
        } else {
            if (injectedClass == String.class) {
                value = defaultAnnotation.values().length == 0 ? "" : defaultAnnotation.values()[0];
            } else if (injectedClass == Integer.class) {
                value = defaultAnnotation.intValues().length == 0 ? 0 : defaultAnnotation.intValues()[0];
            } else if (injectedClass == Long.class) {
                value = defaultAnnotation.longValues().length == 0 ? 0l : defaultAnnotation.longValues()[0];
            } else if (injectedClass == Boolean.class) {
                value = defaultAnnotation.booleanValues().length == 0 ? false
                        : defaultAnnotation.booleanValues()[0];
            } else if (injectedClass == Short.class) {
                value = defaultAnnotation.shortValues().length == 0 ? ((short) 0)
                        : defaultAnnotation.shortValues()[0];
            } else if (injectedClass == Float.class) {
                value = defaultAnnotation.floatValues().length == 0 ? 0f : defaultAnnotation.floatValues()[0];
            } else if (injectedClass == Double.class) {
                value = defaultAnnotation.doubleValues().length == 0 ? 0d : defaultAnnotation.doubleValues()[0];
            } else {
                log.warn("Default values for {} are not supported", injectedClass);
            }
        }
    } else {
        log.warn("Cannot provide default for {}", type);
    }
    return value;
}

From source file:au.com.addstar.cellblock.configuration.AutoConfig.java

@SuppressWarnings("unchecked")
public boolean load() {
    FileConfiguration yml = new YamlConfiguration();
    try {/*from  www . j ava  2  s  .  c o m*/
        if (mFile.getParentFile().exists() || mFile.getParentFile().mkdirs()) {// Make sure the file exists
            if (mFile.exists() || mFile.createNewFile()) {
                // Parse the config
                yml.load(mFile);
                for (Field field : getClass().getDeclaredFields()) {
                    ConfigField configField = field.getAnnotation(ConfigField.class);
                    if (configField == null)
                        continue;

                    String optionName = configField.name();
                    if (optionName.isEmpty())
                        optionName = field.getName();

                    field.setAccessible(true);

                    String path = (configField.category().isEmpty() ? "" : configField.category() + ".") //$NON-NLS-2$
                            + optionName;
                    if (!yml.contains(path)) {
                        if (field.get(this) == null)
                            throw new InvalidConfigurationException(
                                    path + " is required to be set! Info:\n" + configField.comment());
                    } else {
                        // Parse the value

                        if (field.getType().isArray()) {
                            // Integer
                            if (field.getType().getComponentType().equals(Integer.TYPE))
                                field.set(this, yml.getIntegerList(path).toArray(new Integer[0]));

                            // Float
                            else if (field.getType().getComponentType().equals(Float.TYPE))
                                field.set(this, yml.getFloatList(path).toArray(new Float[0]));

                            // Double
                            else if (field.getType().getComponentType().equals(Double.TYPE))
                                field.set(this, yml.getDoubleList(path).toArray(new Double[0]));

                            // Long
                            else if (field.getType().getComponentType().equals(Long.TYPE))
                                field.set(this, yml.getLongList(path).toArray(new Long[0]));

                            // Short
                            else if (field.getType().getComponentType().equals(Short.TYPE))
                                field.set(this, yml.getShortList(path).toArray(new Short[0]));

                            // Boolean
                            else if (field.getType().getComponentType().equals(Boolean.TYPE))
                                field.set(this, yml.getBooleanList(path).toArray(new Boolean[0]));

                            // String
                            else if (field.getType().getComponentType().equals(String.class)) {
                                field.set(this, yml.getStringList(path).toArray(new String[0]));
                            } else
                                throw new IllegalArgumentException("Cannot use type "
                                        + field.getType().getSimpleName() + " for AutoConfiguration"); //$NON-NLS-1$
                        } else if (List.class.isAssignableFrom(field.getType())) {
                            if (field.getGenericType() == null)
                                throw new IllegalArgumentException(
                                        "Cannot use type List without specifying generic type for AutoConfiguration");

                            Type type = ((ParameterizedType) field.getGenericType())
                                    .getActualTypeArguments()[0];

                            if (type.equals(Integer.class))
                                field.set(this, newList((Class<? extends List<Integer>>) field.getType(),
                                        yml.getIntegerList(path)));
                            else if (type.equals(Float.class))
                                field.set(this, newList((Class<? extends List<Float>>) field.getType(),
                                        yml.getFloatList(path)));
                            else if (type.equals(Double.class))
                                field.set(this, newList((Class<? extends List<Double>>) field.getType(),
                                        yml.getDoubleList(path)));
                            else if (type.equals(Long.class))
                                field.set(this, newList((Class<? extends List<Long>>) field.getType(),
                                        yml.getLongList(path)));
                            else if (type.equals(Short.class))
                                field.set(this, newList((Class<? extends List<Short>>) field.getType(),
                                        yml.getShortList(path)));
                            else if (type.equals(Boolean.class))
                                field.set(this, newList((Class<? extends List<Boolean>>) field.getType(),
                                        yml.getBooleanList(path)));
                            else if (type.equals(String.class))
                                field.set(this, newList((Class<? extends List<String>>) field.getType(),
                                        yml.getStringList(path)));
                            else
                                throw new IllegalArgumentException(
                                        "Cannot use type " + field.getType().getSimpleName() + "<" //$NON-NLS-2$
                                                + type.toString() + "> for AutoConfiguration");
                        } else if (Set.class.isAssignableFrom(field.getType())) {
                            if (field.getGenericType() == null)
                                throw new IllegalArgumentException(
                                        "Cannot use type set without specifying generic type for AytoConfiguration");

                            Type type = ((ParameterizedType) field.getGenericType())
                                    .getActualTypeArguments()[0];

                            if (type.equals(Integer.class))
                                field.set(this, newSet((Class<? extends Set<Integer>>) field.getType(),
                                        yml.getIntegerList(path)));
                            else if (type.equals(Float.class))
                                field.set(this, newSet((Class<? extends Set<Float>>) field.getType(),
                                        yml.getFloatList(path)));
                            else if (type.equals(Double.class))
                                field.set(this, newSet((Class<? extends Set<Double>>) field.getType(),
                                        yml.getDoubleList(path)));
                            else if (type.equals(Long.class))
                                field.set(this, newSet((Class<? extends Set<Long>>) field.getType(),
                                        yml.getLongList(path)));
                            else if (type.equals(Short.class))
                                field.set(this, newSet((Class<? extends Set<Short>>) field.getType(),
                                        yml.getShortList(path)));
                            else if (type.equals(Boolean.class))
                                field.set(this, newSet((Class<? extends Set<Boolean>>) field.getType(),
                                        yml.getBooleanList(path)));
                            else if (type.equals(String.class))
                                field.set(this, newSet((Class<? extends Set<String>>) field.getType(),
                                        yml.getStringList(path)));
                            else
                                throw new IllegalArgumentException(
                                        "Cannot use type " + field.getType().getSimpleName() + "<" //$NON-NLS-2$
                                                + type.toString() + "> for AutoConfiguration");
                        } else {
                            // Integer
                            if (field.getType().equals(Integer.TYPE))
                                field.setInt(this, yml.getInt(path));

                            // Float
                            else if (field.getType().equals(Float.TYPE))
                                field.setFloat(this, (float) yml.getDouble(path));

                            // Double
                            else if (field.getType().equals(Double.TYPE))
                                field.setDouble(this, yml.getDouble(path));

                            // Long
                            else if (field.getType().equals(Long.TYPE))
                                field.setLong(this, yml.getLong(path));

                            // Short
                            else if (field.getType().equals(Short.TYPE))
                                field.setShort(this, (short) yml.getInt(path));

                            // Boolean
                            else if (field.getType().equals(Boolean.TYPE))
                                field.setBoolean(this, yml.getBoolean(path));

                            // ItemStack
                            else if (field.getType().equals(ItemStack.class))
                                field.set(this, yml.getItemStack(path));

                            // String
                            else if (field.getType().equals(String.class))
                                field.set(this, yml.getString(path));
                            else
                                throw new IllegalArgumentException("Cannot use type "
                                        + field.getType().getSimpleName() + " for AutoConfiguration"); //$NON-NLS-1$
                        }
                    }
                }

                onPostLoad();
            } else {
                Bukkit.getLogger().log(Level.INFO, "Unable to create file: " + mFile.toString());
            }
        } else {
            Bukkit.getLogger().log(Level.INFO, "Unable to create file: " + mFile.getParentFile().toString());
        }
        return true;
    } catch (IOException | InvalidConfigurationException | IllegalAccessException
            | IllegalArgumentException e) {
        e.printStackTrace();
        return false;
    }
}

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

/** Write a {@link CWritable}, {@link String}, primitive type, or an array of
 * the preceding. *///from   www .ja v a 2  s  .c  om
public static void writeObject(DataOutput out, Object instance, Class declaredClass, CloudataConf conf,
        boolean arrayComponent) throws IOException {

    if (instance == null) { // null
        instance = new NullInstance(declaredClass, conf);
        declaredClass = CWritable.class;
        arrayComponent = false;
    }

    if (!arrayComponent) {
        CUTF8.writeString(out, declaredClass.getName()); // always write declared
        //System.out.println("Write:declaredClass.getName():" + declaredClass.getName());
    }

    if (declaredClass.isArray()) { // array
        int length = Array.getLength(instance);
        out.writeInt(length);
        //System.out.println("Write:length:" + length);

        if (declaredClass.getComponentType() == Byte.TYPE) {
            out.write((byte[]) instance);
        } else if (declaredClass.getComponentType() == ColumnValue.class) {
            //ColumnValue?  Deserialize? ?? ?   ?? ?  .
            writeColumnValue(out, instance, declaredClass, conf, length);
        } else {
            for (int i = 0; i < length; i++) {
                writeObject(out, Array.get(instance, i), declaredClass.getComponentType(), conf,
                        !declaredClass.getComponentType().isArray());
            }
        }
    } else if (declaredClass == String.class) { // String
        CUTF8.writeString(out, (String) instance);

    } else if (declaredClass.isPrimitive()) { // primitive type

        if (declaredClass == Boolean.TYPE) { // boolean
            out.writeBoolean(((Boolean) instance).booleanValue());
        } else if (declaredClass == Character.TYPE) { // char
            out.writeChar(((Character) instance).charValue());
        } else if (declaredClass == Byte.TYPE) { // byte
            out.writeByte(((Byte) instance).byteValue());
        } else if (declaredClass == Short.TYPE) { // short
            out.writeShort(((Short) instance).shortValue());
        } else if (declaredClass == Integer.TYPE) { // int
            out.writeInt(((Integer) instance).intValue());
        } else if (declaredClass == Long.TYPE) { // long
            out.writeLong(((Long) instance).longValue());
        } else if (declaredClass == Float.TYPE) { // float
            out.writeFloat(((Float) instance).floatValue());
        } else if (declaredClass == Double.TYPE) { // double
            out.writeDouble(((Double) instance).doubleValue());
        } else if (declaredClass == Void.TYPE) { // void
        } else {
            throw new IllegalArgumentException("Not a primitive: " + declaredClass);
        }
    } else if (declaredClass.isEnum()) { // enum
        CUTF8.writeString(out, ((Enum) instance).name());
    } else if (CWritable.class.isAssignableFrom(declaredClass)) { // Writable
        if (instance.getClass() == declaredClass) {
            out.writeShort(TYPE_SAME); // ? ?? ? ?? 
            //System.out.println("Write:TYPE_SAME:" + TYPE_SAME);

        } else {
            out.writeShort(TYPE_DIFF);
            //System.out.println("Write:TYPE_DIFF:" + TYPE_DIFF);
            CUTF8.writeString(out, instance.getClass().getName());
            //System.out.println("Write:instance.getClass().getName():" + instance.getClass().getName());
        }
        ((CWritable) instance).write(out);
        //System.out.println("Write:instance value");

    } else {
        throw new IOException("Can't write: " + instance + " as " + declaredClass);
    }
}

From source file:org.cocoa4android.util.sbjson.SBJsonWriter.java

/**
 *  //  w ww.j a v  a2  s . com
 * @param clazz   
 * @return
 */
public static boolean isNumber(Class<?> clazz) {
    return (clazz != null) && ((Byte.TYPE.isAssignableFrom(clazz)) || (Short.TYPE.isAssignableFrom(clazz))
            || (Integer.TYPE.isAssignableFrom(clazz)) || (Long.TYPE.isAssignableFrom(clazz))
            || (Float.TYPE.isAssignableFrom(clazz)) || (Double.TYPE.isAssignableFrom(clazz))
            || (Number.class.isAssignableFrom(clazz)));
}

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

public static Object getPrimitiveTypeForNull(Class<?> clazz) {
    if (clazz.equals(Long.TYPE)) {
        return 0L;
    } else if (clazz.equals(Integer.TYPE)) {
        return 0;
    } else if (clazz.equals(Float.TYPE)) {
        return 0.0F;
    } else if (clazz.equals(Double.TYPE)) {
        return 0.0D;
    } else if (clazz.equals(Boolean.TYPE)) {
        return false;
    }//  www .  j a v  a2  s.c  om
    return null;
}

From source file:org.gradle.internal.reflect.JavaReflectionUtil.java

public static Class<?> getWrapperTypeForPrimitiveType(Class<?> type) {
    if (type == Character.TYPE) {
        return Character.class;
    } else if (type == Boolean.TYPE) {
        return Boolean.class;
    } else if (type == Long.TYPE) {
        return Long.class;
    } else if (type == Integer.TYPE) {
        return Integer.class;
    } else if (type == Short.TYPE) {
        return Short.class;
    } else if (type == Byte.TYPE) {
        return Byte.class;
    } else if (type == Float.TYPE) {
        return Float.class;
    } else if (type == Double.TYPE) {
        return Double.class;
    }/*www.jav a 2s . c  o  m*/
    throw new IllegalArgumentException(
            String.format("Don't know the wrapper type for primitive type %s.", type));
}