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.msu.cme.rdp.seqmatch.cli.SeqmatchCheckRevSeq.java

public static void main(String[] args) throws Exception {

    String trainingFile = null;//from   w w w.  j av a2  s.  com
    String queryFile = null;
    String outputFile = null;
    PrintWriter revOutputWriter = new PrintWriter(System.out);
    PrintStream correctedQueryOut = System.out;
    String traineeDesc = null;
    int numOfResults = 20;
    boolean checkReverse = false;

    float diffScoreCutoff = CheckReverseSeq.DIFF_SCORE_CUTOFF;
    String format = "txt"; // default

    try {
        CommandLine line = new PosixParser().parse(options, args);

        if (line.hasOption("c")) {
            checkReverse = true;
        }

        if (line.hasOption("t")) {
            trainingFile = line.getOptionValue("t");
        } else {
            throw new Exception("training file must be specified");
        }
        if (line.hasOption("q")) {
            queryFile = line.getOptionValue("q");
        } else {
            throw new Exception("query file must be specified");
        }
        if (line.hasOption("o")) {
            outputFile = line.getOptionValue("o");
        } else {
            throw new Exception("output file must be specified");
        }
        if (line.hasOption("r")) {
            revOutputWriter = new PrintWriter(line.getOptionValue("r"));
        }
        if (line.hasOption("s")) {
            correctedQueryOut = new PrintStream(line.getOptionValue("s"));
        }
        if (line.hasOption("d")) {
            diffScoreCutoff = Float.parseFloat(line.getOptionValue("d"));
        }
        if (line.hasOption("h")) {
            traineeDesc = line.getOptionValue("h");
        }
        if (line.hasOption("n")) {
            numOfResults = Integer.parseInt(line.getOptionValue("n"));
        }
        if (line.hasOption("f")) {
            format = line.getOptionValue("f");
            if (!format.equals("tab") && !format.equals("dbformat") && !format.equals("xml")) {
                throw new IllegalArgumentException("Only dbformat, tab or xml format available");
            }
        }

    } catch (Exception e) {
        System.out.println("Command Error: " + e.getMessage());
        new HelpFormatter().printHelp(120, "SeqmatchCheckRevSeq", "", options, "", true);
        return;
    }

    SeqmatchCheckRevSeq theObj = new SeqmatchCheckRevSeq();

    if (!checkReverse) {
        theObj.doUserLibMatch(queryFile, trainingFile, outputFile, numOfResults, format, traineeDesc);
    } else {
        theObj.checkRevSeq(queryFile, trainingFile, outputFile, revOutputWriter, correctedQueryOut,
                diffScoreCutoff, format, traineeDesc);
    }
}

From source file:blue.Marker.java

public static Marker loadFromXML(Element data) {
    Marker m = new Marker();

    m.setTime(Float.parseFloat(data.getAttributeValue("time")));
    m.setName(data.getAttributeValue("name"));

    return m;/*from  w  ww .  j  av a  2  s  .c o m*/
}

From source file:uk.ac.ebi.intact.editor.config.property.FloatPropertyConverter.java

@Override
public Float convertFromString(String str) {
    if (str == null)
        return null;

    return Float.parseFloat(str);
}

From source file:com.canoo.webtest.util.ConversionUtil.java

/**
 * Convert a string value to a float. If the value is null, return the specified default value.
 *
 * @return parsed value. If value is null return default value.
 * @throws NumberFormatException//from  w w w  .  j  av  a 2  s .c  om
 */
public static float convertToFloat(String value, float defaultValue) {
    if (value != null) {
        return Float.parseFloat(value);
    }
    return defaultValue;
}

From source file:gov.nih.nci.caarray.application.util.Utils.java

/**
 * @param value the value to test./*w w  w  .j  av a  2  s.  c o  m*/
 * @return true is the value can be parsed as an Float.
 */
public static boolean isFloat(String value) {
    try {
        Float.parseFloat(value);
        return true;
    } catch (NumberFormatException e) {
        return false;
    }
}

From source file:Main.java

/**
 * For some reason, can't find this utility method in the java framework.
 * //from  w  ww .j  a v  a2  s.  com
 * @param sDateTime
 *            an xsd:dateTime string
 * @return an equivalent java.util.Date
 * @throws ParseException
 */
public static Date parseXsdDateTime(String sDateTime) throws ParseException {
    final DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");

    int iDotPosition = NORMAL_IDOT_POSITION;
    if (sDateTime.charAt(0) == '-') {
        iDotPosition = IDOT_POSITION_IFNEG;
    }
    Date result;
    if (sDateTime.length() <= iDotPosition) {
        return format.parse(sDateTime + "Z");
    }

    String millis = null;
    char c = sDateTime.charAt(iDotPosition);
    if (c == '.') {
        // if datetime has milliseconds, separate them
        int eoms = iDotPosition + 1;
        while (Character.isDigit(sDateTime.charAt(eoms))) {
            eoms += 1;
        }
        millis = sDateTime.substring(iDotPosition, eoms);
        sDateTime = sDateTime.substring(0, iDotPosition) + sDateTime.substring(eoms);
        c = sDateTime.charAt(iDotPosition);
    }
    if (c == '+' || c == '-') {
        format.setTimeZone(TimeZone.getTimeZone("GMT" + sDateTime.substring(iDotPosition)));
        sDateTime = sDateTime.substring(0, iDotPosition) + "Z";
    } else if (c != 'Z') {
        throw new ParseException("Illegal timezone specification.", iDotPosition);
    }

    result = format.parse(sDateTime);
    if (millis != null) {
        result.setTime(result.getTime() + Math.round(Float.parseFloat(millis) * ONE_SEC_IN_MILLISECS));
    }

    result = offsetDateFromGMT(result);
    return result;
}

From source file:it.polimi.proximityapi.jsonLogic.POIJsonParser.java

public static ArrayList<POI> parsePOIFile(String jsonString) {
    ArrayList<POI> poiList = new ArrayList<>();
    JSONParser parser = new JSONParser();

    JSONArray poiArray;/*from   w w w.j  av  a 2  s .  co m*/
    try {
        poiArray = (JSONArray) parser.parse(jsonString);
        for (int i = 0; i < poiArray.size(); i++) {
            JSONObject jsonPOI = (JSONObject) poiArray.get(i);
            POI poi = new POI();
            poi.setName((String) jsonPOI.get(JsonStrings.NAME));
            poi.setLatitude(Double.parseDouble((String) jsonPOI.get(JsonStrings.LATITUDE)));
            poi.setLongitude(Double.parseDouble((String) jsonPOI.get(JsonStrings.LONGITUDE)));
            if (!jsonPOI.get(JsonStrings.RADIUS).equals(""))
                poi.setRadius(Float.parseFloat((String) jsonPOI.get(JsonStrings.RADIUS)));
            else {
                //Default radius set when it is not set in the corresponding JSON object
                poi.setRadius(TechnologyManager.BT_START_GEOFENCE_RADIUS);
            }
            poi.setBeaconUuid((String) jsonPOI.get(JsonStrings.BEACON_UUID));
            poiList.add(poi);
        }
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return poiList;
}

From source file:com.gmail.gkovalechyn.automaticevents.parsing.IFloat.java

@Override
public void fromArgs(String[] args) {
    if (args.length == 0) {
        this.value = 0f;
    } else {//from w  w  w. ja va  2  s  . c  o  m
        this.value = Float.parseFloat(args[0]);
    }
}

From source file:com.grillecube.common.utils.JSONHelper.java

/**
 * parse object to float/*  w ww. ja  va  2  s .  c om*/
 * 
 * @see JSONArray getDouble(int index);
 **/
public static float jsonObjectToFloat(Object object) {
    try {
        if (object instanceof Number) {
            return (((Number) object).floatValue());
        }
        return (Float.parseFloat((String) object));
    } catch (Exception e) {
        throw new JSONException(object + " is not a number.");
    }
}

From source file:cz.mgn.mediservice.rest.Loader.java

public static ArrayList<Drug> loadDrugs(int pharmacyId) {
    ArrayList<Drug> drugs = new ArrayList<Drug>();

    JSONArray json = (JSONArray) loadJson();
    for (Object item : json) {
        JSONObject drugJson = (JSONObject) item;

        int id = Integer.parseInt((String) drugJson.get("id"));
        String name = (String) drugJson.get("name");
        String description = (String) drugJson.get("description");
        float price = Float.parseFloat((String) drugJson.get("price"));

        Drug drug = new Drug(id, name, description, price);
        drugs.add(drug);/*from w w w . ja  v  a 2s .c  o  m*/
    }

    return drugs;
}