List of usage examples for java.lang Float parseFloat
public static float parseFloat(String s) throws NumberFormatException
From source file:edu.cornell.kfs.sys.util.RestXmlUtil.java
protected static Object populateBusinessObject(DataObjectEntry doe, Map<?, ?> m) { Object bo = ObjectUtils.createNewObjectFromClass(doe.getDataObjectClass()); PersistenceStructureService persistenceStructureService = SpringContext .getBean(PersistenceStructureService.class); for (Object key : m.keySet()) { String propertyName = (String) key; Class<?> propertyType = ObjectUtils.getPropertyType(bo, propertyName, persistenceStructureService); if (propertyType != null) { try { Object propertyValue = m.get(key); if (propertyValue != null && !propertyValue.equals("null")) { String value = (String) propertyValue; if (TypeUtils.isIntegralClass(propertyType)) { propertyValue = Integer.parseInt(value); } else if (TypeUtils.isDecimalClass(propertyType)) { propertyValue = Float.parseFloat(value); } else if (TypeUtils.isTemporalClass(propertyType)) { propertyValue = KfsDateUtils.convertToSqlDate(DateUtils.parseDate(value, DATE_FORMAT)); } else if (TypeUtils.isBooleanClass(propertyType)) { propertyValue = Boolean.parseBoolean(value); }// ww w. j a v a2 s .c o m } else { propertyValue = null; } ObjectUtils.setObjectProperty(bo, propertyName, propertyValue); } catch (Exception ex) { LOG.error(ex); } } } return bo; }
From source file:com.jaeksoft.searchlib.crawler.FieldMap.java
public FieldMap(String multilineText, char fieldSeparator, char concatSeparator) throws IOException { StringReader sr = null;//from w w w . j av a 2 s .com BufferedReader br = null; this.concatSeparator = concatSeparator; try { sr = new StringReader(multilineText); br = new BufferedReader(sr); String line; while ((line = br.readLine()) != null) { String[] cols = StringUtils.split(line, fieldSeparator); if (cols == null || cols.length < 2) continue; String source = cols[0]; String target = cols[1]; String analyzer = cols.length > 2 ? cols[2] : null; Float boost = cols.length > 3 ? Float.parseFloat(cols[3]) : null; add(new SourceField(source, concatSeparator), new TargetField(target, analyzer, boost, null)); } } finally { IOUtils.close(br, sr); } }
From source file:ca.liquidlabs.android.speedtestvisualizer.model.SpeedTestRecord.java
/** * Constructs speedtest model object from parsed csv record. <br/> * TODO: Handle the exceptions in future, and show user friendly error * message to user./*from w ww . ja va2 s . c om*/ * * @param csvRecord */ public SpeedTestRecord(CSVRecord csvRecord) { try { this.date = csvRecord.get(KEY_DATE); // data connection type - should be one of expected values this.connectionType = ConnectionType.fromString(csvRecord.get(KEY_CONNTYPE)); // Lat, Lon is in float this.lat = Float.parseFloat(csvRecord.get(KEY_LAT)); this.lon = Float.parseFloat(csvRecord.get(KEY_LON)); // download and upload values are always in kbps this.download = Float.parseFloat(csvRecord.get(KEY_DOWNL)); this.upload = Float.parseFloat(csvRecord.get(KEY_UPL)); // latency is numeric - in milliseconds this.latency = Integer.parseInt(csvRecord.get(KEY_LATENCY)); this.serverName = csvRecord.get(KEY_SERVER); this.internalIp = csvRecord.get(KEY_IPINT); this.externalIp = csvRecord.get(KEY_IPEXT); } catch (NumberFormatException e) { // if for some reason unexpected value is passed, stop parsing throw new IllegalArgumentException("Unable to parse record: " + csvRecord.toString()); } catch (ArrayIndexOutOfBoundsException e) { // this might happen for some leftover lines when copy and pasting // data. throw new IllegalArgumentException("Invalid record : " + csvRecord.toString()); } }
From source file:com.linkedin.pinot.routing.TableConfigRoutingTableSelector.java
private float getLlcRatio(String realtimeTableName) { RealtimeTableConfig tableConfig = (RealtimeTableConfig) ZKMetadataProvider .getRealtimeTableConfig(_propertyStore, realtimeTableName); if (tableConfig == null) { LOGGER.warn("Failed to fetch table config for table {}", realtimeTableName); return 0.0f; }/*www . j ava 2s.c o m*/ Map<String, String> customConfigs = tableConfig.getCustomConfigs().getCustomConfigs(); if (customConfigs.containsKey(LLC_ROUTING_PERCENTAGE_CONFIG_KEY)) { String routingPercentageString = customConfigs.get(LLC_ROUTING_PERCENTAGE_CONFIG_KEY); float routingPercentage; try { routingPercentage = Float.parseFloat(routingPercentageString); } catch (NumberFormatException e) { LOGGER.warn("Couldn't parse {} as a valid LLC routing percentage, should be a number between 0-100", e); return 0.0f; } if (routingPercentage < 0.0f || 100.0f < routingPercentage) { routingPercentage = Math.min(Math.max(routingPercentage, 0.0f), 100.0f); LOGGER.warn("LLC routing percentage ({}) is outside of [0;100], percentage was clamped to {}.", routingPercentageString, routingPercentage); } return routingPercentage; } return 0.0f; }
From source file:account.management.controller.BankAccountController.java
@FXML private void onSaveButtonClick(ActionEvent event) { String name = this.nalme.getText(); String note = this.note.getText(); String balance = this.balance.getText(); try {//www . j a v a 2 s . c o m float bal = 0; if (dr_cr.getSelectionModel().getSelectedItem().equals("Cr")) { bal = Float.parseFloat(balance); bal *= -1f; } else { bal = Float.parseFloat(balance); } System.out.println("start"); Unirest.get(MetaData.baseUrl + "add/account").queryString("name", name).queryString("parent", "22") .queryString("account_type", "1").queryString("description", note) .queryString("opening_balance", String.valueOf(bal)) .queryString("location", location.getSelectionModel().getSelectedItem().getId()).asJson(); Msg.showInformation("Success"); } catch (Exception ex) { Msg.showError(""); } }
From source file:com.ratebeer.android.api.command.GetPlacesAroundCommand.java
@Override protected void parse(JSONArray json) throws JSONException { places = new ArrayList<Place>(); for (int i = 0; i < json.length(); i++) { JSONObject result = json.getJSONObject(i); String avgRating = result.getString("AvgRating"); places.add(new Place(result.getInt("PlaceID"), HttpHelper.cleanHtml(result.getString("PlaceName")), result.getInt("PlaceType"), HttpHelper.cleanHtml(result.getString("Address")), HttpHelper.cleanHtml(result.getString("City")), result.getString("StateID"), result.getInt("CountryID"), HttpHelper.cleanHtml(result.getString("PostalCode")), HttpHelper.cleanHtml(result.getString("PhoneNumber")), avgRating.equals("null") ? -1 : (int) Float.parseFloat(avgRating), -1, HttpHelper.cleanHtml(result.getString("PhoneAC")), result.getDouble("Latitude"), result.getDouble("Longitude"), result.getDouble("Distance"))); }/* ww w .ja va 2 s. c om*/ }
From source file:com.bookstore.qr_codescan.danmakuFlame.master.flame.danmaku.danmaku.parser.android.AcFunDanmakuParser.java
private Danmakus _parse(JSONObject jsonObject, Danmakus danmakus) { if (danmakus == null) { danmakus = new Danmakus(); }//from ww w .j a v a 2 s. c o m if (jsonObject == null || jsonObject.length() == 0) { return danmakus; } for (int i = 0; i < jsonObject.length(); i++) { try { JSONObject obj = jsonObject; String c = obj.getString("c"); String[] values = c.split(","); if (values.length > 0) { int type = Integer.parseInt(values[2]); // if (type == 7) // FIXME : hard code // TODO : parse advance danmaku json continue; long time = (long) (Float.parseFloat(values[0]) * 1000); // int color = Integer.parseInt(values[1]) | 0xFF000000; // float textSize = Float.parseFloat(values[3]); // ? BaseDanmaku item = mContext.mDanmakuFactory.createDanmaku(type, mContext); if (item != null) { item.time = time; item.textSize = textSize * (mDispDensity - 0.6f); item.textColor = color; item.textShadowColor = color <= Color.BLACK ? Color.WHITE : Color.BLACK; DanmakuUtils.fillText(item, obj.optString("m", "....")); item.index = i; item.setTimer(mTimer); danmakus.addItem(item); } } } catch (JSONException e) { } catch (NumberFormatException e) { } } return danmakus; }
From source file:edu.snu.leader.hidden.builder.ForcedPersonalityDistributionIndividualBuilder.java
/** * Initializes the builder/* w w w . j a va 2 s . c o m*/ * * @param simState The simulation's state * @see edu.snu.leader.hidden.builder.AbstractIndividualBuilder#initialize(edu.snu.leader.hidden.SimulationState) */ @Override public void initialize(SimulationState simState) { _LOG.trace("Entering initialize( simState )"); // Call the superclass implementation super.initialize(simState); // Get the properties Properties props = simState.getProps(); // Get the min personality String minPersonalityStr = props.getProperty(_MIN_PERSONALITY_KEY); Validate.notEmpty(minPersonalityStr, "Minimum personality value (key=" + _MIN_PERSONALITY_KEY + ") may not be empty"); _minPersonality = Float.parseFloat(minPersonalityStr); _LOG.info("Using _minPersonality=[" + _minPersonality + "]"); // Get the max personality String maxPersonalityStr = props.getProperty(_MAX_PERSONALITY_KEY); Validate.notEmpty(maxPersonalityStr, "Maximum personality value (key=" + _MAX_PERSONALITY_KEY + ") may not be empty"); _maxPersonality = Float.parseFloat(maxPersonalityStr); _LOG.info("Using _maxPersonality=[" + _maxPersonality + "]"); // Get the max personality individual count String maxPersonalityIndCountStr = props.getProperty(_MAX_PERSONALITY_IND_COUNT_KEY); Validate.notEmpty(maxPersonalityStr, "Maximum personality individual count value (key=" + _MAX_PERSONALITY_IND_COUNT_KEY + ") may not be empty"); _maxPersonalityIndCount = Integer.parseInt(maxPersonalityIndCountStr); _LOG.info("Using _maxPersonalityIndCount=[" + _maxPersonalityIndCount + "]"); _LOG.trace("Leaving initialize( simState )"); }
From source file:net.vivekiyer.GAL.ActiveSyncManager.java
private float getActiveSyncVersionFloat() { if (mActiveSyncVersionFloat == 0.0F) mActiveSyncVersionFloat = Float.parseFloat(mActiveSyncVersion); return mActiveSyncVersionFloat; }
From source file:com.tlabs.eve.api.parser.BaseRule.java
private static final boolean setPropertyImpl(final Object bean, final String property, final String value) { Method stringMethod = getSetMethod(bean, property, String.class); if (null != stringMethod) { return invokeMethod(bean, stringMethod, value); }//w w w. j av a2 s . c o m Method booleanMethod = getSetMethod(bean, property, boolean.class); if (null == booleanMethod) { booleanMethod = getSetMethod(bean, property, Boolean.class); } if (null != booleanMethod) { return invokeMethod(bean, booleanMethod, "1".equals(value)); } Method longMethod = getSetMethod(bean, property, long.class); if (null == longMethod) { longMethod = getSetMethod(bean, property, Long.class); } if (null != longMethod) { long longValue = 0l; try { longValue = Long.parseLong(value);//is it really a long value? } catch (NumberFormatException e) { longValue = EveAPI.parseDateTime(value); } return invokeMethod(bean, longMethod, longValue); } Method doubleMethod = getSetMethod(bean, property, double.class); if (null == doubleMethod) { doubleMethod = getSetMethod(bean, property, Double.class); } if (null != doubleMethod) { return invokeMethod(bean, doubleMethod, Double.parseDouble(value)); } Method floatMethod = getSetMethod(bean, property, float.class); if (null == floatMethod) { floatMethod = getSetMethod(bean, property, Float.class); } if (null != floatMethod) { return invokeMethod(bean, floatMethod, Float.parseFloat(value)); } Method integerMethod = getSetMethod(bean, property, int.class); if (null == integerMethod) { integerMethod = getSetMethod(bean, property, Integer.class); } if (null != integerMethod) { return invokeMethod(bean, integerMethod, Integer.parseInt(value)); } if (LOG.isDebugEnabled()) { LOG.debug("No suitable setter: " + property + "@" + bean.getClass().getSimpleName()); } return false; }