List of usage examples for java.lang Float parseFloat
public static float parseFloat(String s) throws NumberFormatException
From source file:za.ac.cput.project.hospitalmanagement.api.MedicineApi.java
@RequestMapping(value = "/updateMedicine", method = RequestMethod.GET) public String updateMedicine(HttpServletRequest request) { String medicineName = request.getParameter("medicineName"); String medicineType = request.getParameter("medicineType"); String quantity = request.getParameter("quantity"); float quantityValue = Float.parseFloat(quantity); String treatmentIDParam = request.getParameter("treatmentID"); Long treatmentID = Long.parseLong(treatmentIDParam); String medicineID = request.getParameter("medicineID"); Long id = Long.parseLong(medicineID); return service.updateMedicine(medicineName, medicineType, quantityValue, treatmentID, id); }
From source file:com.madrobot.di.Converter.java
public static Object convertTo(final JSONObject jsonObject, final String fieldName, final Class<?> clz, final Field field) { Object value = null;/*from www.j a v a 2 s . c o m*/ if (clzTypeKeyMap.containsKey(clz)) { try { final int code = clzTypeKeyMap.get(clz); switch (code) { case TYPE_STRING: value = jsonObject.optString(fieldName); break; case TYPE_SHORT: value = Short.parseShort(jsonObject.optString(fieldName, "0")); break; case TYPE_INT: value = jsonObject.optInt(fieldName); break; case TYPE_LONG: value = jsonObject.optLong(fieldName); break; case TYPE_CHAR: String chatValue = jsonObject.optString(fieldName); if (chatValue.length() > 0) { value = chatValue.charAt(0); } else { value = '\0'; } break; case TYPE_FLOAT: value = Float.parseFloat(jsonObject.optString(fieldName, "0.0f")); break; case TYPE_DOUBLE: value = jsonObject.optDouble(fieldName); break; case TYPE_BOOLEAN: value = jsonObject.optString(fieldName); if (field.isAnnotationPresent(BooleanFormat.class)) { BooleanFormat formatAnnotation = field.getAnnotation(BooleanFormat.class); String trueFormat = formatAnnotation.trueFormat(); String falseFormat = formatAnnotation.falseFormat(); if (trueFormat.equals(value)) { value = true; } else if (falseFormat.equals(value)) { value = false; } else { Log.e(JSONDeserializer.TAG, "Expecting " + trueFormat + " / " + falseFormat + " but its " + value); } } else { value = Boolean.parseBoolean((String) value); } break; case TYPE_DATE: value = DateFormat.getDateInstance().parse(jsonObject.optString(fieldName)); break; } } catch (NumberFormatException e) { Log.e(JSONDeserializer.TAG, e.getMessage()); } catch (ParseException e) { Log.e(JSONDeserializer.TAG, e.getMessage()); } } return value; }
From source file:com.gargoylesoftware.htmlunit.javascript.host.canvas.rendering.AwtRenderingBackend.java
/** * {@inheritDoc}/*from www. j a v a 2s . co m*/ */ public void setFillStyle(final String fillStyle) { final String tmpFillStyle = fillStyle.replaceAll("\\s", ""); Color color = null; if (tmpFillStyle.startsWith("rgb(")) { final String[] colors = tmpFillStyle.substring(4, tmpFillStyle.length() - 1).split(","); color = new Color(Integer.parseInt(colors[0]), Integer.parseInt(colors[1]), Integer.parseInt(colors[2])); } else if (tmpFillStyle.startsWith("rgba(")) { final String[] colors = tmpFillStyle.substring(5, tmpFillStyle.length() - 1).split(","); color = new Color(Integer.parseInt(colors[0]), Integer.parseInt(colors[1]), Integer.parseInt(colors[2]), (int) (Float.parseFloat(colors[3]) * 255)); } else if (tmpFillStyle.startsWith("#")) { color = Color.decode(tmpFillStyle); } else { try { final Field f = Color.class.getField(tmpFillStyle); color = (Color) f.get(null); } catch (final Exception e) { LOG.info("Can not find color '" + tmpFillStyle + '\''); color = Color.black; } } graphics2D_.setColor(color); }
From source file:edu.snu.leader.spatial.calculator.CompactSigmoidSueurDecisionProbabilityCalculator.java
/** * Initializes the calculator/*from w ww . j a v a2 s . c o m*/ * * @param simState The simulation's state * @see edu.snu.leader.spatial.DecisionProbabilityCalculator#initialize(edu.snu.leader.spatial.SimulationState) */ @Override public void initialize(SimulationState simState) { _LOG.trace("Entering initialize( simState )"); // Call superclass implementation super.initialize(simState); // Get the properties Properties props = simState.getProperties(); // Get the sigmoid slope value String sigmoidSlopeValueStr = props.getProperty(_SIGMOID_SLOPE_VALUE_KEY); Validate.notEmpty(sigmoidSlopeValueStr, "Sigmoid slope value (Key =" + _SIGMOID_SLOPE_VALUE_KEY + ") may not be empty "); _sigmoidSlopeValue = Float.parseFloat(sigmoidSlopeValueStr); _LOG.info("Using _sigmoidSlopeValue = [" + _sigmoidSlopeValue + "]"); _LOG.trace("Leaving initialize( simState )"); }
From source file:edu.snu.leader.hidden.builder.SpecificPersonalityIndividualBuilder.java
/** * Initializes the builder/* ww w. j av a 2 s. com*/ * * @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 specific personality String specificPersonalityStr = props.getProperty(_SPECIFIC_PERSONALITY); Validate.notEmpty(specificPersonalityStr, "Specific personality value (key=" + _SPECIFIC_PERSONALITY + ") may not be empty"); _personality = Float.parseFloat(specificPersonalityStr); _LOG.info("Using _personality=[" + _personality + "]"); _LOG.trace("Leaving initialize( simState )"); }
From source file:com.ratebeer.android.api.command.GetBeerDetailsCommand.java
@Override protected void parse(JSONArray json) throws JSONException { details = null;//from w w w . j av a 2s. c om if (json.length() > 0) { JSONObject result = json.getJSONObject(0); String overall = result.getString("OverallPctl"); String style = result.getString("StylePctl"); details = new BeerDetails(result.getInt("BeerID"), HttpHelper.cleanHtml(result.getString("BeerName")), result.getInt("BrewerID"), HttpHelper.cleanHtml(result.getString("BrewerName")), HttpHelper.cleanHtml(result.getString("BeerStyleName")), (float) result.getDouble("Alcohol"), overall.equals("null") ? GetBeerDetailsCommand.NO_SCORE_YET : Float.parseFloat(overall), style.equals("null") ? GetBeerDetailsCommand.NO_SCORE_YET : Float.parseFloat(style), HttpHelper.cleanHtml(result.getString("Description"))); } }
From source file:edu.snu.leader.hidden.personality.AbstractPersonalityDecayCalculator.java
/** * Initialize the decay calculator/* w w w . j a v a2 s . com*/ * * @param simState The simulation's state */ @Override public void initialize(SimulationState simState) { _LOG.trace("Entering initialize( simState )"); // Store the simulation state _simState = simState; // Get the properties Properties props = simState.getProps(); // Get the decay time String decayTimeStr = props.getProperty(_DECAY_TIME_KEY); Validate.notEmpty(decayTimeStr, "Decay time (key=" + _DECAY_TIME_KEY + ") may not be empty"); _decayTime = Float.parseFloat(decayTimeStr); _LOG.info("Using _decayTime=[" + _decayTime + "]"); // Get the difference threshold String differenceThresholdStr = props.getProperty(_DIFFERENCE_THRESHOLD_KEY); Validate.notEmpty(differenceThresholdStr, "Difference threshold (key=" + _DIFFERENCE_THRESHOLD_KEY + ") may not be empty"); _differenceThreshold = Float.parseFloat(differenceThresholdStr); _LOG.info("Using _differenceThreshold=[" + _differenceThreshold + "]"); _LOG.trace("Leaving initialize( simState )"); }
From source file:edu.uci.ics.fuzzyjoin.hadoop.recordpairs.MapBroadcastSelfJoin.java
private void addJoinIndex(Path path) { try {/*from ww w . jav a 2 s .co m*/ BufferedReader fis = new BufferedReader(new FileReader(path.toString())); String line = null; while ((line = fis.readLine()) != null) { String[] splits = line.split(" "); int rid1 = Integer.parseInt(splits[0]); int rid2 = Integer.parseInt(splits[1]); float similarity = Float.parseFloat(splits[2]); if (rid1 < rid2) { int r = rid1; rid1 = rid2; rid2 = r; } RIDPairSimilarity ridSimilarity = new RIDPairSimilarity(rid1, rid2, similarity); // Use ArrayList to lower the memory requirements. This causes // duplicated to be outputed. The duplicates need to be // eliminated in the Reduce. ArrayList<RIDPairSimilarity> ridSimilarities = joinIndex.get(rid1); if (ridSimilarities != null) { ridSimilarities.add(ridSimilarity); } else { ridSimilarities = new ArrayList<RIDPairSimilarity>(); ridSimilarities.add(ridSimilarity); joinIndex.put(rid1, ridSimilarities); } ridSimilarities = joinIndex.get(rid2); if (ridSimilarities != null) { ridSimilarities.add(ridSimilarity); } else { ridSimilarities = new ArrayList<RIDPairSimilarity>(); ridSimilarities.add(ridSimilarity); joinIndex.put(rid2, ridSimilarities); } } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:account.management.controller.ViewProjectController.java
/** * Initializes the controller class./*from w w w . ja v a2 s .co m*/ */ @Override public void initialize(URL url, ResourceBundle rb) { this.name.setCellValueFactory(new PropertyValueFactory("name")); this.investment.setCellValueFactory(new PropertyValueFactory("investment")); this.party.setCellValueFactory(new PropertyValueFactory("party")); this.start_date.setCellValueFactory(new PropertyValueFactory("formattedStartDate")); this.operation_date.setCellValueFactory(new PropertyValueFactory("formattedOperationDate")); this.dimilish_date.setCellValueFactory(new PropertyValueFactory("formattedDimilishDate")); new Thread(() -> { try { HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "get/project/all").asJson(); JSONArray array = res.getBody().getArray(); for (int i = 0; i < array.length(); i++) { JSONObject obj = array.getJSONObject(i); String id = obj.get("id").toString(); String name = obj.getString("name"); String investment = String.valueOf(Float.parseFloat(obj.getString("investment"))); String related_party = obj.getString("related_party"); String starting_date = obj.getString("starting_date"); String operation_date = obj.getString("operation_date"); String dimilish_date = obj.getString("dimilish_date"); tableView.getItems().add(new Project(id, name, investment, related_party, starting_date, operation_date, dimilish_date)); } } catch (UnirestException ex) { Logger.getLogger(ViewProjectController.class.getName()).log(Level.SEVERE, null, ex); } }).start(); }
From source file:de.forsthaus.backend.util.IpLocator.java
private static float stringToFloat(String fString) { try {// w ww . j a va2 s . co m return Float.parseFloat(fString); } catch (final NumberFormatException e) { return -1; } }