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:io.seldon.memcache.DogpileHandler.java

@Autowired
public DogpileHandler(@Value("${io.seldon.dogpile.expire.factor:0.75}") String expireStr,
        @Value("${io.seldon.dogpile.active:true}") String activeStr) {
    expireFactor = Float.parseFloat(expireStr);
    if ("true".equals(activeStr))
        active = true;//from w  w  w.jav a2 s . c o m
    logger.info("Creating dogpile cache handler with active: " + active + " and expire factor " + expireFactor);
    peer = this;
}

From source file:com.haulmont.cuba.gui.components.SizeWithUnit.java

/**
 * Returns an object whose numeric value and unit are taken from the string
 * {@code sizeString}. If {@code sizeString} does not specify a unit and {@code defaultUnit} is not null,
 * {@code defaultUnit} is used as the unit. Null, empty or 'AUTO' string will produce {-1, SizeUnit#PIXELS}.
 *
 * @param sizeString  the string to be parsed
 * @param defaultUnit The unit to be used if {@code sizeString} does not contain any unit.
 *                    Use {@code null} for no default unit.
 * @return an object containing the parsed value and unit
 *///  www.  j a  va2 s .  c  o  m
public static SizeWithUnit parseStringSize(String sizeString, SizeUnit defaultUnit) {
    if (StringUtils.isEmpty(sizeString) || "auto".equalsIgnoreCase(sizeString)) {
        return new SizeWithUnit(-1, SizeUnit.PIXELS);
    }

    float size;
    SizeUnit unit;
    Matcher matcher = SIZE_PATTERN.matcher(sizeString);
    if (matcher.find()) {
        size = Float.parseFloat(matcher.group(1));
        if (size < 0) {
            size = -1;
            unit = SizeUnit.PIXELS;
        } else {
            String symbol = matcher.group(2);
            if ((symbol != null && symbol.length() > 0) || defaultUnit == null) {
                unit = SizeUnit.getUnitFromSymbol(symbol);
            } else {
                unit = defaultUnit;
            }
        }
    } else {
        throw new IllegalArgumentException(
                "Invalid size argument: \"" + sizeString + "\" (should match " + SIZE_PATTERN.pattern() + ")");
    }

    return new SizeWithUnit(size, unit);
}

From source file:com.alcatel_lucent.nz.wnmsextract.reader.CSVReader.java

/**
 * String tokeniser method will split up a CSV file by row and column 
 * returning a List<List<String>>
 * @param in/*from  ww  w  . j  av a  2s .com*/
 * @param struct
 * @return
 */
public static ArrayList<ArrayList<String>> read(BufferedReader in, ArrayList<ColumnStructure> struct) {
    ArrayList<ArrayList<String>> dmap = new ArrayList<ArrayList<String>>();
    CSVParser parser = new CSVParser(in, CSVReader.strategy);

    //if header
    try {
        //[consume header]
        //String[] header = 
        parser.getLine();

        //and body
        String[] line = null;

        while ((line = parser.getLine()) != null) {
            ArrayList<String> list = new ArrayList<String>();

            for (int i = 0; i < line.length; i++) {
                ColumnStructure cs = struct.get(i);
                switch (cs) {
                case VC:
                    list.add(line[i]);
                    break;
                case TS:
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(DATA_DF.parse(line[i]));
                    list.add(ALUDBUtilities.ALUDB_DF.format(cal.getTime()));
                    break;
                case FL:
                    list.add(String.valueOf(validateFloat(Float.parseFloat(line[i]))));
                    break;
                case IT:
                    list.add(String.valueOf(validateInt(Integer.parseInt(line[i]))));
                    break;
                default:
                    list.add(line[i]);
                }
            }

            dmap.add(list);
        }
    } catch (IOException ioe) {
        // TODO Auto-generated catch block
        ioe.printStackTrace();
    } catch (ParseException pe) {
        // TODO Auto-generated catch block
        pe.printStackTrace();
    }

    return dmap;
}

From source file:com.kurento.kmf.test.services.Recorder.java

public static float getPesqMos(String audio, int sampleRate) {
    float pesqmos = 0;

    try {//from  w w  w.  j a v  a  2  s.c om
        String pesq = KurentoServicesTestHelper.getTestFilesPath() + "/bin/pesq/PESQ";
        String origWav = "";
        if (audio.startsWith(HTTP_TEST_FILES)) {
            origWav = KurentoServicesTestHelper.getTestFilesPath() + audio.replace(HTTP_TEST_FILES, "");
        } else {
            // Download URL
            origWav = KurentoMediaServerManager.getWorkspace() + "/downloaded.wav";
            URL url = new URL(audio);
            ReadableByteChannel rbc = Channels.newChannel(url.openStream());
            FileOutputStream fos = new FileOutputStream(origWav);
            fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
            fos.close();
        }

        Shell.runAndWait(pesq, "+" + sampleRate, origWav, RECORDED_WAV);
        List<String> lines = FileUtils.readLines(new File(PESQ_RESULTS), "utf-8");
        pesqmos = Float.parseFloat(lines.get(1).split("\t")[2].trim());
        log.info("PESQMOS " + pesqmos);

        Shell.runAndWait("rm", PESQ_RESULTS);

    } catch (IOException e) {
        log.error("Exception recording local audio", e);
    }

    return pesqmos;
}

From source file:MSUmpire.SpectrumParser.PKLScanParser.java

private void Parse() throws FileNotFoundException, IOException {
    //806.080993652344,8429.974609375,1
    //832.287536621094,7226.927734375,1
    //854.039978027344,6682.37646484375,1
    //861.061340332031,8370.4716796875,1
    BufferedReader reader = new BufferedReader(new FileReader(filename));
    String line = "";
    String[] Values = null;//from w w w.j a v  a2s.  co m
    scan = new ScanData();
    scan.MGFTitle = FilenameUtils.getBaseName(filename);
    while ((line = reader.readLine()) != null) {
        if ((Values = line.split(",")).length == 3) {
            scan.AddPoint(Float.parseFloat(Values[0]), Float.parseFloat(Values[1]));
        }
    }
    reader.close();
}

From source file:auction.Auction.java

public int run(String[] args) throws Exception {

    int workers = Integer.parseInt(args[4]);

    GiraphJob job = new GiraphJob(super.getConf(), getClass().getName());

    GiraphConfiguration conf = job.getConfiguration();
    conf.setBoolean("giraph.useSuperstepCounters", false);
    conf.setFloat("EPSILON", Float.parseFloat(args[2]));
    conf.setInt("MAX", Integer.parseInt(args[3]));

    conf.setWorkerConfiguration(workers, workers, 100.0f);

    conf.setVertexInputFormatClass(IdDoubleMatrixVertexValueInputFormat.class);
    GiraphFileInputFormat.addVertexInputPath(conf, new Path(args[0]));

    conf.setVertexClass(AuctionVertex.class);

    conf.setVertexOutputFormatClass(EdgeListAuctionVertexOutputFormat.class);
    FileOutputFormat.setOutputPath(job.getInternalJob(), new Path(args[1]));

    if (job.run(true)) {
        return 0;
    } else {//from   w ww .  j ava2s .co m
        return -1;
    }
}

From source file:hola.ControladorUsuario.java

@RequestMapping(value = "/usuario", method = RequestMethod.PUT, headers = { "Accept=application/json" })
@ResponseBody//from w ww.  j a  va  2s . c  o m
String actualizar(@RequestBody String json) throws Exception {
    System.out.println("<<<<<<<<<Se ha recibido el json" + json);
    Map<String, String> map = new HashMap<String, String>();
    ObjectMapper mapper = new ObjectMapper();

    //Transformamos el json
    map = mapper.readValue(json, new TypeReference<HashMap<String, String>>() {
    });
    int edad = Integer.parseInt(map.get("edad"));
    float sueldo = Float.parseFloat(map.get("sueldo"));
    int id = Integer.parseInt(map.get("idUsuario"));

    String nombre = map.get("nombre");
    //AJUSTAMOS los campos veniudos de JSON al objeto a guardarse  
    Usuario u = new Usuario();
    u.setEdad(edad);
    u.setNombre(nombre);
    u.setSueldo(sueldo);
    u.setIdUsuario(id);
    //Guardamos el objeto
    DAOUsuario dao = new DAOUsuario();
    dao.actualizar(u);

    return "Se actualizo el usuario  " + nombre;
}

From source file:fr.xebia.demo.objectgrid.ObjectGridUtils.java

public static void checkJvmPreRequisitesForObjectGrid() {
    float javaVersion = Float.parseFloat(System.getProperty("java.specification.version").substring(0, 3));
    String jvmVendor = System.getProperty("java.vm.vendor");

    Validate.isTrue(jvmVendor.indexOf("IBM") > -1,
            "JVM must be an IBM 5+ JVM, vendor " + jvmVendor + " is not supported");
    Validate.isTrue(javaVersion >= 1.5f,
            "JVM must be an IBM 5+ JVM, version " + javaVersion + " is not supported");
}

From source file:org.zywx.wbpalmstar.plugin.uexiconlist.utils.IconListUtils.java

public static void setUIConfig(String jsonStr, float scale) {
    if (!TextUtils.isEmpty(jsonStr)) {
        try {/* ww w.  j  ava2s . c o  m*/
            JSONObject json = new JSONObject(jsonStr);

            int x = (int) (Float.parseFloat(json.optString(JK_UI_X)));
            UIConfig.setX(x);
            UIConfig.setScaleX((int) (x * scale));

            int y = (int) (Float.parseFloat(json.optString(JK_UI_Y)));
            UIConfig.setY(y);
            UIConfig.setScaleY((int) (y * scale));

            int width = (int) (Float.parseFloat(json.optString(JK_UI_W)));
            UIConfig.setWidth(width);
            UIConfig.setScaleWidth((int) (width * scale));

            int hight = (int) (Float.parseFloat(json.optString(JK_UI_H)));
            UIConfig.setHight(hight);
            UIConfig.setScaleHight((int) (hight * scale));

            UIConfig.setLine(((int) Float.parseFloat(json.optString(JK_UI_LINE))));
            UIConfig.setRow(((int) Float.parseFloat(json.optString(JK_UI_ROW))));

            UIConfig.setBackgroundColor(
                    Color.parseColor(json.optString(JK_BACKGROUND_COLOR, DEF_BACKGROUND_COLOR)));
            UIConfig.setTileTextColor(
                    Color.parseColor(json.optString(JK_TITLE_TEXT_COLOR, DEF_TITLE_TEXT_COLOR)));
            boolean isShowIconFrame = json.optBoolean(JK_IS_SHOW_ICON_FRAME, false);
            UIConfig.setIsShowIconFrame(isShowIconFrame);
            if (isShowIconFrame) {
                UIConfig.setIconFrameColor(
                        Color.parseColor(json.optString(JK_ICON_FRAME_COLOR, DEF_ICON_FRAME_COLOR)));
            }
            LogUtils.logDebug(true, "UIconfig:" + jsonStr);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

From source file:example.RepoChain.java

@Override
public String run(ChaincodeStub stub, String function, String[] args) {

    log.info("Called run with function arg -" + function);
    switch (function) {
    case "init":
        log.info("Inside init");
        init(stub, function, args);//ww  w  .ja va 2s  .  c o  m

        break;
    case "instruct":
        if (args.length < 8) {
            log.error("Not enough args for instruct, return error");
            return "Error: Not enough args for instruct, return error";
        } else {
            log.info("Trade instruct");
            String xref, tid, partID, contraID, cusip;
            float repoRate, startAmount;
            int par;
            xref = args[0];
            tid = args[1];
            partID = args[2];
            contraID = args[3];
            repoRate = Float.parseFloat(args[4]);
            startAmount = Float.parseFloat(args[5]);
            par = Integer.parseInt(args[6]);
            cusip = args[7];
            RepoContract repoObj = new RepoContract(xref, tid, partID, contraID, cusip, repoRate, startAmount,
                    par);
            log.info("Trade instruct with -" + repoObj);
            stub.putRawState("~" + repoObj.getKey(), ByteString.copyFrom(repoObj.toByteArr()));
            matchRepo(stub, repoObj);
        }
        break;
    case "deltrades":
        Map<String, ByteString> allTrades = null;
        // query for only unmatched trades identified by the ~ prefix in the key
        allTrades = stub.rangeQueryRawState("", "");
        for (String key : allTrades.keySet()) {
            stub.delState(key);
        }
        break;

    }
    return null;
}