Example usage for java.util Scanner nextDouble

List of usage examples for java.util Scanner nextDouble

Introduction

In this page you can find the example usage for java.util Scanner nextDouble.

Prototype

public double nextDouble() 

Source Link

Document

Scans the next token of the input as a double .

Usage

From source file:com.planetmayo.debrief.satc.util.StraightLineCullingTestForm.java

private void loadFile(File file) throws IOException {
    Scanner scanner = new Scanner(file);
    scanner.useLocale(Locale.US);
    List<List<Coordinate>> coordinates = new ArrayList<List<Coordinate>>();
    while (true) {
        try {/*from   www.  j a va2 s  . co m*/
            int num = scanner.nextInt();
            scanner.next();
            double x = scanner.nextDouble();
            double y = scanner.nextDouble();

            if (num > 0) {
                num--;
                while (coordinates.size() <= num) {
                    coordinates.add(new ArrayList<Coordinate>());
                }
                Coordinate coordinate = new Coordinate(x, y);
                coordinates.get(num).add(coordinate);
            }
        } catch (NoSuchElementException ex) {
            break;
        }
    }
    for (int i = 0; i < coordinates.size(); i++) {
        Coordinate c = coordinates.get(i).get(0);
        coordinates.get(i).add(c);
    }
    culling(coordinates);
}

From source file:uk.ac.gda.dls.client.views.ReadonlyScannableComposite.java

private void setVal(String newVal) {
    if (decimalPlaces != null) {
        Scanner sc = new Scanner(newVal.trim());
        if (sc.hasNextDouble()) {
            NumberFormat format = NumberFormat.getInstance();
            format.setMaximumFractionDigits(decimalPlaces.intValue());
            newVal = format.format(sc.nextDouble());
        }/* w  ww.j  a  v a 2  s  .c o m*/
        sc.close();
    }
    val = newVal;
    if (!isDisposed()) {
        if (minPeriodMS != null) {
            if (!textUpdateScheduled) {
                textUpdateScheduled = true;
                display.asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        display.timerExec(minPeriodMS, setTextRunnable);
                    }
                });
            }
        } else {
            display.asyncExec(setTextRunnable);
        }
    }
}

From source file:ro.hasna.ts.math.ml.distance.LongestCommonSubsequenceDistanceTest.java

@Test
public void testResultLarge() throws Exception {
    LongestCommonSubsequenceDistance lcss = new LongestCommonSubsequenceDistance(0.1, 0.05);
    int m = 128;/*  w w w  .  ja v  a 2  s .  c  o m*/
    ZNormalizer normalizer = new ZNormalizer();

    Scanner dataScanner = new Scanner(getClass().getResourceAsStream("data-100k.txt"))
            .useLocale(Locale.ENGLISH);
    double[] data = new double[m];
    double[] copy = new double[m];
    for (int i = 0; i < m && dataScanner.hasNextDouble(); i++) {
        data[i] = dataScanner.nextDouble();
    }

    Scanner queryScanner = new Scanner(getClass().getResourceAsStream("query-128.txt"))
            .useLocale(Locale.ENGLISH);
    double[] query = new double[m];
    for (int i = 0; i < m && queryScanner.hasNextDouble(); i++) {
        query[i] = queryScanner.nextDouble();
    }
    query = normalizer.normalize(query);

    double min = Double.POSITIVE_INFINITY;
    int posMin = 0;
    int n = 0;
    //        long duration = 0;
    while (dataScanner.hasNextDouble()) {
        System.arraycopy(data, 1, copy, 0, m - 1);
        copy[m - 1] = dataScanner.nextDouble();
        double[] normalizedCopy = normalizer.normalize(copy);

        //            long start = System.currentTimeMillis();
        double d = lcss.compute(normalizedCopy, query, min);
        //            duration += System.currentTimeMillis() - start;

        if (d < min) {
            min = d;
            posMin = n;
        }

        data = copy;
        n++;
    }

    //        System.out.println("duration=" + duration);

    Assert.assertEquals(93728, posMin);
    Assert.assertEquals(0.5625, min, TimeSeriesPrecision.EPSILON);
}

From source file:com.rockhoppertech.music.DurationParser.java

/**
 * Copies new events into the TimeSeries parameter - which is also returned.
 * /*from ww  w. j  a v a2s .c  o  m*/
 * @param ts
 *            a {@code TimeSeries} that will be added to
 * @param s
 *            a duration string
 * @return the same{@code TimeSeries} that you passed in
 */
public static TimeSeries getDurationAsTimeSeries(TimeSeries ts, String s) {
    String token = null;
    Scanner scanner = new Scanner(s);

    if (s.indexOf(',') != -1) {
        scanner.useDelimiter(",");
    }

    while (scanner.hasNext()) {
        if (scanner.hasNext(dpattern)) {
            token = scanner.next(dpattern);
            double d = getDottedValue(token);
            ts.add(d);
            logger.debug("'{}' is dotted value is {}", token, d);

        } else if (scanner.hasNext(pattern)) {
            token = scanner.next(pattern);
            double d = durKeyMap.get(token);
            ts.add(d);
            logger.debug("'{}' is not dotted value is {}", token, d);
            // } else if (scanner.hasNext(tripletPattern)) {
            // token = scanner.next(tripletPattern);
            // double d = durKeyMap.get(token);
            // ts.add(d);
            // System.out.println(String
            // .format("'%s' is not dotted value is %f",
            // token,
            // d));
        } else if (scanner.hasNextDouble()) {
            double d = scanner.nextDouble();
            ts.add(d);
            logger.debug("{} is a double", d);
        } else {
            // just ignore it. or throw exception?
            String skipped = scanner.next();
            logger.debug("skipped '{}'", skipped);
        }
    }
    scanner.close();
    return ts;
}

From source file:hudson.plugins.plot.XMLSeries.java

/**
 * Convert a given object into a String.
 * /*from w ww.  jav  a 2  s. c o m*/
 * @param obj
 *            Xpath Object
 * @return String representation of the node
 */
private String nodeToString(Object obj) {
    String ret = null;

    if (nodeType == XPathConstants.BOOLEAN) {
        return (((Boolean) obj)) ? "1" : "0";
    }

    if (nodeType == XPathConstants.NUMBER)
        return ((Double) obj).toString().trim();

    if (nodeType == XPathConstants.NODE || nodeType == XPathConstants.NODESET) {
        if (obj instanceof String) {
            ret = ((String) obj).trim();
        } else {
            if (null == obj) {
                return null;
            }

            Node node = (Node) obj;
            NamedNodeMap nodeMap = node.getAttributes();

            if ((null != nodeMap) && (null != nodeMap.getNamedItem("time"))) {
                ret = nodeMap.getNamedItem("time").getTextContent();
            }

            if (null == ret) {
                ret = node.getTextContent().trim();
            }
        }
    }

    if (nodeType == XPathConstants.STRING)
        ret = ((String) obj).trim();

    // for Node/String/NodeSet, try and parse it as a double.
    // we don't store a double, so just throw away the result.
    Scanner scanner = new Scanner(ret);
    if (scanner.hasNextDouble()) {
        return String.valueOf(scanner.nextDouble());
    }
    return null;
}

From source file:com.rockhoppertech.music.DurationParser.java

public static List<Double> getDurationsAsList(String durations) {
    String token = null;/*from   w ww .ja  va 2 s .c om*/
    List<Double> list = new ArrayList<Double>();
    Scanner scanner = new Scanner(durations);

    if (durations.indexOf(',') != -1) {
        scanner.useDelimiter(",");
    }

    while (scanner.hasNext()) {
        if (scanner.hasNext(dpattern)) {
            token = scanner.next(dpattern);
            double d = getDottedValue(token);
            list.add(d);
            logger.debug("'{}' is dotted value is {}", token, d);

        } else if (scanner.hasNext(pattern)) {
            token = scanner.next(pattern);
            double d = durKeyMap.get(token);
            list.add(d);
            logger.debug("'{}' is not dotted value is {}", token, d);
            // } else if (scanner.hasNext(tripletPattern)) {
            // token = scanner.next(tripletPattern);
            // double d = durKeyMap.get(token);
            // ts.add(d);
            // System.out.println(String
            // .format("'%s' is not dotted value is %f",
            // token,
            // d));
        } else if (scanner.hasNextDouble()) {
            double d = scanner.nextDouble();
            list.add(d);
            logger.debug("{} is a double", d);
        } else {
            // just ignore it. or throw exception?
            String skipped = scanner.next();
            logger.debug("skipped '{}'", skipped);
        }
    }
    scanner.close();
    return list;
}

From source file:picard.analysis.TheoreticalSensitivityTest.java

@Test
public void testHetSensDistributions() throws Exception {
    //Expect theoretical sens to be close to .9617 for Solexa-332667
    final double tolerance = 0.02;
    final double expectedResult = .9617;
    final int maxDepth = 500;
    final double[] depthDistribution = new double[maxDepth + 1];
    final double[] qualityDistribution = new double[50];

    final Scanner scanDepth = new Scanner(DEPTH);
    for (int i = 0; scanDepth.hasNextDouble(); i++) {
        depthDistribution[i] = scanDepth.nextDouble();
    }/*from   w w  w .  java 2  s .  c  om*/
    final Scanner scanBaseQ = new Scanner(BASEQ);
    for (int j = 0; scanBaseQ.hasNextDouble(); j++) {
        qualityDistribution[j] = scanBaseQ.nextDouble();
    }

    final int sampleSize = 1_000;
    final double logOddsThreshold = 3.0;
    final double result = TheoreticalSensitivity.hetSNPSensitivity(depthDistribution, qualityDistribution,
            sampleSize, logOddsThreshold);
    Assert.assertEquals(result, expectedResult, tolerance);
}

From source file:simcommunity.TheSim.java

public static void batchSim_fixedconnessioni() {

    Scanner valore = new Scanner(System.in).useLocale(Locale.US);

    double o; //omogeneit

    System.out.print("\n===================================");
    System.out.print("\nSIMULAZIONE BATCH con individui crescenti e numero di connessioni fisse\n");
    System.out.print("\n===================================");

    System.out.print("\n\nDimensione della comunit iniziale ");
    int comIniziali = valore.nextInt();

    System.out.print("Dimensione della comunit finale ");
    int comFinale = valore.nextInt();

    System.out.print("Incremento comunit ");
    int incrementocomunita = valore.nextInt();

    System.out.print("Numero collegamenti ");
    GlobalVar.numcollegamenti = valore.nextInt();

    System.out.print("Dimensione del DNA ");
    GlobalVar.dimDNA = valore.nextInt();

    System.out.print("Quante ere ");
    GlobalVar.numERE = valore.nextInt();

    System.out.print("Soglia di omogeneit ");
    GlobalVar.omoSoglia = valore.nextDouble();

    System.out.println("\nINDIVIDUI\tCONNESSIONI\tCICLI\tOMOGENEIT");

    for (int i = comIniziali; i < comFinale; i = i + incrementocomunita) {
        GlobalVar.dimensionecom = i;//from   w w  w.j a  v  a  2  s .  c o  m
        o = ciclocomunita();

        System.out.println(
                "\n" + i + "\t\t" + GlobalVar.numcollegamenti + "\t\t" + GlobalVar.ereEffettuate + "\t\t" + o);

    }

}

From source file:simcommunity.TheSim.java

public static void batchSim_fixedindividui() {

    Scanner valore = new Scanner(System.in).useLocale(Locale.US);

    double o; //omogeneit

    System.out.print("\n===================================");
    System.out.print("\nSIMULAZIONE BATCH con connessioni crescenti e numero di individui fissi\n");
    System.out.print("\n===================================");

    System.out.print("\n\nDimensione della comunit (fisso) ");
    GlobalVar.dimensionecom = valore.nextInt();

    System.out.print("Numero collegamenti iniziale ");
    int colIniziali = valore.nextInt();

    System.out.print("Numero collegamenti finale ");
    int colFinali = valore.nextInt();

    System.out.print("Incremento collegamenti ");
    int incrementocollegamenti = valore.nextInt();

    System.out.print("Dimensione del DNA ");
    GlobalVar.dimDNA = valore.nextInt();

    System.out.print("Quante ere ");
    GlobalVar.numERE = valore.nextInt();

    System.out.print("Soglia di omogeneit ");
    GlobalVar.omoSoglia = valore.nextDouble();

    System.out.println("\nINDIVIDUI\tCONNESSIONI\tCICLI\tOMOGENEIT");

    for (int i = colIniziali; i < colFinali; i = i + incrementocollegamenti) {
        GlobalVar.numcollegamenti = i;//w  w w.  j av a 2  s.  c om
        o = ciclocomunita();

        System.out.println(
                "\n" + GlobalVar.dimensionecom + "\t\t" + i + "\t\t" + GlobalVar.ereEffettuate + "\t\t" + o);

    }

}

From source file:simcommunity.TheSim.java

public static void batchSim_completa() {

    Scanner valore = new Scanner(System.in).useLocale(Locale.US);

    double o; //omogeneit

    System.out.print("\n===================================");
    System.out.print("\nSIMULAZIONE BATCH completa\n");
    System.out.print("\n===================================");

    System.out.print("\n\nNumero individui iniziale ");
    int comIniziali = valore.nextInt();

    System.out.print("Numero individui  finale ");
    int comFinale = valore.nextInt();

    System.out.print("Incremento individui ");
    int incrementocomunita = valore.nextInt();

    System.out.print("Numero collegamenti iniziale ");
    int colIniziali = valore.nextInt();

    System.out.print("Numero collegamenti finale ");
    int colFinali = valore.nextInt();

    System.out.print("Incremento collegamenti ");
    int incrementocollegamenti = valore.nextInt();

    System.out.print("Dimensione del DNA ");
    GlobalVar.dimDNA = valore.nextInt();

    System.out.print("Soglia ere massima ");
    GlobalVar.numERE = valore.nextInt();

    System.out.print("Soglia di omogeneit ");
    GlobalVar.omoSoglia = valore.nextDouble();

    //modifica/*from w  w w .  j  ava  2 s .  c  o m*/
    //System.out.println("\nind\tcon\tere\tomo");

    //Riga degli individui
    for (int i = comIniziali; i <= comFinale; i = i + incrementocomunita)
        System.out.print("\t" + i);
    System.out.println();

    for (int j = colIniziali; j <= colFinali; j = j + incrementocollegamenti) {
        System.out.print(j + "\t");
        for (int i = comIniziali; i <= comFinale; i = i + incrementocomunita) {
            GlobalVar.dimensionecom = i;
            GlobalVar.numcollegamenti = j;

            o = ciclocomunita();

            System.out.print(GlobalVar.ereEffettuate + "\t");
        }
        System.out.println();

    }

}