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:loadjson.JsonParse.java

public void LoadJson() throws IOException, ParseException, SQLException, ClassNotFoundException {

    FileReader reader = new FileReader("allsets.json");
    JSONParser jsonParser = new JSONParser();
    JSONObject jsonObject = (JSONObject) jsonParser.parse(reader);
    Iterator<JSONObject> iterator = jsonObject.values().iterator();

    //  System.out.println(s.get("border"));

    Conn conn = new Conn();

    while (iterator.hasNext()) {

        JSONObject lJson = iterator.next();
        JSONArray cards = (JSONArray) lJson.get("cards");
        String code = String.valueOf(lJson.get("code"));
        String border = String.valueOf(lJson.get("border"));

        for (Object card : cards) {
            Card c = new Card();

            JSONObject js = (JSONObject) card;
            c.setId(String.valueOf(js.get("id")));
            try {
                c.setName(js.get("name").toString());
            } catch (NullPointerException e) {
                c.setName("");
            }/*from www .j a  v a  2  s. com*/
            c.setNames(String.valueOf(js.get("names")).replaceAll("[\\[\\\"\\]]", ""));

            try {
                c.setManaCost(js.get("manaCost").toString());
            } catch (NullPointerException e) {
                c.setManaCost("");
            }
            try {
                c.setCmc(Float.parseFloat(String.valueOf(js.get("cmc"))));
            } catch (NumberFormatException e) {
                c.setCmc(0);
            }
            c.setColor(String.valueOf(js.get("colors")).replaceAll("[\\[\\\"\\]]", ""));
            c.setColorIdentity(String.valueOf(js.get("colorIdentity")).replaceAll("[\\[\\\"\\]]", ""));
            try {
                c.setType(js.get("type").toString());
            } catch (NullPointerException e) {
                c.setType("");
            }
            try {
                c.setSupertypes(js.get("supertypes").toString());
            } catch (NullPointerException e) {
                c.setSupertypes("");
            }
            try {
                c.setTypes(js.get("types").toString());
            } catch (NullPointerException e) {
                c.setTypes("");
            }
            try {
                c.setSubtypes(js.get("subtypes").toString());
            } catch (NullPointerException e) {
                c.setSubtypes("");
            }
            try {
                c.setRarity(js.get("rarity").toString());
            } catch (NullPointerException e) {
                c.setRarity("");
            }
            try {
                c.setText(js.get("text").toString());
            } catch (NullPointerException e) {
                c.setText("");
            }
            try {
                c.setFlavor(js.get("flavor").toString());
            } catch (NullPointerException e) {
                c.setFlavor("");
            }
            try {
                c.setArtist(js.get("artist").toString());
            } catch (NullPointerException e) {
                c.setArtist("");
            }
            try {
                c.setNumber(js.get("number").toString());
            } catch (NullPointerException e) {
                c.setNumber("");
            }
            try {
                c.setPower(js.get("power").toString());
            } catch (NullPointerException e) {
                c.setPower("");
            }
            try {
                c.setToughness(js.get("toughness").toString());
            } catch (NullPointerException e) {
                c.setToughness("");
            }
            try {
                c.setLoyalty(js.get("loyalty").toString());
            } catch (NullPointerException e) {
                c.setLoyalty("");
            }
            c.setMultiverseid(String.valueOf(js.get("multiverseid")));
            try {
                c.setVariations(js.get("variations").toString());
            } catch (NullPointerException e) {
                c.setVariations("");
            }
            c.setImageName(String.valueOf(js.get("imageName")));
            try {
                c.setWatermark(js.get("watermark").toString());
            } catch (NullPointerException e) {
                c.setWatermark("");
            }
            c.setBorder(border);
            try {
                c.setTimeshifted(js.get("timeshifted").toString());
            } catch (NullPointerException e) {
                c.setTimeshifted("");
            }
            try {
                c.setHand(js.get("hand").toString());
            } catch (NullPointerException e) {
                c.setHand("");
            }
            try {
                c.setReserved(String.valueOf(js.get("reserved")));
            } catch (NullPointerException e) {
            }
            try {
                c.setReleaseDate(js.get("releaseDate").toString());
            } catch (NullPointerException e) {
                c.setReleaseDate("");
            }
            try {
                c.setStarter(js.get("starter").toString());
            } catch (NullPointerException e) {
                c.setStarter("");
            }

            c.setSetsCode(code);

            //System.out.println(c.getPower());
            conn.insertTb(c);

            /* if(!String.valueOf(js.get("names")).equalsIgnoreCase("null")){
               System.out.println(String.valueOf(js.get("names")));
            }
                    
            String color =   String.valueOf(js.get("colorIdentity")).replaceAll("[\\[\\\"\\]]", "");
                    
                    
              System.out.println(code+" - "+js.get("name")+" - "+js.get("name")+" - "+color);*/

        }

    }

    //  JSONArray cards = (JSONArray) jsonObject.get("cards");
    // System.out.println(cards.size());
    /*  Iterator<String> iterator = cars.iterator();
    while (iterator.hasNext()) {
        System.out.print("--");
     System.out.println(iterator.next());
    }*/
}

From source file:com.avira.couchdoop.demo.ExportMapper.java

@Override
/**/*ww w. j a v a  2s.c om*/
 * Recommended articles are in the format: session_id   article_name1;score1    article_name2;score2    ....
 */
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
    String[] tokens = value.toString().split(DELIMITER);

    String documentKey = tokens[0];

    Recommendation rec = new Recommendation();
    for (int i = 1; i < tokens.length; i++) {
        String[] recData = tokens[i].split(SECONDARY_DELIMITER);
        rec.addArticle(new RecommendedItem(recData[0], Float.parseFloat(recData[1])));
    }

    CouchbaseAction action = new CouchbaseAction(CouchbaseOperation.SET, JACKSON.writeValueAsString(rec));

    context.write(KEY_PREFIX + documentKey, action);
}

From source file:it.volaconnoi.bean.RouteManagerBean.java

@Override
public void addRoute(String airlane, String aircraft_id, String airport_city_source, String airport_city_dest,
        String departure_date, String arrival_date, String departure_hour, String departure_minutes,
        String arrival_hour, String arrival_minutes, String class_travel, String seats, String rate) {
    Route route = new Route();

    route.setAirlane(airlane);/* ww w .  j  a  v a 2 s  .co m*/
    route.setAircraft_id(aircraft_id.toUpperCase());

    route.setAirport_city_source(airportFacade.find(Integer.parseInt(airport_city_source)));
    route.setAirport_city_dest(airportFacade.find(Integer.parseInt(airport_city_dest)));

    route.setDeparture_date(utilBean.getFormattedDate(departure_date, departure_hour, departure_minutes, 0));
    route.setArrival_date(utilBean.getFormattedDate(arrival_date, arrival_hour, arrival_minutes, 0));

    route.setTravel_class(class_travel);
    route.setSeats(Integer.parseInt(seats));
    route.setPrice(Float.parseFloat(rate));

    route.setReservationsList(new LinkedList<Reservation>());

    em.persist(route);
}

From source file:io.github.autsia.crowly.services.sentiment.impl.CrowlySentimentAnalyzer.java

@Override
public Pair<Sentiment, Float> analyze(String text) {
    try {//from w  w  w .  ja v  a  2  s.  c  o  m
        HttpResponse<JsonNode> request = Unirest.post(URL).field("txt", text).asJson();
        JSONObject result = request.getBody().getObject().getJSONObject(RESULT);
        String sentiment = result.getString(SENTIMENT);
        Float confidence = Float.parseFloat(result.getString(CONFIDENCE));
        return new ImmutablePair<>(Sentiment.get(sentiment), confidence);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return new ImmutablePair<>(Sentiment.NEUTRAL, 0.5f);
    }
}

From source file:me.st28.flexseries.flexcore.util.LocationUtils.java

/**
 * Converts a string to a location./*from   w w  w.java2 s.com*/
 *
 * @param rawLocation The raw location.<br />
 *                    <b>Format:</b> <code>world;x;y;z;yaw;pitch</code>
 * @return A new Location object that represents the input string.
 */
public static Location stringToLocation(String rawLocation) {
    Validate.notNull(rawLocation, "Raw location cannot be null.");

    String[] split = rawLocation.split(";");

    if (split.length != 6) {
        throw new IllegalArgumentException("Invalid location '" + rawLocation + "'");
    }

    World world = Bukkit.getWorld(split[0]);
    double x = Double.parseDouble(split[1]);
    double y = Double.parseDouble(split[2]);
    double z = Double.parseDouble(split[3]);
    float yaw = Float.parseFloat(split[4]);
    float pitch = Float.parseFloat(split[5]);

    return new Location(world, x, y, z, yaw, pitch);
}

From source file:de.ellpeck.actuallyadditions.mod.booklet.gui.GuiBooklet.java

private static float getFontSize(String lang, ConfigIntValues config, float defaultValue) {
    int conf = config.getValue();
    if (conf <= 0) {
        try {/*from ww w .  j av a  2s .c o  m*/
            return Float.parseFloat(
                    StringUtil.localize("booklet." + ActuallyAdditions.MODID + ".fontSize." + lang));
        } catch (Exception e) {
            return defaultValue;
        }
    } else {
        return conf / 100F;
    }
}

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

@FXML
private void onClickShowTrialBalance(ActionEvent event) {
    try {/* w  w  w.  j a v a2  s  .c o m*/
        HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "report/trialbalance/with/date")
                .queryString("start_date", this.start.getValue().toString())
                .queryString("end_date", this.end.getValue().toString()).asJson();
        JSONArray array = res.getBody().getArray();
        Vector v = new Vector();
        HashMap params = new HashMap();
        float total_dr = 0, total_cr = 0;
        for (int i = 1; i < array.length(); i++) {
            JSONObject obj = array.getJSONObject(i);
            String id = obj.get("id").toString();
            String name = obj.getString("name");
            String balance = String.format("%1$.2f", obj.getDouble("balance"));
            //String balance = String.valueOf(obj.getDouble("balance"));
            String dr, cr;
            if (Float.parseFloat(balance) < 0) {
                cr = balance;
                dr = "";
                total_cr += Float.parseFloat(cr);
            } else {
                dr = balance;
                total_dr += Float.parseFloat(dr);
                cr = "";
            }
            if (!dr.equals(""))
                dr = String.format("%1$.2f", Double.parseDouble(dr));
            if (!cr.equals(""))
                cr = String.format("%1$.2f", Double.parseDouble(cr));
            v.add(new TrialBalance(name, dr, cr));
        }

        Vector trialBalanceVector = getSortedTrialBalance(v, array);

        params.put("total_dr", String.format("%1$.2f", total_dr));
        params.put("total_cr", String.format("%1$.2f", total_cr * (-1)));
        Report report = new Report();
        report.getReport("src\\report\\trialBalance.jrxml", new JRBeanCollectionDataSource(trialBalanceVector),
                params, "Trial Balance");

    } catch (UnirestException ex) {
        Logger.getLogger(ReportTrialBalanceController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:edu.usu.sdl.openstorefront.core.util.EntityUtil.java

/**
 * This will set default on the fields that are marked with a default and
 * are null/*from ww  w  .ja v  a 2  s.c  o m*/
 *
 * @param entity
 */
public static void setDefaultsOnFields(Object entity) {
    Objects.requireNonNull(entity, "Entity must not be NULL");
    List<Field> fields = getAllFields(entity.getClass());
    for (Field field : fields) {
        DefaultFieldValue defaultFieldValue = field.getAnnotation(DefaultFieldValue.class);
        if (defaultFieldValue != null) {
            field.setAccessible(true);
            try {
                if (field.get(entity) == null) {
                    String value = defaultFieldValue.value();
                    Class fieldClass = field.getType();
                    if (fieldClass.getSimpleName().equalsIgnoreCase(String.class.getSimpleName())) {
                        field.set(entity, value);
                    } else if (fieldClass.getSimpleName().equalsIgnoreCase(Long.class.getSimpleName())) {
                        field.set(entity, value);
                    } else if (fieldClass.getSimpleName().equalsIgnoreCase(Integer.class.getSimpleName())) {
                        field.set(entity, Integer.parseInt(value));
                    } else if (fieldClass.getSimpleName().equalsIgnoreCase(Boolean.class.getSimpleName())) {
                        field.set(entity, Convert.toBoolean(value));
                    } else if (fieldClass.getSimpleName().equalsIgnoreCase(Double.class.getSimpleName())) {
                        field.set(entity, Double.parseDouble(value));
                    } else if (fieldClass.getSimpleName().equalsIgnoreCase(Float.class.getSimpleName())) {
                        field.set(entity, Float.parseFloat(value));
                    } else if (fieldClass.getSimpleName().equalsIgnoreCase(BigDecimal.class.getSimpleName())) {
                        field.set(entity, Convert.toBigDecimal(value));
                    } else if (fieldClass.getSimpleName().equalsIgnoreCase(Date.class.getSimpleName())) {
                        field.set(entity, TimeUtil.fromString(value));
                    } else if (fieldClass.getSimpleName().equalsIgnoreCase(BigInteger.class.getSimpleName())) {
                        field.set(entity, new BigInteger(value));
                    }
                }
            } catch (IllegalArgumentException | IllegalAccessException ex) {
                throw new OpenStorefrontRuntimeException(
                        "Unable to get value on " + entity.getClass().getName(), "Check entity passed in.");
            }
        }
    }
}

From source file:org.cellcore.code.engine.page.extractor.mfrag.MFRAGPageDataExtractor.java

@Override
protected int getStock(Document doc) {
    Elements trs = doc.select("#Tableau").get(0).children().get(0).children();
    float iPrice = Float.MAX_VALUE;
    int iStock = 0;
    for (int i = 1; i < trs.size(); i++) {
        Element tr = trs.get(i);// ww  w  . ja  v  a  2 s. c om
        String val = tr.select("td").get(3).select("strong").get(0).childNodes().get(0).attr("text");
        String stockV = tr.select("td").get(4).select("option").last().childNodes().get(0).attr("text");
        val = cleanPriceString(val);
        float price = Float.parseFloat(val);

        if (price < iPrice) {
            iPrice = price;
            iStock = Integer.parseInt(stockV.replaceAll("\\(", "").replaceAll("\\)", ""));
        }
    }
    return iStock;
}

From source file:de.ingrid.iplug.opensearch.converter.RankingModifierFromPD.java

private void setMultiplier(String multiplier) {
    if (multiplier != null) {
        this.multiplier = Float.parseFloat(multiplier);
    }
}