List of usage examples for java.lang Float TYPE
Class TYPE
To view the source code for java.lang Float TYPE.
Click Source Link
From source file:com.epam.catgenome.manager.externaldb.bindings.ExternalDBBindingTest.java
private Object createParam(Class type) throws IllegalAccessException, InvocationTargetException, InstantiationException { Object param;// ww w . ja v a 2s . co m if (type == String.class) { param = "test"; } else if (type == Integer.class || type == Integer.TYPE) { param = RandomUtils.nextInt(); } else if (type == Long.class || type == Long.TYPE) { param = RandomUtils.nextLong(); } else if (type == Float.class || type == Float.TYPE) { param = RandomUtils.nextFloat(); } else if (type == Double.class || type == Double.TYPE) { param = RandomUtils.nextDouble(); } else if (type == Boolean.class || type == Boolean.TYPE) { param = RandomUtils.nextBoolean(); } else if (type == BigInteger.class) { param = new BigInteger(TEST_BIGINTEGER); } else if (type == List.class) { param = new ArrayList<>(); } else if (type == XMLGregorianCalendar.class) { try { param = DatatypeFactory.newInstance().newXMLGregorianCalendar(); } catch (DatatypeConfigurationException e) { throw new IllegalArgumentException(e.getMessage(), e); } } else { Constructor[] constructors = type.getConstructors(); param = constructors[0].newInstance(); } return param; }
From source file:org.jcommon.com.util.config.ConfigLoader.java
public static void loadConf4xml(InputStream is, BaseConfigMBean config) throws FileNotFoundException { if (is == null) throw new FileNotFoundException(); try {/*w w w . jav a 2 s. co m*/ Document doc = new SAXReader().read(is); Element root = doc.getRootElement(); String element = null; Class<?> type = null; java.lang.reflect.Field[] fs = config.getClass().getDeclaredFields(); for (java.lang.reflect.Field f : fs) { element = f.getName(); String value = getTextFromElement(root, element); if (value == null) continue; type = f.getType(); Object args = null; java.lang.reflect.Method m = getMethod(config.getClass(), "set" + element); if (m == null) m = getMethod(config.getClass(), "is" + element); if (m != null) { if (notNull(value)) { if (String.class == type) { args = value; } else if (java.lang.Integer.class == type || Integer.TYPE == type) { args = Integer.valueOf(value); } else if (java.lang.Boolean.class == type || Boolean.TYPE == type) { args = Boolean.parseBoolean(value); } else if (java.lang.Long.class == type || Long.TYPE == type) { args = Long.valueOf(value); } else if (java.lang.Float.class == type || Float.TYPE == type) { args = Float.valueOf(value); } else if (java.util.Collection.class.isAssignableFrom(type)) { args = loadCollection(root, element, f); } else if (java.util.Map.class.isAssignableFrom(type)) { args = loadMap(root, element, f); } else { logger.info("not map Class:" + type); continue; } } try { m.invoke(config, args); logger.info(element + ":" + value); } catch (Exception e) { logger.warn(e); continue; } } else if (notNull(value)) logger.warn("can't find element:" + value); } try { is.close(); } catch (Exception e) { } logger.info(String.format("Read config file: %s", is)); } catch (Throwable t) { logger.error("read config file error:" + is + "\n" + t.getMessage()); } }
From source file:com.github.michalbednarski.intentslab.Utils.java
public static Object getDefaultValueForPrimitveClass(Class<?> aClass) { if (aClass == Boolean.TYPE) { return false; } else if (aClass == Byte.TYPE) { return (byte) 0; } else if (aClass == Character.TYPE) { return 0; } else if (aClass == Short.TYPE) { return (short) 0; } else if (aClass == Integer.TYPE) { return 0; } else if (aClass == Long.TYPE) { return (long) 0; } else if (aClass == Float.TYPE) { return 0; } else if (aClass == Double.TYPE) { return 0; } else {//from w w w . j a v a 2 s .c o m throw new RuntimeException("Not primitive type"); } }
From source file:cc.aileron.accessor.TypeConvertorImpl.java
/** * default constractor//ww w .j a va 2s . c o m */ @Inject public TypeConvertorImpl() { map.put(Boolean.TYPE, new C() { @Override public Boolean convert(final java.lang.Number number) { return number.intValue() != 0; } }); map.put(Byte.TYPE, new C() { @Override public Byte convert(final java.lang.Number number) { return number.byteValue(); } }); map.put(Short.TYPE, new C() { @Override public Short convert(final java.lang.Number number) { return number.shortValue(); } }); map.put(Integer.TYPE, new C() { @Override public Integer convert(final java.lang.Number number) { return number.intValue(); } }); map.put(Long.TYPE, new C() { @Override public Long convert(final java.lang.Number number) { return number.longValue(); } }); map.put(Float.TYPE, new C() { @Override public Float convert(final java.lang.Number number) { return number.floatValue(); } }); map.put(Double.TYPE, new C() { @Override public Double convert(final java.lang.Number number) { return number.doubleValue(); } }); }
From source file:org.soybeanMilk.SbmUtils.java
/** * ?<code>type</code>?/*from ww w. ja va2 s.c om*/ * @param type * @return * @date 2010-12-31 */ public static Type wrapType(Type type) { if (!isClassType(type)) return type; else if (!narrowToClass(type).isPrimitive()) return type; else if (Byte.TYPE.equals(type)) return Byte.class; else if (Short.TYPE.equals(type)) return Short.class; else if (Integer.TYPE.equals(type)) return Integer.class; else if (Long.TYPE.equals(type)) return Long.class; else if (Float.TYPE.equals(type)) return Float.class; else if (Double.TYPE.equals(type)) return Double.class; else if (Boolean.TYPE.equals(type)) return Boolean.class; else if (Character.TYPE.equals(type)) return Character.class; else return type; }
From source file:com.adobe.acs.commons.data.Variant.java
@SuppressWarnings("squid:S3776") public final <T> void setValue(T val) { if (val == null) { return;//from ww w .ja v a 2 s . c o m } Class type = val.getClass(); if (type == Variant.class) { Variant v = (Variant) val; longVal = v.longVal; doubleVal = v.doubleVal; stringVal = v.stringVal; booleanVal = v.booleanVal; dateVal = v.dateVal; } else if (type == Byte.TYPE || type == Byte.class) { setLongVal(((Byte) val).longValue()); } else if (type == Integer.TYPE || type == Integer.class) { setLongVal(((Integer) val).longValue()); } else if (type == Long.TYPE || type == Long.class) { setLongVal((Long) val); } else if (type == Short.TYPE || type == Short.class) { setLongVal(((Short) val).longValue()); } else if (type == Float.TYPE || type == Float.class) { setDoubleVal((Double) val); } else if (type == Double.TYPE || type == Double.class) { setDoubleVal((Double) val); } else if (type == Boolean.TYPE || type == Boolean.class) { setBooleanVal((Boolean) val); } else if (type == String.class) { setStringVal((String) val); } else if (type == Date.class) { setDateVal((Date) val); } else if (type == Instant.class) { setDateVal(new Date(((Instant) val).toEpochMilli())); } else if (type == Calendar.class) { setDateVal(((Calendar) val).getTime()); } else { setStringVal(String.valueOf(val)); } }
From source file:org.atemsource.atem.impl.common.attribute.primitive.PrimitiveTypeFactory.java
@PostConstruct public void initialize() { classes = new ArrayList<Class>(); classes.add(String.class); classes.add(Boolean.class); classes.add(Boolean.TYPE);// w ww. ja v a 2 s . co m classes.add(Long.class); classes.add(Long.TYPE); classes.add(Integer.class); classes.add(Integer.TYPE); classes.add(Float.class); classes.add(Float.TYPE); classes.add(Double.TYPE); classes.add(Double.class); classes.add(Character.TYPE); classes.add(Character.TYPE); classes.add(Character.class); classes.add(Byte.TYPE); classes.add(Byte.class); classes.add(Enum.class); classes.add(BigInteger.class); classes.add(BigDecimal.class); Collection<PrimitiveTypeRegistrar> registrars = beanLocator.getInstances(PrimitiveTypeRegistrar.class); for (PrimitiveTypeRegistrar registrar : registrars) { PrimitiveType<?>[] types = registrar.getTypes(); for (PrimitiveType<?> primitiveType : types) { classToType.put(primitiveType.getJavaType(), primitiveType); classes.add(primitiveType.getJavaType()); } } }
From source file:org.openflexo.antar.binding.TypeUtils.java
public static boolean isFloat(Type type) { if (type == null) { return false; }/*from w w w . j a v a 2s. co m*/ return type.equals(Float.class) || type.equals(Float.TYPE); }
From source file:org.kordamp.ezmorph.object.NumberMorpher.java
public Object morph(Object value) { if (value != null && type.isAssignableFrom(value.getClass())) { // no conversion needed return value; }//from www . ja 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; } 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); } } }
From source file:jef.tools.ArrayUtils.java
/** * ?// ww w. j a va 2 s. c o m * * @param obj * @return */ public static Object[] toObject(Object obj) { Class<?> c = obj.getClass(); Assert.isTrue(c.isArray()); Class<?> priType = c.getComponentType(); if (!priType.isPrimitive()) return (Object[]) obj; if (priType == Boolean.TYPE) { return toObject((boolean[]) obj); } else if (priType == Byte.TYPE) { return toObject((byte[]) obj); } else if (priType == Character.TYPE) { return toObject((char[]) obj); } else if (priType == Integer.TYPE) { return toObject((int[]) obj); } else if (priType == Long.TYPE) { return toObject((long[]) obj); } else if (priType == Float.TYPE) { return toObject((float[]) obj); } else if (priType == Double.TYPE) { return toObject((double[]) obj); } else if (priType == Short.TYPE) { return toObject((short[]) obj); } throw new IllegalArgumentException(); }