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:edu.cmu.cs.lti.ark.fn.identification.training.ConvertAlphabetFile.java

public static void main(String[] args) throws Exception {
    final String alphabetFile = args[0];
    final String modelFile = args[1];
    final String outFile = args[2];
    final String featureType = args[3];
    final double threshold = args.length >= 5 ? Double.parseDouble(args[4].trim()) : DEFAULT_THRESHOLD;

    // read in map from feature id -> feature name
    final BiMap<Integer, String> featureNameById = readAlphabetFile(new File(alphabetFile)).inverse();
    // read in parameter values
    final double[] parameters = TrainBatch.loadModel(modelFile);
    // write out list of (feature name, feature value) pairs
    final BufferedWriter output = Files.newWriter(new File(outFile), Charsets.UTF_8);
    try {/*from w w w  . j  a v a2 s. c  o m*/
        output.write(String.format("%s\n", featureType));
        for (int i : xrange(parameters.length)) {
            final double val = parameters[i];
            if (Math.abs(val) <= threshold)
                continue;
            output.write(String.format("%s\t%s\n", featureNameById.get(i), val));
        }
    } finally {
        closeQuietly(output);
    }
}

From source file:com.nubits.nubot.tests.TestRPC.java

public static void main(String[] args) {

    //Default values
    String custodian = Passwords.CUSTODIAN_PUBLIC_ADDRESS;
    String user = Passwords.NUD_RPC_USER;
    String pass = Passwords.NUD_RPC_PASS;
    double sell = 0;
    double buy = 0;
    //java -jar testRPC user pass custodian sell buy
    if (args.length == 5) {
        LOG.info("Reading input parameters");
        user = args[0];/* w  w  w . j a v a  2s . co  m*/
        pass = args[1];
        custodian = args[2];
        sell = Double.parseDouble(args[3]);
        buy = Double.parseDouble(args[4]);
    }

    Utils.loadProperties("settings.properties");

    TestRPC test = new TestRPC();

    test.setup(Constant.INTERNAL_EXCHANGE_PEATIO, custodian, Constant.NBT_BTC, user, pass);
    test.testCheckNudTask();
    try {
        Thread.sleep(2000);

    } catch (InterruptedException ex) {
        Logger.getLogger(TestRPC.class.getName()).log(Level.SEVERE, null, ex);
    }
    //test.testGetInfo();
    //test.testIsConnected();
    test.testSendLiquidityInfo(buy, sell, 1);
    //test.testGetLiquidityInfo();
    //test.testGetLiquidityInfo(Constant.SELL, Passwords.CUSTODIA_PUBLIC_ADDRESS);
    //test.testGetLiquidityInfo(Constant.BUY, Passwords.CUSTODIA_PUBLIC_ADDRESS);

    System.exit(0);

}

From source file:com.super_bits.modulos.paginas.adminTools.PgAdminContainerObjetoTest.java

public static void main(String[] paramentros) {

    // Ask for user input
    System.out.print("Enter 1st value:");

    // use scanner to read the console input
    Scanner scan = new Scanner(System.in);
    String valor = scan.next();//from  www .j a  v a 2  s  . c  o m
    double valorAtualizado = Double.parseDouble(valor) * 8.333;
    double calculoMultiplo = 10 * (Math.ceil(Math.abs(valorAtualizado / 10)));

    System.out.println(calculoMultiplo);

    double teste = (double) Math.round(Double.parseDouble(valor) * 8.3d) * 10 / 10d;
    System.out.println("TEste:" + teste);

    System.out.println("Result of the operation is " + valor);

    System.out.println(Precision.round(0.912385, 0, BigDecimal.ROUND_HALF_UP));
    int yourScale = 10;
    System.out.println(BigDecimal.valueOf(0.42344534534553453453 - 0.42324534524553453453).setScale(yourScale,
            BigDecimal.ROUND_HALF_UP));
}

From source file:eu.bitm.NominatimReverseGeocoding.NominatimReverseGeocodingJAPI.java

public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("use -help for instructions");
    } else if (args.length < 2) {
        if (args[0].equals("-help")) {
            System.out.println("Mandatory parameters:");
            System.out.println("   -lat [latitude]");
            System.out.println("   -lon [longitude]");
            System.out.println("\nOptional parameters:");
            System.out.println("   -zoom [0-18] | from 0 (country) to 18 (street address), default 18");
            System.out.println("   -osmid       | show also osm id and osm type of the address");
            System.out.println("\nThis page:");
            System.out.println("   -help");
        } else//from w ww. j a va 2  s  .  c  om
            System.err.println("invalid parameters, use -help for instructions");
    } else {
        boolean latSet = false;
        boolean lonSet = false;
        boolean osm = false;

        double lat = -200;
        double lon = -200;
        int zoom = 18;

        for (int i = 0; i < args.length; i++) {
            if (args[i].equals("-lat")) {
                try {
                    lat = Double.parseDouble(args[i + 1]);
                } catch (NumberFormatException nfe) {
                    System.out.println("Invalid latitude");
                    return;
                }

                latSet = true;
                i++;
                continue;
            } else if (args[i].equals("-lon")) {
                try {
                    lon = Double.parseDouble(args[i + 1]);
                } catch (NumberFormatException nfe) {
                    System.out.println("Invalid longitude");
                    return;
                }

                lonSet = true;
                i++;
                continue;
            } else if (args[i].equals("-zoom")) {
                try {
                    zoom = Integer.parseInt(args[i + 1]);
                } catch (NumberFormatException nfe) {
                    System.out.println("Invalid zoom");
                    return;
                }

                i++;
                continue;
            } else if (args[i].equals("-osm")) {
                osm = true;
            } else {
                System.err.println("invalid parameters, use -help for instructions");
                return;
            }
        }

        if (latSet && lonSet) {
            NominatimReverseGeocodingJAPI nominatim = new NominatimReverseGeocodingJAPI(zoom);
            Address address = nominatim.getAdress(lat, lon);
            System.out.println(address);
            if (osm) {
                System.out.print("OSM type: " + address.getOsmType() + ", OSM id: " + address.getOsmId());
            }
        } else {
            System.err.println("please specifiy -lat and -lon, use -help for instructions");
        }
    }
}

From source file:com.tengen.MultiArrayFindTest.java

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

    MongoClient client = new MongoClient();
    DB db = client.getDB("school");
    DBCollection collection = db.getCollection("students");

    System.out.println("Find one:");
    DBObject one = collection.findOne();
    System.out.println(one);//from   w w w  .j a va2 s .c  o m

    System.out.println("\nFind all: ");
    DBCursor cursor = collection.find().sort(new BasicDBObject("_id", 1));
    System.out.println(cursor.count());

    try {
        while (cursor.hasNext()) {

            int id = (Integer) cursor.next().get("_id");
            //String s =  cursor.next().get("name");

            Map<Integer, String> myMap = new HashMap<Integer, String>();

            BasicBSONList bl = (BasicBSONList) cursor.next().get("scores");
            for (Object bo : bl) {

                BasicBSONObject bo1 = (BasicBSONObject) bo;
                System.out.println(bo);
                System.out.println(Integer.toString(id));

                if (1 > 1) {
                }
                double total1 = Double.parseDouble(bo1.get("score").toString());
                System.out.println("score1: " + total1);

                myMap.put(id, bo1.get("score").toString());
                System.out.println("score: " + myMap.get(id));

                double total = Double.parseDouble(myMap.get(id).toString());
                System.out.println("score: " + total);

                //}
            }

        }

    } finally {
        cursor.close();
    }

    System.out.println("\nCount:");
    long count = collection.count();
    System.out.println(count);
}

From source file:com.espertech.esper.example.marketdatafeed.FeedSimMain.java

public static void main(String[] args) throws IOException, InterruptedException {
    if (args.length < 3) {
        System.out.println(/*  w w  w .  j a  v  a 2 s.  c om*/
                "Arguments are: <number of threads> <drop probability percent> <number of seconds to run>");
        System.out.println("  number of threads: the number of threads sending feed events into the engine");
        System.out.println("  drop probability percent: a number between zero and 100 that dictates the ");
        System.out
                .println("                            probability that per second one of the feeds drops off");
        System.out.println("  number of seconds: the number of seconds the simulation runs");
        System.exit(-1);
    }

    int numberOfThreads;
    try {
        numberOfThreads = Integer.parseInt(args[0]);
    } catch (NullPointerException e) {
        System.out.println("Invalid number of threads:" + args[0]);
        System.exit(-2);
        return;
    }

    double dropProbability;
    try {
        dropProbability = Double.parseDouble(args[1]);
    } catch (NumberFormatException e) {
        System.out.println("Invalid drop probability:" + args[1]);
        System.exit(-2);
        return;
    }

    int numberOfSeconds;
    try {
        numberOfSeconds = Integer.parseInt(args[2]);
    } catch (NullPointerException e) {
        System.out.println("Invalid number of seconds to run:" + args[2]);
        System.exit(-2);
        return;
    }

    // Run the sample
    System.out.println("Using " + numberOfThreads + " threads with a drop probability of " + dropProbability
            + "%, for " + numberOfSeconds + " seconds");
    FeedSimMain feedSimMain = new FeedSimMain(numberOfThreads, dropProbability, numberOfSeconds, true,
            "FeedSimMain", false);
    feedSimMain.run();
}

From source file:de.bitocean.dspm.examples.Vertex.java

public static void main(String[] args) throws GraphIOException, FileNotFoundException, IOException {

    Reader reader = new FileReader(GRAPHML_ACTIVITY_DEPENDENCY_FILE);

    BufferedReader br = new BufferedReader(reader);
    while (br.ready()) {
        System.out.println(br.readLine());
    }/*from  w  w w  .  j  a v a  2 s .c  o  m*/

    Transformer<NodeMetadata, Vertex> vtrans = new Transformer<NodeMetadata, Vertex>() {
        public Vertex transform(NodeMetadata nmd) {
            Vertex v = new Vertex();
            v.id = nmd.getId();
            v.name = nmd.getProperty("name");
            v.expression = nmd.getProperty("expression");
            return v;
        }
    };

    Transformer<EdgeMetadata, Edge> etrans = new Transformer<EdgeMetadata, Edge>() {
        public Edge transform(EdgeMetadata emd) {
            System.out.println(emd.toString());
            Edge e = new Edge();
            try {
                e.source = emd.getSource();
            } catch (Exception ex) {

            }
            e.target = emd.getTarget();
            e.weight = Double.parseDouble(emd.getProperty("weight"));
            return e;
        }
    };

    Transformer<HyperEdgeMetadata, Edge> hetrans = new Transformer<HyperEdgeMetadata, Edge>() {
        public Edge transform(HyperEdgeMetadata emd) {
            Edge e = new Edge();
            try {
                e.source = emd.getProperty("source");
            } catch (Exception ex) {

            }
            e.target = emd.getProperty("target");
            e.weight = Double.parseDouble(emd.getProperty("weight"));
            return e;
        }
    };
    Transformer<GraphMetadata, DirectedSparseGraph<Vertex, Edge>> gtrans = new Transformer<GraphMetadata, DirectedSparseGraph<Vertex, Edge>>() {
        public DirectedSparseGraph<Vertex, Edge> transform(GraphMetadata gmd) {
            return new DirectedSparseGraph<Vertex, Edge>();
        }
    };

    GraphMLReader2<DirectedSparseGraph<Vertex, Edge>, Vertex, Edge> gmlr =
            //new GraphMLReader2<UndirectedSparseGraph<Vertex,Edge>, Vertex, Edge>(fileReader, graphTransformer, vertexTransformer, edgeTransformer, hyperEdgeTransformer)
            new GraphMLReader2<DirectedSparseGraph<Vertex, Edge>, Vertex, Edge>(reader, gtrans, vtrans, etrans,
                    hetrans);

    DirectedSparseGraph<Vertex, Edge> g = gmlr.readGraph();

    System.out.println("Number of vetex: " + g.getVertexCount());
    System.out.println("Number of edges: " + g.getEdgeCount());

    System.out.println("==========================");
    System.out.println("Vertices");
    System.out.println("==========================");
    for (Vertex v : g.getVertices()) {
        System.out.println(v);
    }

    System.out.println("==========================");
    System.out.println("Edges");
    System.out.println("==========================");
    for (Edge e : g.getEdges()) {
        System.out.println(e);
    }

}

From source file:akori.AKORI.java

public static void main(String[] args) throws IOException, InterruptedException {
    System.out.println("esto es AKORI");

    URL = "http://www.mbauchile.cl";
    PATH = "E:\\NetBeansProjects\\AKORI\\";
    NAME = "mbauchile.png";
    // Extrar DOM tree

    Document doc = Jsoup.connect(URL).timeout(0).get();

    // The Firefox driver supports javascript 
    WebDriver driver = new FirefoxDriver();
    driver.manage().window().maximize();
    System.out.println(driver.manage().window().getSize().toString());
    System.out.println(driver.manage().window().getPosition().toString());
    int xmax = driver.manage().window().getSize().width;
    int ymax = driver.manage().window().getSize().height;

    // Go to the URL page
    driver.get(URL);/* ww  w.  jav  a 2 s . c om*/

    File screen = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(screen, new File(PATH + NAME));

    BufferedImage img = ImageIO.read(new File(PATH + NAME));
    //Graphics2D graph = img.createGraphics();

    BufferedImage img1 = new BufferedImage(xmax, ymax, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graph1 = img.createGraphics();
    double[][] matrix = new double[ymax][xmax];
    BufferedReader in = new BufferedReader(new FileReader("et.txt"));
    String linea;
    double max = 0;
    graph1.drawImage(img, 0, 0, null);
    HashMap<String, Integer> lista = new HashMap<String, Integer>();
    int count = 0;
    for (int i = 0; (linea = in.readLine()) != null && i < 10000; ++i) {
        String[] datos = linea.split(",");
        int x = (int) Double.parseDouble(datos[0]);
        int y = (int) Double.parseDouble(datos[2]);
        long time = Double.valueOf(datos[4]).longValue();
        if (x >= xmax || y >= ymax)
            continue;
        if (time < 691215)
            continue;
        if (time > 705648)
            break;
        if (lista.containsKey(x + "," + y))
            lista.put(x + "," + y, lista.get(x + "," + y) + 1);
        else
            lista.put(x + "," + y, 1);
        ++count;
    }
    System.out.println(count);
    in.close();
    Iterator iter = lista.entrySet().iterator();
    Map.Entry e;
    for (String key : lista.keySet()) {
        Integer i = lista.get(key);
        if (max < i)
            max = i;
    }
    System.out.println(max);
    max = 0;
    while (iter.hasNext()) {
        e = (Map.Entry) iter.next();
        String xy = (String) e.getKey();
        String[] datos = xy.split(",");
        int x = Integer.parseInt(datos[0]);
        int y = Integer.parseInt(datos[1]);
        matrix[y][x] += (int) e.getValue();
        double aux;
        if ((aux = normalMatrix(matrix, y, x, ((int) e.getValue()) * 4)) > max) {
            max = aux;
        }
        //normalMatrix(matrix,x,y,20);
        if (matrix[y][x] > max)
            max = matrix[y][x];
    }
    int A, R, G, B, n;
    for (int i = 0; i < xmax; ++i) {
        for (int j = 0; j < ymax; ++j) {
            if (matrix[j][i] != 0) {
                n = (int) Math.round(matrix[j][i] * 100 / max);
                R = Math.round((255 * n) / 100);
                G = Math.round((255 * (100 - n)) / 100);
                B = 0;
                A = Math.round((255 * n) / 100);
                ;
                if (R > 255)
                    R = 255;
                if (R < 0)
                    R = 0;
                if (G > 255)
                    G = 255;
                if (G < 0)
                    G = 0;
                if (R < 50)
                    A = 0;
                graph1.setColor(new Color(R, G, B, A));
                graph1.fillOval(i, j, 1, 1);
            }
        }
    }
    //graph1.dispose();

    ImageIO.write(img, "png", new File("example.png"));
    System.out.println(max);

    graph1.setColor(Color.RED);
    // Extraer elementos
    Elements e1 = doc.body().getAllElements();
    int i = 1;
    ArrayList<String> tags = new ArrayList<String>();
    for (Element temp : e1) {

        if (tags.indexOf(temp.tagName()) == -1) {
            tags.add(temp.tagName());

            List<WebElement> query = driver.findElements(By.tagName(temp.tagName()));
            for (WebElement temp1 : query) {
                Point po = temp1.getLocation();
                Dimension d = temp1.getSize();
                if (d.width <= 0 || d.height <= 0 || po.x < 0 || po.y < 0)
                    continue;
                System.out.println(i + " " + temp.nodeName());
                System.out.println("  x: " + po.x + " y: " + po.y);
                System.out.println("  width: " + d.width + " height: " + d.height);
                graph1.draw(new Rectangle(po.x, po.y, d.width, d.height));
                ++i;
            }
        }
    }

    graph1.dispose();
    ImageIO.write(img, "png", new File(PATH + NAME));

    driver.quit();

}

From source file:bariopendatalab.ImportData.java

/**
 * @param args the command line arguments
 *///from   w  ww.j av a 2 s . c  o  m
public static void main(String[] args) {
    int i = 0;
    try {
        MongoClient client = new MongoClient("localhost", 27017);
        DBAccess dbaccess = new DBAccess(client);
        dbaccess.dropDB();
        dbaccess.createDB();
        FileReader reader = new FileReader(new File(args[0]));
        Iterable<CSVRecord> records = CSVFormat.EXCEL.withHeader().withIgnoreEmptyLines().withDelimiter(',')
                .parse(reader);
        i = 2;
        for (CSVRecord record : records) {
            String type = record.get("Tipologia");
            if (type == null || type.length() == 0) {
                Logger.getLogger(ImportData.class.getName()).log(Level.WARNING, "No type in line {0}", i);
            }

            String description = record.get("Nome");
            if (description != null && description.length() == 0) {
                description = null;
            }

            String address = record.get("Indirizzo");
            if (address != null && address.length() == 0) {
                address = null;
            }

            String civ = record.get("Civ");
            if (civ != null && civ.length() == 0) {
                civ = null;
            }

            if (address != null && civ != null) {
                address += ", " + civ;
            }

            String note = record.get("Note");
            if (note != null && note.length() == 0) {
                note = null;
            }

            String longitudine = record.get("Longitudine");
            String latitudine = record.get("Latitudine");
            if (longitudine != null && latitudine != null) {
                if (longitudine.length() > 0 && latitudine.length() > 0) {
                    try {
                        dbaccess.insert(type, description, address, note, Utils
                                .get2DPoint(Double.parseDouble(latitudine), Double.parseDouble(longitudine)));
                    } catch (NumberFormatException nex) {
                        dbaccess.insert(type, description, address, note, null);
                    }
                } else {
                    dbaccess.insert(type, description, address, note, null);
                }
            } else {
                dbaccess.insert(type, description, address, note, null);
            }
            i++;
        }
        reader.close();
    } catch (Exception ex) {
        Logger.getLogger(ImportData.class.getName()).log(Level.SEVERE, "Error line " + i, ex);
    }
}

From source file:com.github.jakz.geophoto.reverse.NominatimReverseGeocodingJAPI.java

public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("use -help for instructions");
    } else if (args.length < 2) {
        if (args[0].equals("-help")) {
            System.out.println("Mandatory parameters:");
            System.out.println("   -lat [latitude]");
            System.out.println("   -lon [longitude]");
            System.out.println("\nOptional parameters:");
            System.out.println("   -zoom [0-18] | from 0 (country) to 18 (street address), default 18");
            System.out.println("   -osmid       | show also osm id and osm type of the address");
            System.out.println("\nThis page:");
            System.out.println("   -help");
        } else//from w  w w .j a  va 2  s  . c  o  m
            System.err.println("invalid parameters, use -help for instructions");
    } else {
        boolean latSet = false;
        boolean lonSet = false;
        boolean osm = false;

        double lat = -200;
        double lon = -200;
        int zoom = 18;

        for (int i = 0; i < args.length; i++) {
            if (args[i].equals("-lat")) {
                try {
                    lat = Double.parseDouble(args[i + 1]);
                } catch (NumberFormatException nfe) {
                    System.out.println("Invalid latitude");
                    return;
                }

                latSet = true;
                i++;
                continue;
            } else if (args[i].equals("-lon")) {
                try {
                    lon = Double.parseDouble(args[i + 1]);
                } catch (NumberFormatException nfe) {
                    System.out.println("Invalid longitude");
                    return;
                }

                lonSet = true;
                i++;
                continue;
            } else if (args[i].equals("-zoom")) {
                try {
                    zoom = Integer.parseInt(args[i + 1]);
                } catch (NumberFormatException nfe) {
                    System.out.println("Invalid zoom");
                    return;
                }

                i++;
                continue;
            } else if (args[i].equals("-osm")) {
                osm = true;
            } else {
                System.err.println("invalid parameters, use -help for instructions");
                return;
            }
        }

        if (latSet && lonSet) {
            NominatimReverseGeocodingJAPI nominatim = new NominatimReverseGeocodingJAPI(zoom);
            Geocode address = nominatim.reverse(new Coordinate(lat, lon));
            System.out.println(address);
        } else {
            System.err.println("please specifiy -lat and -lon, use -help for instructions");
        }
    }
}