Example usage for java.lang Double parseDouble

List of usage examples for java.lang Double parseDouble

Introduction

In this page you can find the example usage for java.lang Double parseDouble.

Prototype

public static double parseDouble(String s) throws NumberFormatException 

Source Link

Document

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

Usage

From source file:com.github.stagirs.common.model.DocumentParser.java

public static Document parse(File file) throws IOException {
    Document doc = new Document();
    doc.setId(file.getName());/*from  ww w  . jav a 2 s  .  com*/
    Iterator<String> list = split(FileUtils.readFileToString(file, "utf-8")).iterator();
    while (list.hasNext()) {
        String item = list.next();
        if (item.equals("<div class='section'>")) {
            doc.getBlocks().add(parseSection(doc.getId(), item, list));
            continue;
        }
        if (item.startsWith("<p")) {
            doc.getBlocks().add(parsePoint(doc.getId(), item, list));
            continue;
        }
        if (item.startsWith("<div class='title' ")) {
            item = item.split("semantic='")[1];
            doc.setTitleSemantic(Double.parseDouble(item.substring(0, item.indexOf("'"))));
            doc.setTitle(list.next());
            list.next();
            continue;
        }
        if (item.equals("<div class='author'>")) {
            doc.setAuthor(list.next());
            list.next();
            continue;
        }
        if (item.equals("<div class='classifier'>")) {
            doc.setClassifier(list.next());
            list.next();
            continue;
        }
        if (item.equals("<div class='thanks'>")) {
            doc.setThanks(list.next());
            list.next();
            continue;
        }
        if (item.equals("<div class='output'>")) {
            doc.setOutput(list.next());
            list.next();
            continue;
        }
    }
    return doc;
}

From source file:trinhm.controller.StudentController.java

@RequestMapping("edit")
public String edit(HttpServletRequest request, ModelMap model) {
    int masv = Integer.parseInt(request.getParameter("txtMasv"));
    String name = request.getParameter("txtName");
    double mark = Double.parseDouble(request.getParameter("txtMark"));
    String major = request.getParameter("txtMajor");
    Student sv = new Student(masv, name, mark, major);
    model.addAttribute("student", sv);

    List<Student> list = new ArrayList<Student>();
    list = StudentModel.showProduct("");
    model.addAttribute("listStudent", list);
    return "student";
}

From source file:com.google.web.bindery.autobean.vm.impl.JsonSplittable.java

public static Splittable create(String payload) {
    try {/* w w w  .j av  a  2s  .  co  m*/
        switch (payload.charAt(0)) {
        case '{':
            return new JsonSplittable(new JSONObject(payload));
        case '[':
            return new JsonSplittable(new JSONArray(payload));
        case '"':
            return new JsonSplittable(new JSONArray("[" + payload + "]").getString(0));
        case '-':
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
            return new JsonSplittable(Double.parseDouble(payload));
        case 't':
        case 'f':
            return new JsonSplittable(Boolean.parseBoolean(payload));
        case 'n':
            return null;
        default:
            throw new RuntimeException("Could not parse payload: payload[0] = " + payload.charAt(0));
        }
    } catch (JSONException e) {
        throw new RuntimeException("Could not parse payload", e);
    }
}

From source file:eu.scape_project.planning.xml.plan.NumericTransformerThresholdFactory.java

@Override
public Double createObject(Attributes arg0) throws Exception {
    return Double.parseDouble(arg0.getValue("value"));
}

From source file:AIR.Common.Utilities.JavaPrimitiveUtils.java

public static boolean doubleTryParse(String value, _Ref<Double> ref) {
    try {/*from   w w w .  j a v a2  s  .c  o  m*/
        ref.set(Double.parseDouble(value));
        return true;
    } catch (NumberFormatException exp) {
        return false;
    }
}

From source file:lectorarchivos.MostrarGraficaCSV.java

/**
 * Creates new form MostrarGraficaCSV/*from w  w  w .j  a  v  a  2s.co m*/
 */
public MostrarGraficaCSV(JTable jTableInfoCSV) {
    initComponents();
    this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    panel = new JPanel();
    getContentPane().add(panel);

    //Fuente de datos
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    //Recorremos la columna del consumo de la tabla
    for (int i = jTableInfoCSV.getRowCount() - 1; i >= 0; i--) {
        if (Double.parseDouble(jTableInfoCSV.getValueAt(i, 4).toString()) > 0)
            dataset.setValue(Double.parseDouble(jTableInfoCSV.getValueAt(i, 4).toString()), "Consumo",
                    jTableInfoCSV.getValueAt(i, 0).toString());
    }

    //Creando el grfico
    JFreeChart chart = ChartFactory.createBarChart3D("Consumo", "Fecha", "Consumo", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(Color.cyan);
    chart.getTitle().setPaint(Color.black);
    chart.setBackgroundPaint(Color.white);
    chart.removeLegend();

    //Cambiar color de barras
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    BarRenderer barRenderer = (BarRenderer) plot.getRenderer();
    barRenderer.setSeriesPaint(0, Color.decode("#5882FA"));

    // Mostrar Grafico
    ChartFrame frame = new ChartFrame("CONSUMO", chart);
    frame.pack();
    frame.getChartPanel().setMouseZoomable(false);
    frame.setVisible(true);

    panel.add(frame);

}

From source file:gov.nih.nci.cabig.caaers.validation.fields.validators.DecimalRangeValidator.java

@Override
public boolean isValid(Object fieldValue) {
    if (fieldValue == null)
        return true;
    if (NumberUtils.isNumber(fieldValue.toString()))
        return Double.parseDouble(fieldValue.toString()) <= end
                && Double.parseDouble(fieldValue.toString()) >= begin;
    return false;
}

From source file:controller.JsonController.java

public ArrayList<JsonModel> ReadJsonCalc() throws FileNotFoundException, IOException, ParseException {

    FileInputStream fstream = new FileInputStream("gistfile1.txt");
    BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
    String strLine;//  ww  w.  j av a  2 s.c  om
    ArrayList<JsonModel> result = new ArrayList<>();
    JsonModel model;

    double L1, G1, L2, G2;

    //Read File Line By Line
    while ((strLine = br.readLine()) != null) {
        model = new JsonModel();
        JSONParser parser = new JSONParser();
        Object obj = parser.parse(strLine);
        JSONObject jsonObject = (JSONObject) obj;

        model.setLatitude((double) Double.parseDouble((String) jsonObject.get("latitude")));
        model.setLongitude((double) Double.parseDouble((String) jsonObject.get("longitude")));
        model.setUserIid((int) Integer.parseInt((String) jsonObject.get("user_id").toString()));
        model.setName(((String) jsonObject.get("name")));

        L1 = Math.toRadians(model.getLatitudeDefault());
        G1 = Math.toRadians(model.getLongitudeDefault());
        L2 = Math.toRadians(model.getLatitude());
        G2 = Math.toRadians(model.getLongitude());

        // do the spherical trig calculation
        double angle = Math.acos(Math.sin(L1) * Math.sin(L2) + Math.cos(L1) * Math.cos(L2) * Math.cos(G1 - G2));
        // convert back to degrees
        angle = Math.toDegrees(angle);

        // each degree on a great circle of Earth is 69.1105 miles
        double distance = (69.1105 * angle) * 1.609344;

        if (distance <= 100)
            result.add(model);
    }
    Collections.sort(result);

    return result;
}

From source file:com.stealthyone.mcb.stbukkitlib.utils.LocationUtils.java

/**
 * Converts a string to a location.// ww  w.  jav a2  s .c o  m
 * Form: 'worldName,x,y,z,yaw,pitch'
 *
 * @param input String to convert.
 * @return String in location form.
 * @throws java.lang.IllegalArgumentException Thrown if the input string is not a valid location.
 */
public static Location stringToLocation(String input) {
    Validate.notNull(input, "Input cannot be null.");

    String[] split = input.split(",");
    if (split.length < 6)
        throw new IllegalArgumentException("Invalid input");

    return new Location(Bukkit.getWorld(split[0]), Double.parseDouble(split[1]), Double.parseDouble(split[2]),
            Double.parseDouble(split[3]), Float.parseFloat(split[4]), Float.parseFloat(split[5]));
}

From source file:com.exalttech.trex.stateful.models.trexglobal.FilterTrexGlobalResponseUtil.java

/**
 * Filter Response to create PortProperty
 *
 * @return//from   w  w w.  ja  v a  2  s  .co m
 */
public static List<PortProperties> createPortPropertiesArray(String response) {
    JSONObject jObject = new JSONObject(response);
    JSONObject data = jObject.getJSONObject("data");
    int numOfPorts = countNumberOfPorts(response);

    List<PortProperties> portProperties = new ArrayList<PortProperties>();
    for (int i = 0; i < numOfPorts; i++) {
        portProperties.add(
                new PortProperties(Long.parseLong(data.get(Constants.PORT_OPACKETS_KEY + "-" + i).toString()),
                        Long.parseLong(data.get(Constants.PORT_OBYTES_KEY + "-" + i).toString()),
                        Long.parseLong(data.get(Constants.PORT_IPACKETS_KEY + "-" + i).toString()),
                        Long.parseLong(data.get(Constants.PORT_IBYTES_KEY + "-" + i).toString()),
                        Long.parseLong(data.get(Constants.PORT_IERROR_KEY + "-" + i).toString()),
                        Long.parseLong(data.get(Constants.PORT_OERROR_KEY + "-" + i).toString()),
                        Double.parseDouble(data.get(Constants.PORT_M_TOTAL_TX_BPS_KEY + "-" + i).toString()),
                        Double.parseDouble(data.get(Constants.PORT_M_TOTAL_TX_PPS_KEY + "-" + i).toString()),
                        Double.parseDouble(data.get(Constants.PORT_M_TOTAL_RX_BPS_KEY + "-" + i).toString()),
                        Double.parseDouble(data.get(Constants.PORT_M_TOTAL_RX_PPS_KEY + "-" + i).toString())));
    }
    return portProperties;
}