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:lu.list.itis.dkd.aig.SimilarityProvider.java

/**
 * Constructor initialising the comparator from properties read from a properties file.
 *
 * @throws ExceptionInInitializerError/*www . java2s .com*/
 */
private SimilarityProvider() throws ExceptionInInitializerError {
    final Properties properties = PropertiesFetcher.getProperties();

    if (properties.isEmpty()) {
        throw new ExceptionInInitializerError("The properties file could not be located!"); //$NON-NLS-1$
    }

    useSemanticSimilarity = Boolean.parseBoolean(
            properties.getProperty(Externalization.SEMANTIC_SIMILARITY_PROPERTY, Externalization.FALSE_STRING));
    useStringSimilarity = Boolean.parseBoolean(
            properties.getProperty(Externalization.STRING_SIMILARITY_PROPERTY, Externalization.FALSE_STRING));
    useSoundexSimilarity = Boolean.parseBoolean(
            properties.getProperty(Externalization.SOUNDEX_SIMILARITY_PROPERTY, Externalization.FALSE_STRING));

    semanticSimilarityWeight = Float.parseFloat(properties
            .getProperty(Externalization.SEMANTIC_SIMILARITY_WEIGHT_PROPERTY, Externalization.ZERO_INTEGER));
    stringSimilarityWeight = Float.parseFloat(properties
            .getProperty(Externalization.STRING_SIMILARITY_WEIGHT_PROPERTY, Externalization.ZERO_INTEGER));
    soundexSimilarityWeight = Float.parseFloat(properties
            .getProperty(Externalization.SOUNDEX_SIMILARITY_WEIGHT_PROPERTY, Externalization.ZERO_INTEGER));

    if (useSemanticSimilarity) {
        throw new NotImplementedException("semantic similarity not yet available");
        //instantiateSemanticSimilarityBridge();
    }
}

From source file:gridool.util.system.SystemUtils.java

private static float parseJavaVersion(String versionStr) {
    if (versionStr == null) {
        throw new IllegalArgumentException();
    }//from  w  w  w  . j a  v  a2s.c o m
    // e.g., 1.3.12, 1.6
    String str = versionStr.substring(0, 3);
    if (versionStr.length() >= 5) {
        str = str + versionStr.substring(4, 5);
    }
    return Float.parseFloat(str);
}

From source file:hola.ControladorUsuario.java

@RequestMapping(value = "/usuario", method = RequestMethod.POST, headers = { "Accept=application/json" })
@ResponseBody/*  w w  w  .  j av  a 2 s.c o m*/
String guardar(@RequestBody String json) throws Exception {
    System.out.println("<<<<<<<<<Se ha recibido el json pra guardar" + 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"));

    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);

    //Guardamos el objeto
    DAOUsuario dao = new DAOUsuario();
    dao.guardar(u);

    return "Se actualizo el usuario  " + nombre;
}

From source file:com.junly.common.util.ReflectUtils.java

/**
 * <p class="detail">/*from  w  w w  .j  av  a  2 s .  co m*/
 * 
 * </p>
 * @author wan.Dong
 * @date 20161112 
 * @param obj 
 * @param name    ??
 * @param value  (?)??false
 * @return
 */
public static boolean setProperty(Object obj, String name, Object value) {
    if (obj != null) {
        Class<?> clazz = obj.getClass();
        while (clazz != null) {
            Field field = null;
            try {
                field = clazz.getDeclaredField(name);
            } catch (Exception e) {
                clazz = clazz.getSuperclass();
                continue;
            }
            try {
                Class<?> type = field.getType();
                if (type.isPrimitive() == true && value != null) {
                    if (value instanceof String) {
                        if (type.equals(int.class) == true) {
                            value = Integer.parseInt((String) value);
                        } else if (type.equals(double.class) == true) {
                            value = Double.parseDouble((String) value);
                        } else if (type.equals(boolean.class) == true) {
                            value = Boolean.parseBoolean((String) value);
                        } else if (type.equals(long.class) == true) {
                            value = Long.parseLong((String) value);
                        } else if (type.equals(byte.class) == true) {
                            value = Byte.parseByte((String) value);
                        } else if (type.equals(char.class) == true) {
                            value = Character.valueOf(((String) value).charAt(0));
                        } else if (type.equals(float.class) == true) {
                            value = Float.parseFloat((String) value);
                        } else if (type.equals(short.class) == true) {
                            value = Short.parseShort((String) value);
                        }
                    }
                    field.setAccessible(true);
                    field.set(obj, value);
                    field.setAccessible(false);
                }
                if (value == null || type.equals(value.getClass()) == true) {
                    field.setAccessible(true);
                    field.set(obj, value);
                    field.setAccessible(false);
                }
                return true;
            } catch (Exception e) {
                return false;
            }
        }
    }
    return false;
}

From source file:vn.edu.vttu.ui.PanelStatiticsRevenue.java

private void showChart(String title, String begin, String end) {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    int row = tbResult.getRowCount();
    for (int i = 0; i < row; i++) {
        float value = 0;
        try {/*from  ww  w .j av  a 2  s . c  o  m*/
            try {
                value = Float.parseFloat(String.valueOf(tbResult.getValueAt(i, 3)).trim().replaceAll("\\.", ""))
                        / 1000;
            } catch (Exception e) {
                value = Float.parseFloat(String.valueOf(tbResult.getValueAt(i, 3)).trim().replaceAll(",", ""))
                        / 1000;
            }
        } catch (Exception e) {
            value = 0;
        }
        String date = String.valueOf(tbResult.getValueAt(i, 0)).trim();

        dataset.addValue(value, "Doanh Thu", date);
    }

    JFreeChart chart = ChartFactory.createLineChart(
            "TH?NG K DOANH THU\nT " + title + " " + begin + " ?N " + title + " " + end, title,
            "S Ti?n(?n v: nghn ng)", dataset);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.black);
    ChartPanel CP = new ChartPanel(chart);
    pnChart.removeAll();
    pnChart.add(CP);
    pnChart.updateUI();
    pnChart.repaint();
    //ChartFrame frame = new ChartFrame("Thng k doanh thu", chart);
    //frame.setSize(450, 350);
    //frame.setVisible(true);
}

From source file:com.fredhopper.core.connector.index.generate.validator.FloatAttributeValidator.java

@Override
protected void validateValue(final FhAttributeData attribute, final List<Violation> violations) {
    final Table<Optional<String>, Optional<Locale>, String> values = attribute.getValues();
    final Map<Optional<Locale>, String> valueMap = values.row(Optional.empty());
    if (CollectionUtils.isEmpty(valueMap) || valueMap.entrySet().size() != 1
            || !valueMap.containsKey(Optional.empty())) {
        rejectValue(attribute, violations, "The \"float\" attribute value cannot be localized.");
        return;//  www  .j ava2 s . com
    }

    final String value = valueMap.get(Optional.empty());
    try {
        if (StringUtils.isBlank(value) || !(Float.parseFloat(value) > 0
                && Double.valueOf(Float.MAX_VALUE).compareTo(Double.valueOf(value)) > 0)) {
            rejectValue(attribute, violations,
                    "The \"float\" attribute value is not in the supported value range.");
        }
    } catch (final NumberFormatException ex) {
        rejectValue(attribute, violations,
                "The \"float\" attribute value does not have the appropriate format.");
    }
}

From source file:net.dahanne.gallery3.client.utils.ItemUtils.java

private static Entity parseJSONToEntity(JSONObject jsonResult) throws JSONException {
    Entity entity = new Entity();
    JSONObject entityJSON = jsonResult.getJSONObject("entity");

    entity.setId(entityJSON.getInt("id"));
    entity.setCaptured(entityJSON.getString("captured").equals("null") ? 0L
            : Integer.parseInt(entityJSON.getString("captured")));
    entity.setCreated(entityJSON.getString("created").equals("null") ? 0
            : Integer.parseInt(entityJSON.getString("created")));
    entity.setDescription(entityJSON.getString("description"));
    entity.setHeight(entityJSON.getString("height").equals("null") ? 0
            : Integer.parseInt(entityJSON.getString("height")));
    entity.setLevel(entityJSON.getInt("level"));
    entity.setMimeType(//from  w ww.  j  a v a  2s. co  m
            entityJSON.getString("mime_type").equals("null") ? null : entityJSON.getString("mime_type"));
    entity.setName(entityJSON.getString("name").equals("null") ? null : entityJSON.getString("name"));
    entity.setOwnerId(entityJSON.getString("owner_id").equals("null") ? 0
            : Integer.parseInt(entityJSON.getString("owner_id")));
    entity.setRandKey(entityJSON.getString("rand_key").equals("null") ? 0f
            : Float.parseFloat(entityJSON.getString("rand_key")));
    entity.setResizeHeight(entityJSON.getString("resize_height").equals("null") ? 0
            : Integer.parseInt(entityJSON.getString("resize_height")));
    entity.setResizeWidth(entityJSON.getString("resize_width").equals("null") ? 0
            : Integer.parseInt(entityJSON.getString("resize_width")));
    entity.setSlug(entityJSON.getString("slug").equals("null") ? null : entityJSON.getString("slug"));
    entity.setSortColumn(entityJSON.getString("sort_column"));
    entity.setSortOrder(entityJSON.getString("sort_order"));
    entity.setThumbHeight(entityJSON.getString("thumb_height").equals("null") ? 0
            : Integer.parseInt(entityJSON.getString("thumb_height")));
    entity.setThumbWidth(entityJSON.getString("thumb_width").equals("null") ? 0
            : Integer.parseInt(entityJSON.getString("thumb_width")));
    entity.setTitle(entityJSON.getString("title"));
    entity.setType(entityJSON.getString("type"));
    entity.setUpdated(entityJSON.getString("updated").equals("null") ? 0
            : Integer.parseInt(entityJSON.getString("updated")));
    entity.setViewCount(entityJSON.getInt("view_count"));
    entity.setWidth(
            entityJSON.getString("width").equals("null") ? 0 : Integer.parseInt(entityJSON.getString("width")));
    entity.setView1(entityJSON.getInt("view_1"));
    entity.setView2(entityJSON.getInt("view_2"));
    entity.setWebUrl(entityJSON.getString("web_url"));
    try {
        entity.setThumbUrl(
                entityJSON.getString("thumb_url").equals("null") ? null : entityJSON.getString("thumb_url"));
    } catch (JSONException e) {
        // nothing to do, it's just that there is no thumb url
    }
    try {
        entity.setThumbSize(entityJSON.getInt("thumb_size"));
    } catch (JSONException e) {
        // nothing to do, it's just that there is no thumb size
    }
    try {
        entity.setThumbUrlPublic(entityJSON.getString("thumb_url_public"));
    } catch (JSONException e) {
        // nothing to do, it's just that there is no thumb url public
    }
    try {
        entity.setParent(ItemUtils.getItemIdFromUrl(entityJSON.getString("parent")));
    } catch (JSONException e) {
        // nothing to do, it's just that there is no parent
    }
    entity.setCanEdit(entityJSON.getBoolean("can_edit"));

    if (entity.getType().equals("album")) {
        try {
            entity.setAlbumCover(entityJSON.getString("album_cover"));
        } catch (JSONException e) {
            // nothing to do, it's just that there is no album_cover
        }
    }

    if (entity.getType().equals("photo")) {
        entity.setFileUrl(entityJSON.getString("file_url"));
        entity.setFileSize(entityJSON.getInt("file_size"));
        try {
            entity.setFileUrlPublic(entityJSON.getString("file_url_public"));
        } catch (JSONException e) {
            // nothing to do, it's just that there is no album_cover
        }
        entity.setResizeUrl(entityJSON.getString("resize_url"));
        try {
            entity.setResizeSize(entityJSON.getInt("resize_size"));
        } catch (JSONException e) {
            // nothing to do, it's just that there is no album_cover
        }
        try {
            entity.setResizeUrlPublic(entityJSON.getString("resize_url_public"));
        } catch (JSONException e) {
            // nothing to do, it's just that there is no album_cover
        }
    }

    return entity;
}

From source file:hivemall.common.EtaEstimator.java

@Nonnull
public static EtaEstimator get(@Nullable CommandLine cl, float defaultEta0) throws UDFArgumentException {
    if (cl == null) {
        return new InvscalingEtaEstimator(defaultEta0, 0.1d);
    }//  w w w  .  j a  v a2s  .c o m

    if (cl.hasOption("boldDriver")) {
        float eta = Primitives.parseFloat(cl.getOptionValue("eta"), 0.3f);
        return new AdjustingEtaEstimator(eta);
    }

    String etaValue = cl.getOptionValue("eta");
    if (etaValue != null) {
        float eta = Float.parseFloat(etaValue);
        return new FixedEtaEstimator(eta);
    }

    float eta0 = Primitives.parseFloat(cl.getOptionValue("eta0"), defaultEta0);
    if (cl.hasOption("t")) {
        long t = Long.parseLong(cl.getOptionValue("t"));
        return new SimpleEtaEstimator(eta0, t);
    }

    double power_t = Primitives.parseDouble(cl.getOptionValue("power_t"), 0.1d);
    return new InvscalingEtaEstimator(eta0, power_t);
}

From source file:account.management.controller.ViewLcController.java

/**
 * Initializes the controller class.//from ww w.jav a  2s  .c  o  m
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    lc_no.setCellValueFactory(new PropertyValueFactory("lc_no"));
    party_name.setCellValueFactory(new PropertyValueFactory("party_name"));
    party_address.setCellValueFactory(new PropertyValueFactory("party_address"));
    party_bank.setCellValueFactory(new PropertyValueFactory("party_bank"));
    our_bank.setCellValueFactory(new PropertyValueFactory("our_bank"));
    amount.setCellValueFactory(new PropertyValueFactory("lc_amount"));
    init_date.setCellValueFactory(new PropertyValueFactory("formattedInitDate"));
    start_date.setCellValueFactory(new PropertyValueFactory("formattedStartDate"));
    dimilish_date.setCellValueFactory(new PropertyValueFactory("formattedDimilishDate"));

    new Thread(() -> {
        try {
            HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "get/lc/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 lc_no = obj.getString("lc_number");
                String party_name = obj.getString("party_name");
                String party_address = obj.getString("party_address");
                String party_bank = obj.getString("party_bank_name");
                String our_bank = obj.getString("our_bank_name");
                String lc_amount = String.valueOf(Float.parseFloat(obj.getString("lc_amount")));
                String init_date = obj.getString("initialing_date");
                String start_date = obj.getString("starting_date");
                String dimilish_date = obj.getString("dimilish_date");

                tableView.getItems().add(new LC(Long.parseLong(id), lc_no, party_name, party_address,
                        party_bank, our_bank, lc_amount, init_date, start_date, dimilish_date));
                //tableView.getItems().add(new Project(id,name,investment,related_party,starting_date,operation_date,dimilish_date));

            }
        } catch (Exception e) {
        }
    }).start();

}

From source file:master.flame.danmaku.danmaku.parser.android.AcFunDanmakuParser.java

private Danmakus _parse(JSONArray jsonArray, Danmakus danmakus) {
    if (danmakus == null) {
        danmakus = new Danmakus();
    }/*from w ww . j  a  v a2s .  c om*/
    if (jsonArray == null || jsonArray.length() == 0) {
        return danmakus;
    }
    for (int i = 0; i < jsonArray.length(); i++) {
        try {
            JSONObject obj = jsonArray.getJSONObject(i);
            String c = obj.getString("c");
            String[] values = c.split(",");
            if (values.length > 0) {
                int type = Integer.parseInt(values[2]); // 
                if (type == 7)
                    // FIXME : hard code
                    // TODO : parse advance danmaku json
                    continue;
                long time = (long) (Float.parseFloat(values[0]) * 1000); // 
                int color = Integer.parseInt(values[1]) | 0xFF000000; // 
                float textSize = Float.parseFloat(values[3]); // ?
                BaseDanmaku item = DanmakuFactory.createDanmaku(type, mDisp);
                if (item != null) {
                    item.time = time;
                    item.textSize = textSize * (mDispDensity - 0.6f);
                    item.textColor = color;
                    item.textShadowColor = color <= Color.BLACK ? Color.WHITE : Color.BLACK;
                    DanmakuFactory.fillText(item, obj.optString("m", "...."));
                    item.index = i;
                    item.setTimer(mTimer);
                    danmakus.addItem(item);
                }
            }
        } catch (JSONException e) {
        } catch (NumberFormatException e) {
        }
    }
    return danmakus;
}