List of usage examples for java.lang Float valueOf
@HotSpotIntrinsicCandidate public static Float valueOf(float f)
From source file:bammerbom.ultimatecore.bukkit.configuration.ConfigSection.java
public List<Float> getFloatList(String path) { List<?> list = getList(path); if (list == null) { return new ArrayList<>(0); }/*from www .j av a2 s. c o m*/ List<Float> result = new ArrayList<>(); for (Object object : list) { if (object instanceof Float) { result.add((Float) object); } else if (object instanceof String) { try { result.add(Float.valueOf((String) object)); } catch (Exception ex) { } } else if (object instanceof Character) { result.add((float) ((Character) object).charValue()); } else if (object instanceof Number) { result.add(((Number) object).floatValue()); } } return result; }
From source file:hd3gtv.mydmam.db.orm.CassandraOrm.java
private Object pullColumn(ColumnList<String> columnlist, Field field) throws InvalidClassException { String name = field.getName(); Class<?> fieldtype = field.getType(); if (columnlist.getColumnByName(name) == null) { return null; }//from w w w .j a v a 2 s . c o m if (columnlist.getColumnByName(name).hasValue() == false) { return null; } if (columnlist.getColumnByName(name).getStringValue().equals(null_value)) { return null; } else if (fieldtype.isAssignableFrom(String.class)) { return columnlist.getColumnByName(name).getStringValue(); } else if (fieldtype.isAssignableFrom(Byte[].class) | fieldtype.isAssignableFrom(byte[].class)) { return columnlist.getColumnByName(name).getByteArrayValue(); } else if (fieldtype.isAssignableFrom(Integer.class) | fieldtype.isAssignableFrom(int.class)) { return columnlist.getColumnByName(name).getIntegerValue(); } else if (fieldtype.isAssignableFrom(Long.class) | fieldtype.isAssignableFrom(long.class)) { return columnlist.getColumnByName(name).getLongValue(); } else if (fieldtype.isAssignableFrom(Boolean.class) | fieldtype.isAssignableFrom(boolean.class)) { return columnlist.getColumnByName(name).getStringValue().equals("true"); } else if (fieldtype.isAssignableFrom(Date.class)) { return columnlist.getColumnByName(name).getDateValue(); } else if (fieldtype.isAssignableFrom(Float.class) | fieldtype.isAssignableFrom(float.class)) { return Float.valueOf(columnlist.getColumnByName(name).getStringValue()); } else if (fieldtype.isAssignableFrom(Double.class) | fieldtype.isAssignableFrom(double.class)) { return Double.valueOf(columnlist.getColumnByName(name).getStringValue()); } else if (fieldtype.isAssignableFrom(UUID.class)) { return columnlist.getColumnByName(name).getUUIDValue(); } else if (fieldtype.isAssignableFrom(JSONObject.class)) { String value = ""; try { Object o = fieldtype.newInstance(); if (o instanceof JSONObject) { value = columnlist.getColumnByName(name).getStringValue(); return (JSONObject) (new JSONParser()).parse(value); } else { return deserialize(columnlist.getColumnByName(name).getStringValue(), JSONObject.class); } } catch (InstantiationException e1) { return null; } catch (IllegalAccessException e1) { return null; } catch (ParseException e) { e.printStackTrace(); System.err.println(value); return null; } } else if (fieldtype.isAssignableFrom(JSONArray.class)) { String value = ""; try { Object o = fieldtype.newInstance(); if (o instanceof JSONArray) { value = columnlist.getColumnByName(name).getStringValue(); return (JSONArray) (new JSONParser()).parse(value); } else { return deserialize(columnlist.getColumnByName(name).getStringValue(), JSONArray.class); } } catch (InstantiationException e1) { return null; } catch (IllegalAccessException e1) { return null; } catch (ParseException e) { e.printStackTrace(); System.err.println(value); return null; } } else if (fieldtype.isAssignableFrom(InetAddress.class)) { String value = columnlist.getColumnByName(name).getStringValue(); try { return InetAddress.getByName(value); } catch (UnknownHostException e) { e.printStackTrace(); System.err.println(value); return null; } } else if (fieldtype.isAssignableFrom(StringBuffer.class)) { String value = columnlist.getColumnByName(name).getStringValue(); return new StringBuffer(value); } else if (fieldtype.isAssignableFrom(Calendar.class)) { long value = columnlist.getColumnByName(name).getLongValue(); Calendar c = Calendar.getInstance(); c.setTimeInMillis(value); return c; } else if (fieldtype.isAssignableFrom(String[].class)) { String value = columnlist.getColumnByName(name).getStringValue(); try { JSONArray ja = (JSONArray) (new JSONParser()).parse(value); String[] result = new String[ja.size()]; for (int pos = 0; pos < ja.size(); pos++) { result[pos] = (String) ja.get(pos); } return result; } catch (ParseException e) { e.printStackTrace(); System.err.println(value); return null; } } else { return deserialize(columnlist.getColumnByName(name).getStringValue(), fieldtype); } }
From source file:com.ucai.test.control.DeviceControlActivity.java
private void displayDeviceData(String data) { if (data != null) { //TODO ?/*from w w w.j a v a2 s . c om*/ mDeviceDataField.setText(data); String newdata = data.substring(0, 4); weight = Double.valueOf(newdata); // Log.e("/weight", weight + ""); // ?? ??? DecimalFormat df = new DecimalFormat("#0.00"); int height = EditActivity.toHeight(); int age = EditActivity.toAge(); //? bmi = df.format(Calculaion.Bmi(height, weight)); fat = df.format(Calculaion.Fat(height, weight, age, sex)); measure_muscle = df.format(Calculaion.Muscle(height, weight, age, sex)); measure_bone = df.format(Calculaion.Bone(height, weight, age, sex)); measure_water = df.format(Calculaion.Water(height, weight, age, sex)); measure_metabolize = df.format(Calculaion.Metabolize(height, weight, age, sex)); measure_bodyage = df.format(Calculaion.BodyAge(age, sex, Calculaion.Bmi(height, weight))); // tv_bmi.setText(bmi); tv_fat.setText(fat + "%"); tv_measure_muscle.setText(measure_muscle + "%"); tv_measure_bone.setText(measure_bone + "%"); tv_measure_water.setText(measure_water + "%"); tv_measure_metabolize.setText(measure_metabolize + "?/"); tv_measure_bodyage.setText(measure_bodyage + "?"); if (data.endsWith("?")) { if (data.equals("0.0 ?")) { Log.e("cst", "data=0.0,so autoGetTemperature"); autoGetTemperature(); } else { // Log.e("cst","data!=0.0,mBluetoothLeService.disconnect()"); // mBluetoothLeService.disconnect(); final MedicalData mdata = new MedicalData(); //TODO ? mdata.setBodyWeight(Float.valueOf(data.split(" ")[0])); Log.e("cst", "----post,data=" + mdata.getBodyWeight()); //sendDataByPost(mdata); new Thread(new Runnable() { @Override public void run() { sendDataByPost(mdata);//?? } }).start(); } } } }
From source file:com.thinkbiganalytics.policy.BasePolicyAnnotationTransformer.java
public Object convertStringToObject(String value, Class type) { if (type.isEnum()) { return Enum.valueOf(type, value); } else if (String.class.equals(type)) { return value; }// w w w. j a v a 2s.c o m if (StringUtils.isBlank(value)) { return null; } else if (Number.class.equals(type)) { return NumberUtils.createNumber(value); } else if (Integer.class.equals(type) || Integer.TYPE.equals(type)) { return new Integer(value); } else if (Long.class.equals(type) || Long.TYPE.equals(type)) { return Long.valueOf(value); } else if (Double.class.equals(type) || Double.TYPE.equals(type)) { return Double.valueOf(value); } else if (Float.class.equals(type) || Float.TYPE.equals(type)) { return Float.valueOf(value); } else if (Pattern.class.equals(type)) { return Pattern.compile(value); } else if (Boolean.class.equals(type) || Boolean.TYPE.equals(type)) { return BooleanUtils.toBoolean(value); } else { throw new IllegalArgumentException( "Unable to convert the value " + value + " to an object of type " + type.getName()); } }
From source file:framework.GlobalHelpers.java
public static void setValueOfFieldOrProperty(Object object, String name, Object value) { Field field;//from w ww . jav a 2s . co m try { field = findInheritedField(object.getClass(), name); if (field != null) { field.setAccessible(true); Class<?> type = field.getType(); if (value != null && !type.equals(value.getClass())) { // TODO conversion if (type.equals(String.class)) { value = String.valueOf(value); } else if (type.equals(short.class) || type.equals(Short.class)) { value = Short.valueOf(String.valueOf(value)); } else if (type.equals(int.class) || type.equals(Integer.class)) { value = Integer.valueOf(String.valueOf(value)); } else if (type.equals(long.class) || type.equals(Long.class)) { value = Long.valueOf(String.valueOf(value)); } else if (type.equals(boolean.class) || type.equals(Boolean.class)) { value = Boolean.valueOf(String.valueOf(value)); } else if (type.equals(float.class) || type.equals(Float.class)) { value = Float.valueOf(String.valueOf(value)); } else if (type.equals(double.class) || type.equals(Double.class)) { value = Double.valueOf(String.valueOf(value)); } else if (type.equals(BigDecimal.class)) { value = new BigDecimal(String.valueOf(value)); } } field.set(object, value); } else { BeanUtils.setProperty(object, name, value); } } catch (Exception e) { // do nth, just skip not existing field (maybe log sth?) } }
From source file:com.streamsets.pipeline.stage.processor.fieldvaluereplacer.FieldValueReplacerProcessor.java
private Object convertToType(String stringValue, Field.Type fieldType, String matchingField) throws ParseException { switch (fieldType) { case BOOLEAN: return Boolean.valueOf(stringValue); case BYTE://from w ww .j a va 2s .co m return Byte.valueOf(stringValue); case BYTE_ARRAY: return stringValue.getBytes(StandardCharsets.UTF_8); case CHAR: return stringValue.charAt(0); case DATE: DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); return dateFormat.parse(stringValue); case TIME: DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss", Locale.ENGLISH); return timeFormat.parse(stringValue); case DATETIME: DateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ", Locale.ENGLISH); return dateTimeFormat.parse(stringValue); case DECIMAL: return new BigDecimal(stringValue); case DOUBLE: return Double.valueOf(stringValue); case FLOAT: return Float.valueOf(stringValue); case INTEGER: return Integer.valueOf(stringValue); case LONG: return Long.valueOf(stringValue); case SHORT: return Short.valueOf(stringValue); case FILE_REF: throw new IllegalArgumentException( Utils.format(Errors.VALUE_REPLACER_03.getMessage(), fieldType, matchingField)); case LIST_MAP: case LIST: case MAP: default: return stringValue; } }
From source file:com.gdcn.modules.db.jdbc.processor.CamelBeanProcessor.java
/** * Convert a <code>ResultSet</code> column into an object. Simple * implementations could just call <code>rs.getObject(index)</code> while * more complex implementations could perform type manipulation to match * the column's type to the bean property type. * * <p>//w w w . j a v a 2 s .co m * This implementation calls the appropriate <code>ResultSet</code> getter * method for the given property type to perform the type conversion. If * the property type doesn't match one of the supported * <code>ResultSet</code> types, <code>getObject</code> is called. * </p> * * @param rs The <code>ResultSet</code> currently being processed. It is * positioned on a valid row before being passed into this method. * * @param index The current column index being processed. * * @param propType The bean property type that this column needs to be * converted into. * * @throws SQLException if a database access error occurs * * @return The object from the <code>ResultSet</code> at the given column * index after optional type processing or <code>null</code> if the column * value was SQL NULL. */ protected Object processColumn(ResultSet rs, int index, Class<?> propType) throws SQLException { if (!propType.isPrimitive() && rs.getObject(index) == null) { return null; } if (propType.equals(String.class)) { return rs.getString(index); } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) { return Integer.valueOf(rs.getInt(index)); } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) { return Boolean.valueOf(rs.getBoolean(index)); } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) { return Long.valueOf(rs.getLong(index)); } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) { return Double.valueOf(rs.getDouble(index)); } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) { return Float.valueOf(rs.getFloat(index)); } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) { return Short.valueOf(rs.getShort(index)); } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) { return Byte.valueOf(rs.getByte(index)); } else if (propType.equals(Timestamp.class)) { return rs.getTimestamp(index); } else if (propType.equals(SQLXML.class)) { return rs.getSQLXML(index); } else { return rs.getObject(index); } }
From source file:org.paxle.tools.charts.impl.gui.ChartServlet.java
/** * Function to update charts with the newly received value * @param fullPath the full-name of the changed {@link StatusVariable} * @param value the value of a {@link StatusVariable} received via event *//*w ww. j a va2 s. com*/ private void updateValue(String fullPath, Object value) { final TimeSeries series = this.seriesMap.get(fullPath); if (series != null) { Number num = null; /* * According to the MA spec the values * must be delivered as String */ if (value instanceof String) { Integer type = this.typeList.get(fullPath); if (type != null) { switch (type.intValue()) { case StatusVariable.TYPE_FLOAT: num = Float.valueOf((String) value); break; case StatusVariable.TYPE_INTEGER: num = Integer.valueOf((String) value); break; // these types are not supported by the chart-servlet for now /* case StatusVariable.TYPE_BOOLEAN: case StatusVariable.TYPE_STRING: */ default: break; } } } /* * XXX: this is a bug of the apache felix implementation. * As defined in the OSGi spec, the value should be delivered * as String */ else if (value instanceof Number) { num = (Number) value; } else { this.logger.warn(String.format("Unexpected type of monitoring variable '%s': %s", value.getClass().getSimpleName(), fullPath)); } if (num != null) { if (fullPath.equalsIgnoreCase(TSERIES_MEMORY_USAGE)) { /* * the memory-usage value is in KB. * See org.paxle.core.monitorable.provider.impl.RuntimeMemoryMonitoring for details */ num = Integer.valueOf(num.intValue() / 1024); } else if (fullPath.startsWith(CPU_MONITORABLE_ID)) { num = new Double(num.doubleValue() * 100f); } series.addOrUpdate(new Minute(new Date()), num); } } }
From source file:gov.nih.nci.cagrid.sdk4query.processor.PublicDataCQL2ParameterizedHQL.java
private java.lang.Object valueToObject(String className, String value) throws QueryProcessingException { LOG.debug("Converting \"" + value + "\" to object of type " + className); if (className.equals(String.class.getName())) { return value; }//from w w w . j a va2 s . co m if (className.equals(Integer.class.getName())) { return Integer.valueOf(value); } if (className.equals(Long.class.getName())) { return Long.valueOf(value); } if (className.equals(Double.class.getName())) { return Double.valueOf(value); } if (className.equals(Float.class.getName())) { return Float.valueOf(value); } if (className.equals(Boolean.class.getName())) { return Boolean.valueOf(value); } if (className.equals(Character.class.getName())) { if (value.length() == 1) { return Character.valueOf(value.charAt(0)); } else { throw new QueryProcessingException( "The value \"" + value + "\" of length " + value.length() + " is not a valid character"); } } if (className.equals(Date.class.getName())) { // try time, then dateTime, then just date List<SimpleDateFormat> formats = new ArrayList<SimpleDateFormat>(3); formats.add(new SimpleDateFormat("HH:mm:ss")); formats.add(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")); formats.add(new SimpleDateFormat("yyyy-MM-dd")); Date date = null; Iterator<SimpleDateFormat> formatIter = formats.iterator(); while (date == null && formatIter.hasNext()) { SimpleDateFormat formatter = formatIter.next(); try { date = formatter.parse(value); } catch (ParseException ex) { LOG.debug(value + " was not parsable by pattern " + formatter.toPattern()); } } if (date == null) { throw new QueryProcessingException("Unable to parse date value \"" + value + "\""); } return date; } throw new QueryProcessingException("No conversion for type " + className); }