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:org.skfiy.typhon.spi.GMConsoleProvider.java
/** * * @param uid//from w w w .j a va2 s . com * @param propertyName * @param val * @throws javax.management.MBeanException */ public void changeProperty(final String uid, final String propertyName, final String val) throws MBeanException { try { invoke(transcoding(uid), new Handler() { @Override void execute() { Player player = SessionUtils.getPlayer(); try { Class<?> propertyType = PropertyUtils.getPropertyType(player, propertyName); if (propertyType == null) { // Not found property throw new IllegalArgumentException("Not found property[" + propertyName + "]"); } if (propertyType == Byte.class || propertyType == Byte.TYPE) { BeanUtils.setProperty(player, propertyName, Byte.valueOf(val)); } else if (propertyType == Character.class || propertyType == Character.TYPE) { BeanUtils.setProperty(player, propertyName, val.charAt(0)); } else if (propertyType == Boolean.class || propertyType == Boolean.TYPE) { BeanUtils.setProperty(player, propertyName, Boolean.valueOf(val)); } else if (propertyType == Integer.class || propertyType == Integer.TYPE) { BeanUtils.setProperty(player, propertyName, Integer.valueOf(val)); } else if (propertyType == Long.class || propertyType == Long.TYPE) { BeanUtils.setProperty(player, propertyName, Long.valueOf(val)); } else if (propertyType == Float.class || propertyType == Float.TYPE) { BeanUtils.setProperty(player, propertyName, Float.valueOf(val)); } else if (propertyType == Double.class || propertyType == Double.TYPE) { BeanUtils.setProperty(player, propertyName, Double.valueOf(val)); } else { BeanUtils.setProperty(player, propertyName, val); } } catch (Exception ex) { throw new IllegalArgumentException(ex.getMessage()); } } }); } catch (Exception e) { throw new MBeanException(e, e.getMessage()); } }
From source file:org.briljantframework.data.resolver.Resolve.java
private static Resolver<Double> initializeDoubleResolver() { Resolver<Double> doubleResolver = new Resolver<>(Double.class); doubleResolver.put(Number.class, Number::doubleValue); doubleResolver.put(Double.class, Number::doubleValue); doubleResolver.put(Double.TYPE, Number::doubleValue); doubleResolver.put(Float.class, Number::doubleValue); doubleResolver.put(Float.TYPE, Number::doubleValue); doubleResolver.put(Long.class, Number::doubleValue); doubleResolver.put(Long.TYPE, Number::doubleValue); doubleResolver.put(Integer.class, Number::doubleValue); doubleResolver.put(Integer.TYPE, Number::doubleValue); doubleResolver.put(Short.class, Number::doubleValue); doubleResolver.put(Short.TYPE, Number::doubleValue); doubleResolver.put(Byte.class, Number::doubleValue); doubleResolver.put(Byte.TYPE, Number::doubleValue); doubleResolver.put(String.class, s -> { Number n = toNumber(s);//from w w w . j a v a 2 s. c om return n != null ? n.doubleValue() : Na.BOXED_DOUBLE; }); return doubleResolver; }
From source file:in.hatimi.nosh.support.CmdLineManager.java
private boolean injectString(Object target, Field field, String value) { if (field.getType().equals(Boolean.class) || field.getType().equals(Boolean.TYPE)) { Boolean vobj = new Boolean(value); return injectImpl(target, field, vobj); }//from w w w . j a v a 2s . co m if (field.getType().equals(Double.class) || field.getType().equals(Double.TYPE)) { Double vobj = Double.valueOf(value); return injectImpl(target, field, vobj); } if (field.getType().equals(Float.class) || field.getType().equals(Float.TYPE)) { Float vobj = Float.valueOf(value); return injectImpl(target, field, vobj); } if (field.getType().equals(Long.class) || field.getType().equals(Long.TYPE)) { Long vobj = Long.valueOf(value); return injectImpl(target, field, vobj); } if (field.getType().equals(Integer.class) || field.getType().equals(Integer.TYPE)) { Integer vobj = Integer.valueOf(value); return injectImpl(target, field, vobj); } if (field.getType().equals(String.class)) { return injectImpl(target, field, value); } if (field.getType().equals(byte[].class)) { return injectImpl(target, field, value.getBytes()); } if (field.getType().equals(char[].class)) { return injectImpl(target, field, value.toCharArray()); } return false; }
From source file:com.nonninz.robomodel.RoboModel.java
private void loadField(Field field, Cursor query) throws DatabaseNotUpToDateException { final Class<?> type = field.getType(); final boolean wasAccessible = field.isAccessible(); final int columnIndex = query.getColumnIndex(field.getName()); field.setAccessible(true);/*w w w.jav a 2 s . c o m*/ /* * TODO: There is the potential of a problem here: * What happens if the developer changes the type of a field between releases? * * If he saves first, then the column type will be changed (In the future). * If he loads first, we don't know if an Exception will be thrown if the * types are incompatible, because it's undocumented in the Cursor documentation. */ try { if (type == String.class) { field.set(this, query.getString(columnIndex)); } else if (type == Boolean.TYPE) { final boolean value = query.getInt(columnIndex) == 1 ? true : false; field.setBoolean(this, value); } else if (type == Byte.TYPE) { field.setByte(this, (byte) query.getShort(columnIndex)); } else if (type == Double.TYPE) { field.setDouble(this, query.getDouble(columnIndex)); } else if (type == Float.TYPE) { field.setFloat(this, query.getFloat(columnIndex)); } else if (type == Integer.TYPE) { field.setInt(this, query.getInt(columnIndex)); } else if (type == Long.TYPE) { field.setLong(this, query.getLong(columnIndex)); } else if (type == Short.TYPE) { field.setShort(this, query.getShort(columnIndex)); } else if (type.isEnum()) { final String string = query.getString(columnIndex); if (string != null && string.length() > 0) { final Object[] constants = type.getEnumConstants(); final Method method = type.getMethod("valueOf", Class.class, String.class); final Object value = method.invoke(constants[0], type, string); field.set(this, value); } } else { // Try to de-json it (db column must be of type text) try { final Object value = mMapper.readValue(query.getString(columnIndex), field.getType()); field.set(this, value); } catch (final Exception e) { final String msg = String.format("Type %s is not supported for field %s", type, field.getName()); Ln.w(e, msg); throw new IllegalArgumentException(msg); } } } catch (final IllegalAccessException e) { final String msg = String.format("Field %s is not accessible", type, field.getName()); throw new IllegalArgumentException(msg); } catch (final NoSuchMethodException e) { // Should not happen throw new RuntimeException(e); } catch (final InvocationTargetException e) { // Should not happen throw new RuntimeException(e); } catch (IllegalStateException e) { // This is when there is no column in db, but there is in the model throw new DatabaseNotUpToDateException(e); } finally { field.setAccessible(wasAccessible); } }
From source file:org.evosuite.regression.ObjectFields.java
private static Object getFieldValue(Field field, Object p) { try {//from www. j ava 2 s . co m /*Class objClass = p.getClass(); if(p instanceof java.lang.String){ ((String) p).hashCode(); }*/ Class<?> fieldType = field.getType(); field.setAccessible(true); if (fieldType.isPrimitive()) { if (fieldType.equals(Boolean.TYPE)) { return field.getBoolean(p); } if (fieldType.equals(Integer.TYPE)) { return field.getInt(p); } if (fieldType.equals(Byte.TYPE)) { return field.getByte(p); } if (fieldType.equals(Short.TYPE)) { return field.getShort(p); } if (fieldType.equals(Long.TYPE)) { return field.getLong(p); } if (fieldType.equals(Double.TYPE)) { return field.getDouble(p); } if (fieldType.equals(Float.TYPE)) { return field.getFloat(p); } if (fieldType.equals(Character.TYPE)) { return field.getChar(p); } throw new UnsupportedOperationException("Primitive type " + fieldType + " not implemented!"); } return field.get(p); } catch (IllegalAccessException exc) { throw new RuntimeException(exc); } catch (OutOfMemoryError e) { e.printStackTrace(); if (MAX_RECURSION != 0) MAX_RECURSION = 0; else throw new RuntimeErrorException(e); return getFieldValue(field, p); } }
From source file:com.adobe.acs.commons.mcp.util.AnnotatedFieldDeserializer.java
@SuppressWarnings("squid:S3776") private static Object convertPrimitiveValue(String value, Class<?> type) throws ParseException { if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) { return value.toLowerCase().trim().equals("true"); } else {/* w w w. j a va2 s .c o m*/ NumberFormat numberFormat = NumberFormat.getNumberInstance(); Number num = numberFormat.parse(value); if (type.equals(Byte.class) || type.equals(Byte.TYPE)) { return num.byteValue(); } else if (type.equals(Double.class) || type.equals(Double.TYPE)) { return num.doubleValue(); } else if (type.equals(Float.class) || type.equals(Float.TYPE)) { return num.floatValue(); } else if (type.equals(Integer.class) || type.equals(Integer.TYPE)) { return num.intValue(); } else if (type.equals(Long.class) || type.equals(Long.TYPE)) { return num.longValue(); } else if (type.equals(Short.class) || type.equals(Short.TYPE)) { return num.shortValue(); } else { return null; } } }
From source file:com.ms.commons.summer.web.util.json.JsonNumberMorpher.java
private boolean isDecimalNumber(Class<?> type) { return (Double.class.isAssignableFrom(type) || Float.class.isAssignableFrom(type) || Double.TYPE == type || Float.TYPE == type || BigDecimal.class.isAssignableFrom(type)); }
From source file:candr.yoclip.option.OptionField.java
@Override public void setOption(final T bean, final String value) { final Class<?> fieldType = getField().getType(); try {/*from w w w . j av a 2 s . co m*/ if (Boolean.TYPE.equals(fieldType) || Boolean.class.isAssignableFrom(fieldType)) { setBooleanOption(bean, value); } else if (Byte.TYPE.equals(fieldType) || Byte.class.isAssignableFrom(fieldType)) { setByteOption(bean, value); } else if (Short.TYPE.equals(fieldType) || Short.class.isAssignableFrom(fieldType)) { setShortOption(bean, value); } else if (Integer.TYPE.equals(fieldType) || Integer.class.isAssignableFrom(fieldType)) { setIntegerOption(bean, value); } else if (Long.TYPE.equals(fieldType) || Long.class.isAssignableFrom(fieldType)) { setLongOption(bean, value); } else if (Character.TYPE.equals(fieldType) || Character.class.isAssignableFrom(fieldType)) { setCharacterOption(bean, value); } else if (Float.TYPE.equals(fieldType) || Float.class.isAssignableFrom(fieldType)) { setFloatOption(bean, value); } else if (Double.TYPE.equals(fieldType) || Double.class.isAssignableFrom(fieldType)) { setDoubleOption(bean, value); } else if (String.class.isAssignableFrom(fieldType)) { setStringOption(bean, value); } else { final String supportedTypes = "boolean, byte, short, int, long, char, float, double, and String"; throw new OptionsParseException( String.format("OldOptionsParser only support %s types", supportedTypes)); } } catch (NumberFormatException e) { final String error = String.format("Error converting '%s' to %s", value, fieldType); throw new OptionsParseException(error, e); } }
From source file:org.kuali.kfs.sys.context.DocumentSerializabilityTest.java
/** * Determines if the given class represents one of the eight Java primitives * @param clazz the class to check//www. java2 s . c om * @return true if the class represents a byte, short, int, long, char, double, float, or boolean; false otherwise */ protected boolean isPrimitive(Class<?> clazz) { return Byte.TYPE.isAssignableFrom(clazz) || Short.TYPE.isAssignableFrom(clazz) || Integer.TYPE.isAssignableFrom(clazz) || Long.TYPE.isAssignableFrom(clazz) || Float.TYPE.isAssignableFrom(clazz) || Double.TYPE.isAssignableFrom(clazz) || Character.TYPE.isAssignableFrom(clazz) || Boolean.TYPE.isAssignableFrom(clazz); }
From source file:candr.yoclip.option.OptionSetter.java
@Override public void setOption(final T bean, final String value) { final Class<?> setterParameterType = getType(); try {// www .j a va 2s .co m if (Boolean.TYPE.equals(setterParameterType) || Boolean.class.isAssignableFrom(setterParameterType)) { setBooleanOption(bean, value); } else if (Byte.TYPE.equals(setterParameterType) || Byte.class.isAssignableFrom(setterParameterType)) { setByteOption(bean, value); } else if (Short.TYPE.equals(setterParameterType) || Short.class.isAssignableFrom(setterParameterType)) { setShortOption(bean, value); } else if (Integer.TYPE.equals(setterParameterType) || Integer.class.isAssignableFrom(setterParameterType)) { setIntegerOption(bean, value); } else if (Long.TYPE.equals(setterParameterType) || Long.class.isAssignableFrom(setterParameterType)) { setLongOption(bean, value); } else if (Character.TYPE.equals(setterParameterType) || Character.class.isAssignableFrom(setterParameterType)) { setCharacterOption(bean, value); } else if (Float.TYPE.equals(setterParameterType) || Float.class.isAssignableFrom(setterParameterType)) { setFloatOption(bean, value); } else if (Double.TYPE.equals(setterParameterType) || Double.class.isAssignableFrom(setterParameterType)) { setDoubleOption(bean, value); } else if (String.class.isAssignableFrom(setterParameterType)) { setStringOption(bean, value); } else { final String supportedTypes = "boolean, byte, short, int, long, char, float, double, and String"; throw new OptionsParseException( String.format("OptionParameter only supports %s types", supportedTypes)); } } catch (NumberFormatException e) { final String error = String.format("Error converting '%s' to %s", value, setterParameterType); throw new OptionsParseException(error, e); } }