List of usage examples for java.lang Float parseFloat
public static float parseFloat(String s) throws NumberFormatException
From source file:com.qagen.osfe.core.utils.BeanPopulator.java
public static Object getValueAsType(String name, String value, String type, String format) { if ((value != null) && (value.trim().length() == 0)) { return null; }// w w w .ja v a 2 s . co m if (type.equals(AttributeType.String.name())) { return value; } if (type.equals(AttributeType.Integer.name())) { return Integer.parseInt(value); } if (type.equals(AttributeType.Float.name())) { return Float.parseFloat(value); } if (type.equals(AttributeType.Double.name())) { return Double.parseDouble(value); } if (type.equals(AttributeType.Boolean.name())) { return Boolean.parseBoolean(value); } if (type.equals(AttributeType.Date.name())) { return getDate(name, value, format); } if (type.equals(AttributeType.Time.name())) { return getTime(name, value, format); } if (type.equals(AttributeType.Long.name())) { return Long.parseLong(value); } if (type.equals(AttributeType.Timestamp.name())) { return getTimestamp(name, value, format); } if (type.equals(AttributeType.Object.name())) { return Timestamp.valueOf(value); } final String message = "The value type, " + type + " is not a defined type. " + "You may need to extend the RowParser class and override the method, getValueAsType()."; throw new FeedErrorException(message); }
From source file:gov.nih.nci.caintegrator.application.analysis.FloatParameterValue.java
/** * {@inheritDoc}//from w w w. j a v a 2 s. c o m */ @Override public void setValueFromString(String stringValue) { if (StringUtils.isBlank(stringValue)) { setValue(null); } else { setValue(Float.parseFloat(stringValue)); } }
From source file:Main.java
/** * Adds values to a SharedPreferences Editor object. Key,value * pairs are expected to come in the values array one after another * such as [key1, value1, key2, value2], etc. This is a side effect * of the Ruby to Java communication through ADB. * /*from w w w .j ava 2 s . c o m*/ * @param editor Editor to which add the values to. * @param values Array of key/value pairs. * * @throws IllegalArgumentException if missing editor or values. */ public static void setPreferences(Editor editor, String[] values) { if (editor == null) { throw new IllegalArgumentException(MISSING_EDITOR); } if (values == null) { throw new IllegalArgumentException(MISSING_VALUES); } // we expect key/value pairs passed one after another such as: // [key1 value1 key2 value2], etc // So we go through them with a 2 step loop int totalParsedArgs = values.length; for (int i = 0; i < totalParsedArgs; i += 2) { if (values[i] == null) { break; } String key = values[i]; String value = values[i + 1]; try { int x = Integer.parseInt(value); editor.putInt(key, x); } catch (NumberFormatException e) { try { float y = Float.parseFloat(value); editor.putFloat(key, y); } catch (NumberFormatException e1) { if (value.equals("true") || value.equals("false")) { editor.putBoolean(key, Boolean.parseBoolean(value)); } else { editor.putString(key, value); } } } } }
From source file:logica.LGraficapeso.java
public static void logicaBtnGraficar(JRadioButton jRLinea) { ChartPanel panel;/*from www . ja v a 2 s.co m*/ JFreeChart chart = null; if (jRLinea.isSelected()) { // ejecuto linea XYSplineRenderer graficoLinea = new XYSplineRenderer(); XYSeriesCollection dataset = new XYSeriesCollection(); ValueAxis x = new NumberAxis(); ValueAxis y = new NumberAxis(); XYSeries serie = new XYSeries("Datos"); XYPlot plot; graficoLinea.setSeriesPaint(0, Color.YELLOW); VGraficaPeso.getPanelLinea().removeAll(); for (int i = 0; i < VGraficaPeso.getjTable1().getRowCount(); i++) { float valor1 = Float.parseFloat(String.valueOf(VGraficaPeso.getjTable1().getValueAt(i, 0))); float valor2 = Float.parseFloat(String.valueOf(VGraficaPeso.getjTable1().getValueAt(i, 1))); System.out.println("valores " + valor1 + " " + valor2); serie.add(valor1, valor2); } dataset.addSeries(serie); x.setLabel("MES"); y.setLabel("peso"); plot = new XYPlot(dataset, x, y, graficoLinea); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setRange(10, 15); chart = new JFreeChart(plot); chart.setTitle("grafico"); panel = new ChartPanel(chart); panel.setBounds(5, 10, 410, 350); VGraficaPeso.getPanelLinea().add(panel); VGraficaPeso.getPanelLinea().repaint(); } }
From source file:logica.LGraficaAltura.java
public static void logicaBtnGraficar(JRadioButton jRLinea) { ChartPanel panel;//from ww w . j av a 2s .co m JFreeChart chart = null; if (jRLinea.isSelected()) { // ejecuto linea XYSplineRenderer graficoLinea = new XYSplineRenderer(); XYSeriesCollection dataset = new XYSeriesCollection(); ValueAxis x = new NumberAxis(); ValueAxis y = new NumberAxis(); XYSeries serie = new XYSeries("Datos"); XYPlot plot; graficoLinea.setSeriesPaint(0, Color.YELLOW); VGraficaAltura.getPanelLinea().removeAll(); for (int i = 0; i < VGraficaAltura.getjTable1().getRowCount(); i++) { float valor1 = Float.parseFloat(String.valueOf(VGraficaAltura.getjTable1().getValueAt(i, 0))); float valor2 = Float.parseFloat(String.valueOf(VGraficaAltura.getjTable1().getValueAt(i, 1))); System.out.println("valores " + valor1 + " " + valor2); serie.add(valor1, valor2); } dataset.addSeries(serie); x.setLabel("MES"); y.setLabel("ALTURA"); plot = new XYPlot(dataset, x, y, graficoLinea); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setRange(15, 30); chart = new JFreeChart(plot); chart.setTitle("grafico"); panel = new ChartPanel(chart); panel.setBounds(5, 10, 410, 350); VGraficaAltura.getPanelLinea().add(panel); VGraficaAltura.getPanelLinea().repaint(); } }
From source file:Main.java
private static void setterValue(PropertyDescriptor property, Object mapValue, Object object) throws InvocationTargetException, IllegalAccessException, ParseException { Method setter = property.getWriteMethod(); if (mapValue == null) { setter.invoke(object, mapValue); return;/*from w w w. j av a2 s . c o m*/ } Class propertyType = property.getPropertyType(); String type = propertyType.getName(); String value = mapValue.toString(); if (type.equals("java.lang.String")) { setter.invoke(object, value); } else if (type.equals("java.lang.Integer")) { setter.invoke(object, Integer.parseInt(value)); } else if (type.equals("java.lang.Long")) { setter.invoke(object, Long.parseLong(value)); } else if (type.equals("java.math.BigDecimal")) { setter.invoke(object, BigDecimal.valueOf(Double.parseDouble(value))); } else if (type.equals("java.math.BigInteger")) { setter.invoke(object, BigInteger.valueOf(Long.parseLong(value))); } else if (type.equals("java.util.Date")) { setter.invoke(object, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(value)); } else if (type.equals("java.lang.Boolean")) { setter.invoke(object, Boolean.valueOf(value)); } else if (type.equals("java.lang.Float")) { setter.invoke(object, Float.parseFloat(value)); } else if (type.equals("java.lang.Double")) { setter.invoke(object, Double.parseDouble(value)); } else if (type.equals("java.lang.byte[]")) { setter.invoke(object, value.getBytes()); } else { setter.invoke(object, value); } }
From source file:indexer.DocVector.java
static public void initVectorRange(Properties prop) { numIntervals = Integer.parseInt(prop.getProperty("vec.numintervals")); MINVAL = Float.parseFloat(prop.getProperty("vec.min", "-1")); MAXVAL = Float.parseFloat(prop.getProperty("vec.max", "1")); }
From source file:AIR.Common.Utilities.JavaPrimitiveUtils.java
public static boolean floatTryParse(String value, _Ref<Float> ref) { try {// w w w. java 2 s . c om ref.set(Float.parseFloat(value)); return true; } catch (NumberFormatException exp) { return false; } }
From source file:com.hippo.ehviewer.client.parser.GalleryApiParser.java
public static void parse(String body, List<GalleryInfo> galleryInfoList) throws JSONException { JSONObject jo = new JSONObject(body); JSONArray ja = jo.getJSONArray("gmetadata"); for (int i = 0, length = ja.length(); i < length; i++) { JSONObject g = ja.getJSONObject(i); long gid = g.getLong("gid"); GalleryInfo gi = getGalleryInfoByGid(galleryInfoList, gid); if (gi == null) { continue; }/*from w w w . ja va2 s . c o m*/ gi.title = ParserUtils.trim(g.getString("title")); gi.titleJpn = ParserUtils.trim(g.getString("title_jpn")); gi.category = EhUtils.getCategory(g.getString("category")); gi.thumb = EhUtils.handleThumbUrlResolution(g.getString("thumb")); gi.uploader = g.getString("uploader"); gi.posted = ParserUtils.formatDate(ParserUtils.parseLong(g.getString("posted")) * 1000); gi.rating = Float.parseFloat(g.getString("rating")); // tags JSONArray tagJa = g.getJSONArray("tags"); int tagLength = tagJa.length(); String[] tags = new String[tagLength]; for (int j = 0; j < tagLength; j++) { tags[j] = tagJa.getString(j); } gi.simpleTags = tags; } }
From source file:blue.noteProcessor.TempoMapper.java
public static TempoMapper createTempoMapper(String timeWarpString) { TempoMapper tm = new TempoMapper(); StringTokenizer st = new StringTokenizer(timeWarpString); String time, tempo;// w w w. jav a 2 s .c om BeatTempoPair temp; if (st.countTokens() % 2 != 0) { // not an even amount of tokens! return null; } tm.timeMap = new BeatTempoPair[st.countTokens() / 2]; int index = 0; BeatTempoPair[] tMap = tm.timeMap; while (st.hasMoreTokens()) { try { time = st.nextToken(); tempo = st.nextToken(); temp = new BeatTempoPair(); temp.beat = Float.parseFloat(time); temp.tempo = Float.parseFloat(tempo); if (temp.beat < 0.0f || temp.tempo <= 0.0f) { return null; } tMap[index] = temp; if (index > 0) { float factor1 = 60.0f / tMap[index - 1].tempo; float factor2 = 60.0f / tMap[index].tempo; float deltaBeat = tMap[index].beat - tMap[index - 1].beat; float acceleration = 0.0f; if (deltaBeat >= 0.0f) { acceleration = (factor2 - factor1) / (tMap[index].beat - tMap[index - 1].beat); } if (tMap[index].beat == tMap[index - 1].beat) { tMap[index].accumulatedTime = tMap[index - 1].accumulatedTime; } else { tMap[index].accumulatedTime = tMap[index - 1].accumulatedTime + getAreaUnderCurve(factor1, deltaBeat, acceleration); } } index++; } catch (Exception e) { // if there's any errors whatsoever, return null // and let the calling procedure handle it return null; } } return tm; }