Example usage for java.lang Float parseFloat

List of usage examples for java.lang Float parseFloat

Introduction

In this page you can find the example usage for java.lang Float parseFloat.

Prototype

public static float parseFloat(String s) throws NumberFormatException 

Source Link

Document

Returns a new float initialized to the value represented by the specified String , as performed by the valueOf method of class Float .

Usage

From source file:edu.snu.leader.spatial.builder.AbstractAgentBuilder.java

/**
 * Loads the locations of the agents from a file
 *
 * @param filename//from w w w .  j  av  a2  s .co  m
 */
protected void loadLocations(String filename) {
    _LOG.trace("Entering loadLocations( filename )");

    _LOG.info("Loading locations from file [" + filename + "]");

    // Try to process the file
    try {
        // Create a reader
        BufferedReader reader = new BufferedReader(new FileReader(filename));

        // Process each line
        String line;
        while (null != (line = reader.readLine())) {
            // Is it a comment or empty?
            if ((0 == line.length()) || line.startsWith("#")) {
                // Yup
                continue;
            }

            // Split it
            String[] parts = line.split("\\s+");

            // Parse it
            float x = Float.parseFloat(parts[0]);
            float y = Float.parseFloat(parts[1]);

            // Build the location and add it to the list
            _locations.add(new Vector2D(x, y));
        }

        // Close the file
        reader.close();
    } catch (Exception e) {
        _LOG.error("Unable to read locations file [" + filename + "]", e);
        throw new RuntimeException("Unable to read locations file [" + filename + "]");
    }

    _LOG.trace("Leaving loadLocations( filename )");
}

From source file:org.yamj.core.service.plugin.TheTVDbScanner.java

@Override
public ScanResult scan(Series series) {
    String id = getSeriesId(series);

    if (StringUtils.isBlank(id)) {
        return ScanResult.MISSING_ID;
    }//from  w w  w . j a va  2  s.  c o  m

    com.omertron.thetvdbapi.model.Series tvdbSeries = tvdbApiWrapper.getSeries(id);

    series.setSourceDbId(SCANNER_ID, tvdbSeries.getId());
    series.setSourceDbId(ImdbScanner.SCANNER_ID, tvdbSeries.getImdbId());

    if (OverrideTools.checkOverwriteTitle(series, SCANNER_ID)) {
        series.setTitle(StringUtils.trim(tvdbSeries.getSeriesName()), SCANNER_ID);
    }

    if (OverrideTools.checkOverwritePlot(series, SCANNER_ID)) {
        series.setPlot(StringUtils.trim(tvdbSeries.getOverview()), SCANNER_ID);
    }

    if (OverrideTools.checkOverwriteOutline(series, SCANNER_ID)) {
        series.setOutline(StringUtils.trim(tvdbSeries.getOverview()), SCANNER_ID);
    }

    // Add the genres
    series.setGenreNames(new HashSet<String>(tvdbSeries.getGenres()), SCANNER_ID);

    // TODO more values
    if (StringUtils.isNumeric(tvdbSeries.getRating())) {
        try {
            series.addRating(SCANNER_ID, (int) (Float.parseFloat(tvdbSeries.getRating()) * 10));
        } catch (NumberFormatException nfe) {
            LOG.warn("Failed to convert TVDB rating '{}' to an integer, error: {}", tvdbSeries.getRating(),
                    nfe.getMessage());
        }
    }

    String faDate = tvdbSeries.getFirstAired();
    if (StringUtils.isNotBlank(faDate) && (faDate.length() >= 4)) {
        series.setStartYear(Integer.parseInt(faDate.substring(0, 4)));
    }

    // CAST & CREW
    Set<CreditDTO> actors = new LinkedHashSet<CreditDTO>();
    for (Actor actor : tvdbApiWrapper.getActors(id)) {
        actors.add(new CreditDTO(JobType.ACTOR, actor.getName(), actor.getRole()));
    }

    // SCAN SEASONS
    this.scanSeasons(series, tvdbSeries, actors);

    return ScanResult.OK;
}

From source file:com.ratebeer.android.api.command.GetStyleDetailsCommand.java

@Override
protected void parse(String html) throws JSONException, ApiException {

    // Parse the top beers table
    int tableStart = html.indexOf("<small><b>MORE BEER STYLES</b></small><br>");
    if (tableStart < 0) {
        throw new ApiException(ApiException.ExceptionType.CommandFailed,
                "The response HTML did not contain the unique top beers of the style table begin HTML string");
    }// w  w w . j a va 2s.  c  o  m

    int nameStart = html.indexOf("<h1>") + "<h1>".length();
    String name = HttpHelper.cleanHtml(html.substring(nameStart, html.indexOf("</h1>", nameStart)));

    int descriptionStart = html.indexOf("\">", nameStart) + "\">".length();
    String description = HttpHelper
            .cleanHtml(html.substring(descriptionStart, html.indexOf("</div>", descriptionStart)).trim());

    String servedInText = ".gif\">&nbsp;";
    List<String> servedIn = new ArrayList<String>();
    int servedInStart = html.indexOf(servedInText, descriptionStart);
    while (servedInStart >= 0) {
        servedIn.add(HttpHelper.cleanHtml(
                html.substring(servedInStart + servedInText.length(), html.indexOf("<br>", servedInStart)))
                .trim());
        servedInStart = html.indexOf(servedInText, servedInStart + 1);
    }

    String rowText = "<td class=\"lineNumber orange\">";
    int rowStart = html.indexOf(rowText, descriptionStart) + rowText.length();
    ArrayList<TopBeer> beers = new ArrayList<TopBeer>();

    while (rowStart > 0 + rowText.length()) {

        int orderNr = Integer.parseInt(html.substring(rowStart, html.indexOf(" ", rowStart)));

        int idStart1 = html.indexOf("<A HREF=\"/beer/", rowStart) + "<A HREF=\"/beer/".length();
        int idStart2 = html.indexOf("/", idStart1) + "/".length();
        int beerId = Integer.parseInt(html.substring(idStart2, html.indexOf("/", idStart2)));

        int beerStart = html.indexOf(">", idStart2) + ">".length();
        String beerName = HttpHelper.cleanHtml(html.substring(beerStart, html.indexOf("<", beerStart)));

        int scoreStart = html.indexOf("<b>", beerStart) + "<b>".length();
        float score = Float.parseFloat(html.substring(scoreStart, html.indexOf("<", scoreStart)));

        int countStart = html.indexOf("#999999\">", scoreStart) + "#999999\">".length();
        int count = Integer.parseInt(html.substring(countStart, html.indexOf("&", countStart)));

        beers.add(new TopBeer(orderNr, beerId, beerName, score, count, Integer.toString(styleId)));
        rowStart = html.indexOf(rowText, countStart) + rowText.length();
    }

    details = new StyleDetails(name, description, servedIn, beers);

}

From source file:org.micromanager.CRISP.CRISPFrame.java

private void updateValues() {
    try {/*from w w  w  .ja va  2  s. com*/
        String val;
        val = core_.getProperty(CRISP_, "LED Intensity");
        int intVal = Integer.parseInt(val);
        LEDSpinner_.getModel().setValue(intVal);

        val = core_.getProperty(CRISP_, "GainMultiplier");
        intVal = Integer.parseInt(val);
        GainSpinner_.getModel().setValue(intVal);

        val = core_.getProperty(CRISP_, "Number of Averages");
        intVal = Integer.parseInt(val);
        NrAvgsSpinner_.getModel().setValue(intVal);

        val = core_.getProperty(CRISP_, "Objective NA");
        float floatVal = Float.parseFloat(val);
        NASpinner_.getModel().setValue(floatVal);

    } catch (Exception ex) {
        ReportingUtils.showError("Error reading values from CRISP");
    }

}

From source file:com.hpe.application.automation.tools.octane.tests.junit.JUnitXmlIterator.java

private static long parseTime(String timeString) {
    String time = timeString.replace(",", "");
    try {/*from   ww w  .ja  va  2  s  .c o  m*/
        float seconds = Float.parseFloat(time);
        return (long) (seconds * 1000);
    } catch (NumberFormatException e) {
        try {
            return new DecimalFormat().parse(time).longValue();
        } catch (ParseException ex) {
            logger.debug("Unable to parse test duration: " + timeString);
        }
    }
    return 0;
}

From source file:com.netflix.dynomitemanager.sidecore.AbstractConfigSource.java

@Override
public float get(final String key, final float defaultValue) {
    final String value = get(key);
    if (value != null) {
        try {/*  w w  w. j  ava 2  s.c om*/
            return Float.parseFloat(value);
        } catch (Exception e) {
            // ignore and return default;
        }
    }
    return defaultValue;
}

From source file:egovframework.rte.fdl.string.EgovStringUtil.java

/**
 * @param str/*from  w  ww  .  ja  v a 2s .co  m*/
 * @return
 */
public static float string2float(String str) {

    if (isNull(str)) {
        return 0.0F;
    }

    return Float.parseFloat(str);
}

From source file:com.sami.chart.util.LineChartDemo1.java

private CategoryDataset createDataset(boolean a) {
    final String series1 = "First";
    final String series2 = "Second";
    final String series3 = "Third";

    GregorianCalendar gc = new GregorianCalendar();
    gc.set(2007, 9, 7);/*w w w. ja  v a2 s  . c  o m*/

    //       Date yesterday = new Date(System.currentTimeMillis() - 86400000);
    Date yesterday = gc.getTime();
    DateChecker checker = new DateChecker();
    checker.setDate(yesterday);

    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    try {
        TempReader reader = (TempReader) getClass().forName(getProperty("reader.Class")).newInstance();
        String line = "";
        while ((line = reader.readLine()) != null) {
            if (checker.isFromToday(line)) {
                String[] items = line.split(",");

                dataset.addValue(Float.parseFloat(items[1]), series1, items[0]);
                dataset.addValue(Float.parseFloat(items[2]), series2, items[0]);
                dataset.addValue(Float.parseFloat(items[3]), series3, items[0]);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return dataset;
}

From source file:org.loklak.api.vis.PieChartServlet.java

public JFreeChart getChart(JSONObject jsonData, boolean legendBit, boolean tooltipBit) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    Iterator iter = jsonData.keys();

    while (iter.hasNext()) {
        String keyData = (String) iter.next();
        Float value = Float.parseFloat(jsonData.getString(keyData));
        dataset.setValue(keyData, value);
    }// w ww. j a v  a  2  s  . co m

    boolean legend = legendBit;
    boolean tooltips = tooltipBit;
    boolean urls = false;

    JFreeChart chart = ChartFactory.createPieChart("Loklak Visualizes - PieChart", dataset, legend, tooltips,
            urls);

    chart.setBorderPaint(Color.BLACK);
    chart.setBorderStroke(new BasicStroke(5.0f));
    chart.setBorderVisible(true);

    return chart;
}

From source file:lumbermill.internal.transformers.Grok.java

/**
 * Float is not supported in java-grok, fixing this here.
 *///from  ww  w  .  ja  v a  2 s.c  o  m
private void fixUnsupportedGrokTypes(final JsonEvent event) {
    event.eachField((field1, value) -> {
        if (field1.endsWith(":float")) {
            String[] nameAndType = field1.split(":");
            event.remove(field1);
            event.put(nameAndType[0], Float.parseFloat(value));
        }
    });
}