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.evosuite.testcase.statements.FunctionalMockStatement.java

public void fillWithNullRefs() {
    for (int i = 0; i < parameters.size(); i++) {
        VariableReference ref = parameters.get(i);
        if (ref == null) {
            Class<?> expected = getExpectedParameterType(i);
            Object value = null;/*from   w  w w .  j  a  v  a  2s. co  m*/
            if (expected.isPrimitive()) {
                //can't fill a primitive with null
                if (expected.equals(Integer.TYPE)) {
                    value = 0;
                } else if (expected.equals(Float.TYPE)) {
                    value = 0f;
                } else if (expected.equals(Double.TYPE)) {
                    value = 0d;
                } else if (expected.equals(Long.TYPE)) {
                    value = 0L;
                } else if (expected.equals(Boolean.TYPE)) {
                    value = false;
                } else if (expected.equals(Short.TYPE)) {
                    value = Short.valueOf("0");
                } else if (expected.equals(Character.TYPE)) {
                    value = 'a';
                }
            }
            parameters.set(i, new ConstantValue(tc, new GenericClass(expected), value));
        }
    }
}

From source file:com.sun.faces.el.impl.Coercions.java

/**
 * Coerces a double to the given primitive number class
 *//*from   w  ww  . j av  a 2s . c  o m*/
static Number coerceToPrimitiveNumber(double pValue, Class pClass) throws ElException {
    if (pClass == Byte.class || pClass == Byte.TYPE) {
        return PrimitiveObjects.getByte((byte) pValue);
    } else if (pClass == Short.class || pClass == Short.TYPE) {
        return PrimitiveObjects.getShort((short) pValue);
    } else if (pClass == Integer.class || pClass == Integer.TYPE) {
        return PrimitiveObjects.getInteger((int) pValue);
    } else if (pClass == Long.class || pClass == Long.TYPE) {
        return PrimitiveObjects.getLong((long) pValue);
    } else if (pClass == Float.class || pClass == Float.TYPE) {
        return PrimitiveObjects.getFloat((float) pValue);
    } else if (pClass == Double.class || pClass == Double.TYPE) {
        return PrimitiveObjects.getDouble(pValue);
    } else {
        return PrimitiveObjects.getInteger(0);
    }
}

From source file:org.jasper.collectionspace.smk.datasource.JsonCSDataSource.java

protected LocaleConvertUtilsBean getConvertBean() {
    if (convertBean == null) {
        convertBean = new LocaleConvertUtilsBean();
        if (locale != null) {
            convertBean.setDefaultLocale(locale);
            convertBean.deregister();/*  www . j a va 2s  . c o  m*/
            //convertBean.lookup();
        }
        convertBean.register(new JRDateLocaleConverter(timeZone), java.util.Date.class, locale);

        // fix for https://issues.apache.org/jira/browse/BEANUTILS-351
        // remove on upgrade to BeanUtils 1.8.1
        JRFloatLocaleConverter floatConverter = new JRFloatLocaleConverter(
                locale == null ? Locale.getDefault() : locale);
        convertBean.register(floatConverter, Float.class, locale);
        convertBean.register(floatConverter, Float.TYPE, locale);
    }
    return convertBean;
}

From source file:nl.knaw.dans.common.ldap.repo.LdapMapper.java

private Object getPrimitive(Class<?> type, String s) throws NamingException {
    Object value = s;//from w  w  w  .  ja v a  2s .  c o m
    if (Integer.TYPE.equals(type)) {
        value = Integer.parseInt(s);
    } else if (Boolean.TYPE.equals(type)) {
        value = new Boolean("TRUE".equals(s));
    } else if (Long.TYPE.equals(type)) {
        value = Long.parseLong(s);
    } else if (Float.TYPE.equals(type)) {
        value = Float.parseFloat(s);
    } else if (Double.TYPE.equals(type)) {
        value = Double.parseDouble(s);
    } else if (Byte.TYPE.equals(type)) {
        value = Byte.parseByte(s);
    } else if (Short.TYPE.equals(type)) {
        value = Short.parseShort(s);
    }
    return value;
}

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

public org.apache.commons.configuration.Configuration mockConfiguration(Field field, boolean isInconfig) {
    if (field == null) {
        return null;
    }//from w w  w  .j a v  a2 s  .co m
    org.apache.commons.configuration.Configuration configuration = mock(
            org.apache.commons.configuration.Configuration.class);
    when(configuration.containsKey(field.getName())).thenReturn(isInconfig);
    if (isInconfig) {
        Class<?> type = field.getType();
        String configParamName = field.getAnnotation(Configuration.class).value();
        if (type.isArray()) {
            type = type.getComponentType();

            if (type == Integer.TYPE || type == Integer.class) {
                when(configuration.getStringArray(configParamName))
                        .thenReturn(new String[] { String.valueOf(Integer.MAX_VALUE) });
            } else if (type == Boolean.TYPE || type == Boolean.class) {
                when(configuration.getStringArray(configParamName)).thenReturn(new String[] { "true" });
            } else if (type == Short.TYPE || type == Short.class) {
                when(configuration.getStringArray(configParamName))
                        .thenReturn(new String[] { String.valueOf(Short.MAX_VALUE) });
            } else if (type == Byte.TYPE || type == Byte.class) {
                when(configuration.getStringArray(configParamName))
                        .thenReturn(new String[] { String.valueOf(Byte.MAX_VALUE) });
            } else if (type == Long.TYPE || type == Long.class) {
                when(configuration.getStringArray(configParamName))
                        .thenReturn(new String[] { String.valueOf(Long.MAX_VALUE) });
            } else if (type == Float.TYPE || type == Float.class) {
                when(configuration.getStringArray(configParamName))
                        .thenReturn(new String[] { String.valueOf(Float.MAX_VALUE) });
            } else if (type == Double.TYPE || type == Double.class) {
                when(configuration.getStringArray(configParamName))
                        .thenReturn(new String[] { String.valueOf(Double.MAX_VALUE) });
            } else if (type == Character.TYPE || type == Character.class) {
                when(configuration.getStringArray(configParamName)).thenReturn(new String[] { "t" });
            } else if (type == String.class) {
                when(configuration.getStringArray(configParamName)).thenReturn(new String[] { "test" });
            } else
                throw new IllegalArgumentException("Type " + type + " cannot be mocked");
        } else {
            if (type == Integer.TYPE || type == Integer.class) {
                when(configuration.getString(configParamName)).thenReturn(String.valueOf(Integer.MAX_VALUE));
            } else if (type == Boolean.TYPE || type == Boolean.class) {
                when(configuration.getString(configParamName)).thenReturn("true");
            } else if (type == Short.TYPE || type == Short.class) {
                when(configuration.getString(configParamName)).thenReturn(String.valueOf(Short.MAX_VALUE));
            } else if (type == Byte.TYPE || type == Byte.class) {
                when(configuration.getString(configParamName)).thenReturn(String.valueOf(Byte.MAX_VALUE));
            } else if (type == Long.TYPE || type == Long.class) {
                when(configuration.getString(configParamName)).thenReturn(String.valueOf(Long.MAX_VALUE));
            } else if (type == Float.TYPE || type == Float.class) {
                when(configuration.getString(configParamName)).thenReturn(String.valueOf(Float.MAX_VALUE));
            } else if (type == Double.TYPE || type == Double.class) {
                when(configuration.getString(configParamName)).thenReturn(String.valueOf(Double.MAX_VALUE));
            } else if (type == Character.TYPE || type == Character.class) {
                when(configuration.getString(configParamName)).thenReturn("t");
            } else if (type == String.class) {
                when(configuration.getString(configParamName)).thenReturn("test");
            } else
                throw new IllegalArgumentException("Type " + type + " cannot be mocked");
        }
    }
    return configuration;
}

From source file:com.sun.faces.el.impl.Coercions.java

/**
 * Coerces a Number to the given primitive number class
 *///from  w w  w .  j  av a2  s .c  o m
static Number coerceToPrimitiveNumber(Number pValue, Class pClass) throws ElException {
    if (pClass == Byte.class || pClass == Byte.TYPE) {
        return PrimitiveObjects.getByte(pValue.byteValue());
    } else if (pClass == Short.class || pClass == Short.TYPE) {
        return PrimitiveObjects.getShort(pValue.shortValue());
    } else if (pClass == Integer.class || pClass == Integer.TYPE) {
        return PrimitiveObjects.getInteger(pValue.intValue());
    } else if (pClass == Long.class || pClass == Long.TYPE) {
        return PrimitiveObjects.getLong(pValue.longValue());
    } else if (pClass == Float.class || pClass == Float.TYPE) {
        return PrimitiveObjects.getFloat(pValue.floatValue());
    } else if (pClass == Double.class || pClass == Double.TYPE) {
        return PrimitiveObjects.getDouble(pValue.doubleValue());
    } else if (pClass == BigInteger.class) {
        if (pValue instanceof BigDecimal)
            return ((BigDecimal) pValue).toBigInteger();
        else
            return BigInteger.valueOf(pValue.longValue());
    } else if (pClass == BigDecimal.class) {
        if (pValue instanceof BigInteger)
            return new BigDecimal((BigInteger) pValue);
        else
            return new BigDecimal(pValue.doubleValue());
    } else {
        return PrimitiveObjects.getInteger(0);
    }
}

From source file:de.micromata.genome.util.bean.PrivateBeanUtils.java

/**
 * Gets the bean size intern./*ww w .j a  v a 2 s.  c o  m*/
 *
 * @param bean the bean
 * @param clazz the clazz
 * @param m the m
 * @param classNameMatcher the class name matcher
 * @param fieldNameMatcher the field name matcher
 * @return the bean size intern
 */
public static int getBeanSizeIntern(Object bean, Class<?> clazz, IdentityHashMap<Object, Object> m,
        Matcher<String> classNameMatcher, Matcher<String> fieldNameMatcher) {
    if (classNameMatcher.match(clazz.getName()) == false) {
        return 0;
    }
    if (clazz.isArray() == true) {
        if (clazz == boolean[].class) {
            return (((boolean[]) bean).length * 4);
        } else if (clazz == char[].class) {
            return (((char[]) bean).length * 2);
        } else if (clazz == byte[].class) {
            return (((byte[]) bean).length * 1);
        } else if (clazz == short[].class) {
            return (((short[]) bean).length * 2);
        } else if (clazz == int[].class) {
            return (((int[]) bean).length * 4);
        } else if (clazz == long[].class) {
            return (((long[]) bean).length * 4);
        } else if (clazz == float[].class) {
            return (((float[]) bean).length * 4);
        } else if (clazz == double[].class) {
            return (((double[]) bean).length * 8);
        } else {
            int length = Array.getLength(bean);
            int ret = (length * 4);
            for (int i = 0; i < length; ++i) {
                ret += getBeanSize(Array.get(bean, i), m, classNameMatcher, fieldNameMatcher);
            }
            return ret;
        }
    }
    int ret = 0;
    try {
        for (Field f : clazz.getDeclaredFields()) {
            int mod = f.getModifiers();
            if (Modifier.isStatic(mod) == true) {
                continue;
            }
            if (fieldNameMatcher.match(clazz.getName() + "." + f.getName()) == false) {
                continue;
            }
            if (f.getType() == Boolean.TYPE) {
                ret += 4;
            } else if (f.getType() == Character.TYPE) {
                ret += 2;
            } else if (f.getType() == Byte.TYPE) {
                ret += 1;
            } else if (f.getType() == Short.TYPE) {
                ret += 2;
            } else if (f.getType() == Integer.TYPE) {
                ret += 4;
            } else if (f.getType() == Long.TYPE) {
                ret += 8;
            } else if (f.getType() == Float.TYPE) {
                ret += 4;
            } else if (f.getType() == Double.TYPE) {
                ret += 8;
            } else {

                ret += 4;
                Object o = null;
                try {
                    o = readField(bean, f);
                    if (o == null) {
                        continue;
                    }
                } catch (NoClassDefFoundError ex) {
                    // nothing
                    continue;
                }
                int nestedsize = getBeanSize(o, o.getClass(), m, classNameMatcher, fieldNameMatcher);
                ret += nestedsize;
            }
        }
    } catch (NoClassDefFoundError ex) {
        // ignore here.
    }
    if (clazz == Object.class || clazz.getSuperclass() == null) {
        return ret;
    }
    ret += getBeanSizeIntern(bean, clazz.getSuperclass(), m, classNameMatcher, fieldNameMatcher);
    return ret;
}

From source file:org.apache.syncope.core.provisioning.java.ConnectorFacadeProxy.java

private Object getPropertyValue(final String propType, final List<?> values) {
    Object value = null;//from  ww w  . j av a 2 s.co m

    try {
        Class<?> propertySchemaClass = ClassUtils.forName(propType, ClassUtils.getDefaultClassLoader());

        if (GuardedString.class.equals(propertySchemaClass)) {
            value = new GuardedString(values.get(0).toString().toCharArray());
        } else if (GuardedByteArray.class.equals(propertySchemaClass)) {
            value = new GuardedByteArray((byte[]) values.get(0));
        } else if (Character.class.equals(propertySchemaClass) || Character.TYPE.equals(propertySchemaClass)) {
            value = values.get(0) == null || values.get(0).toString().isEmpty() ? null
                    : values.get(0).toString().charAt(0);
        } else if (Integer.class.equals(propertySchemaClass) || Integer.TYPE.equals(propertySchemaClass)) {
            value = Integer.parseInt(values.get(0).toString());
        } else if (Long.class.equals(propertySchemaClass) || Long.TYPE.equals(propertySchemaClass)) {
            value = Long.parseLong(values.get(0).toString());
        } else if (Float.class.equals(propertySchemaClass) || Float.TYPE.equals(propertySchemaClass)) {
            value = Float.parseFloat(values.get(0).toString());
        } else if (Double.class.equals(propertySchemaClass) || Double.TYPE.equals(propertySchemaClass)) {
            value = Double.parseDouble(values.get(0).toString());
        } else if (Boolean.class.equals(propertySchemaClass) || Boolean.TYPE.equals(propertySchemaClass)) {
            value = Boolean.parseBoolean(values.get(0).toString());
        } else if (URI.class.equals(propertySchemaClass)) {
            value = URI.create(values.get(0).toString());
        } else if (File.class.equals(propertySchemaClass)) {
            value = new File(values.get(0).toString());
        } else if (String[].class.equals(propertySchemaClass)) {
            value = values.toArray(new String[] {});
        } else {
            value = values.get(0) == null ? null : values.get(0).toString();
        }
    } catch (Exception e) {
        LOG.error("Invalid ConnConfProperty specified: {} {}", propType, values, e);
    }

    return value;
}

From source file:org.apache.syncope.core.provisioning.java.MappingManagerImpl.java

@Transactional(readOnly = true)
@Override//from   w w  w  .j  a v a2  s. c o  m
public List<PlainAttrValue> getIntValues(final Provision provision, final Item mapItem,
        final IntAttrName intAttrName, final Any<?> any) {

    LOG.debug("Get internal values for {} as '{}' on {}", any, mapItem.getIntAttrName(),
            provision.getResource());

    Any<?> reference = null;
    Membership<?> membership = null;
    if (intAttrName.getEnclosingGroup() == null && intAttrName.getRelatedAnyObject() == null) {
        reference = any;
    }
    if (any instanceof GroupableRelatable) {
        GroupableRelatable<?, ?, ?, ?, ?> groupableRelatable = (GroupableRelatable<?, ?, ?, ?, ?>) any;

        if (intAttrName.getEnclosingGroup() != null) {
            Group group = groupDAO.findByName(intAttrName.getEnclosingGroup());
            if (group == null || !groupableRelatable.getMembership(group.getKey()).isPresent()) {
                LOG.warn("No membership for {} in {}, ignoring", intAttrName.getEnclosingGroup(),
                        groupableRelatable);
            } else {
                reference = group;
            }
        } else if (intAttrName.getRelatedAnyObject() != null) {
            AnyObject anyObject = anyObjectDAO.findByName(intAttrName.getRelatedAnyObject());
            if (anyObject == null || groupableRelatable.getRelationships(anyObject.getKey()).isEmpty()) {
                LOG.warn("No relationship for {} in {}, ignoring", intAttrName.getRelatedAnyObject(),
                        groupableRelatable);
            } else {
                reference = anyObject;
            }
        } else if (intAttrName.getMembershipOfGroup() != null) {
            Group group = groupDAO.findByName(intAttrName.getMembershipOfGroup());
            membership = groupableRelatable.getMembership(group.getKey()).orElse(null);
        }
    }
    if (reference == null) {
        LOG.warn("Could not determine the reference instance for {}", mapItem.getIntAttrName());
        return Collections.emptyList();
    }

    List<PlainAttrValue> values = new ArrayList<>();
    boolean transform = true;

    AnyUtils anyUtils = anyUtilsFactory.getInstance(reference);
    if (intAttrName.getField() != null) {
        PlainAttrValue attrValue = anyUtils.newPlainAttrValue();

        switch (intAttrName.getField()) {
        case "key":
            attrValue.setStringValue(reference.getKey());
            values.add(attrValue);
            break;

        case "realm":
            attrValue.setStringValue(reference.getRealm().getFullPath());
            values.add(attrValue);
            break;

        case "password":
            // ignore
            break;

        case "userOwner":
        case "groupOwner":
            Mapping uMapping = provision.getAnyType().equals(anyTypeDAO.findUser()) ? provision.getMapping()
                    : null;
            Mapping gMapping = provision.getAnyType().equals(anyTypeDAO.findGroup()) ? provision.getMapping()
                    : null;

            if (reference instanceof Group) {
                Group group = (Group) reference;
                String groupOwnerValue = null;
                if (group.getUserOwner() != null && uMapping != null) {
                    groupOwnerValue = getGroupOwnerValue(provision, group.getUserOwner());
                }
                if (group.getGroupOwner() != null && gMapping != null) {
                    groupOwnerValue = getGroupOwnerValue(provision, group.getGroupOwner());
                }

                if (StringUtils.isNotBlank(groupOwnerValue)) {
                    attrValue.setStringValue(groupOwnerValue);
                    values.add(attrValue);
                }
            }
            break;

        case "suspended":
            if (reference instanceof User) {
                attrValue.setBooleanValue(((User) reference).isSuspended());
                values.add(attrValue);
            }
            break;

        case "mustChangePassword":
            if (reference instanceof User) {
                attrValue.setBooleanValue(((User) reference).isMustChangePassword());
                values.add(attrValue);
            }
            break;

        default:
            try {
                Object fieldValue = FieldUtils.readField(reference, intAttrName.getField(), true);
                if (fieldValue instanceof Date) {
                    // needed because ConnId does not natively supports the Date type
                    attrValue.setStringValue(DateFormatUtils.ISO_8601_EXTENDED_DATETIME_TIME_ZONE_FORMAT
                            .format((Date) fieldValue));
                } else if (Boolean.TYPE.isInstance(fieldValue)) {
                    attrValue.setBooleanValue((Boolean) fieldValue);
                } else if (Double.TYPE.isInstance(fieldValue) || Float.TYPE.isInstance(fieldValue)) {
                    attrValue.setDoubleValue((Double) fieldValue);
                } else if (Long.TYPE.isInstance(fieldValue) || Integer.TYPE.isInstance(fieldValue)) {
                    attrValue.setLongValue((Long) fieldValue);
                } else {
                    attrValue.setStringValue(fieldValue.toString());
                }
                values.add(attrValue);
            } catch (Exception e) {
                LOG.error("Could not read value of '{}' from {}", intAttrName.getField(), reference, e);
            }
        }
    } else if (intAttrName.getSchemaType() != null) {
        switch (intAttrName.getSchemaType()) {
        case PLAIN:
            PlainAttr<?> attr;
            if (membership == null) {
                attr = reference.getPlainAttr(intAttrName.getSchemaName()).orElse(null);
            } else {
                attr = ((GroupableRelatable<?, ?, ?, ?, ?>) reference)
                        .getPlainAttr(intAttrName.getSchemaName(), membership).orElse(null);
            }
            if (attr != null) {
                if (attr.getUniqueValue() != null) {
                    values.add(anyUtils.clonePlainAttrValue(attr.getUniqueValue()));
                } else if (attr.getValues() != null) {
                    attr.getValues().forEach(value -> values.add(anyUtils.clonePlainAttrValue(value)));
                }
            }
            break;

        case DERIVED:
            DerSchema derSchema = derSchemaDAO.find(intAttrName.getSchemaName());
            if (derSchema != null) {
                String value = membership == null ? derAttrHandler.getValue(reference, derSchema)
                        : derAttrHandler.getValue(reference, membership, derSchema);
                if (value != null) {
                    PlainAttrValue attrValue = anyUtils.newPlainAttrValue();
                    attrValue.setStringValue(value);
                    values.add(attrValue);
                }
            }
            break;

        case VIRTUAL:
            // virtual attributes don't get transformed
            transform = false;

            VirSchema virSchema = virSchemaDAO.find(intAttrName.getSchemaName());
            if (virSchema != null) {
                LOG.debug("Expire entry cache {}-{}", reference, intAttrName.getSchemaName());
                virAttrCache.expire(reference.getType().getKey(), reference.getKey(),
                        intAttrName.getSchemaName());

                List<String> virValues = membership == null ? virAttrHandler.getValues(reference, virSchema)
                        : virAttrHandler.getValues(reference, membership, virSchema);
                virValues.stream().map(value -> {
                    PlainAttrValue attrValue = anyUtils.newPlainAttrValue();
                    attrValue.setStringValue(value);
                    return attrValue;
                }).forEachOrdered(attrValue -> values.add(attrValue));
            }
            break;

        default:
        }
    }

    LOG.debug("Internal values: {}", values);

    List<PlainAttrValue> transformed = values;
    if (transform) {
        for (ItemTransformer transformer : MappingUtils.getItemTransformers(mapItem)) {
            transformed = transformer.beforePropagation(mapItem, any, transformed);
        }
        LOG.debug("Transformed values: {}", values);
    } else {
        LOG.debug("No transformation occurred");
    }

    return transformed;
}

From source file:com.sun.faces.el.impl.Coercions.java

/**
 * Coerces a String to the given primitive number class
 *//*from   ww w . j  ava2 s  .c  om*/
static Number coerceToPrimitiveNumber(String pValue, Class pClass) throws ElException {
    if (pClass == Byte.class || pClass == Byte.TYPE) {
        return Byte.valueOf(pValue);
    } else if (pClass == Short.class || pClass == Short.TYPE) {
        return Short.valueOf(pValue);
    } else if (pClass == Integer.class || pClass == Integer.TYPE) {
        return Integer.valueOf(pValue);
    } else if (pClass == Long.class || pClass == Long.TYPE) {
        return Long.valueOf(pValue);
    } else if (pClass == Float.class || pClass == Float.TYPE) {
        return Float.valueOf(pValue);
    } else if (pClass == Double.class || pClass == Double.TYPE) {
        return Double.valueOf(pValue);
    } else if (pClass == BigInteger.class) {
        return new BigInteger(pValue);
    } else if (pClass == BigDecimal.class) {
        return new BigDecimal(pValue);
    } else {
        return PrimitiveObjects.getInteger(0);
    }
}