Example usage for java.lang Double toString

List of usage examples for java.lang Double toString

Introduction

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

Prototype

public static String toString(double d) 

Source Link

Document

Returns a string representation of the double argument.

Usage

From source file:playground.dgrether.analysis.charts.DgModalSplitDiffQuantilesChart.java

private void calculateData() {
    List<DgAnalysisPopulation> quantiles = this.ana.getQuantiles(this.nQuantiles,
            new DgPersonDataIncomeComparator());
    List<String> labels = new ArrayList<String>();
    int column = 0;
    for (DgAnalysisPopulation p : quantiles) {
        p.calculateMinMaxIncome();//w  w w  .  ja va2 s  .c o m
        double carPlans1 = p.calculateNumberOfCarPlans(runId1);
        double carPlans2 = p.calculateNumberOfCarPlans(runId2);
        int groupSize = p.getPersonData().size();
        double carFraction = (carPlans2 - carPlans1) / groupSize * 100.0;
        double ptFraction = (carPlans1 - carPlans2) / groupSize * 100;
        String title = Double.toString(p.getMaxIncome());
        title = title.substring(0, title.indexOf("."));
        this.dataset.addValue(carFraction, "car", title);
        this.dataset.addValue(ptFraction, "non-car", title);
        if (carFraction != 0.0) {
            String s = Double.toString(carFraction);
            this.labelgenerator.addLabel(0, column, s.substring(0, s.lastIndexOf(".") + 2));
            s = Double.toString(ptFraction);
            this.labelgenerator.addLabel(1, column, s.substring(0, s.lastIndexOf(".") + 2));
        }
        column++;
    }
}

From source file:by.zatta.pilight.model.Origin.java

public static void parse(JSONObject jMessage) {
    // Log.v(TAG, jMessage.toString());

    Iterator<?> fit = jMessage.keys();
    /* Iterate through all entries */
    while (fit.hasNext()) {
        String firstKey = (String) fit.next();
        try {/*  w ww .  j av  a 2  s  .c  om*/
            JSONObject jSecond = jMessage.getJSONObject(firstKey);
            // Log.v(TAG, "firstKey: " + firstKey); //devices, values
            // Log.v(TAG, "jSecond: "+ jSecond.toString()); // {"living":["KamerTemp"]} & {"temperature":"20062"}

            if (firstKey.equals("devices")) {
                Iterator<?> sit = jSecond.keys();
                while (sit.hasNext()) {
                    String secondKey = (String) sit.next();
                    JSONArray jSecArr = jSecond.optJSONArray(secondKey);
                    String jSecStr = jSecond.optString(secondKey);

                    if (jSecArr != null) {
                        /* Iterate through all values for this setting */
                        for (Short i = 0; i < jSecArr.length(); i++) {
                            // Log.v(TAG, "Uit array:" + jSecArr.get(i).toString());
                            originEntry.setNameID(jSecArr.get(i).toString());
                        }
                    } else if (jSecStr != null) {
                        // Log.v(TAG, "Uit string: " + jSecStr);
                        originEntry.setNameID(jSecStr);
                    }
                }
            }
            if (firstKey.equals("values")) {
                Iterator<?> sit = jSecond.keys();
                List<SettingEntry> settings = new ArrayList<SettingEntry>();

                while (sit.hasNext()) {
                    String secondKey = (String) sit.next();
                    JSONArray jSecArr = jSecond.optJSONArray(secondKey);
                    String jSecStr = jSecond.optString(secondKey);
                    Double jSecDbl = jSecond.optDouble(secondKey);
                    Long jSecLng = jSecond.optLong(secondKey);

                    SettingEntry sentry = new SettingEntry();
                    if (jSecArr != null) {
                        /* Iterate through all values for this setting */
                        for (Short i = 0; i < jSecArr.length(); i++) {
                            // Log.v(TAG, "Uit array:" + jSecArr.get(i).toString());
                            sentry.setKey(secondKey);
                            sentry.setValue(jSecArr.get(i).toString());
                        }
                    } else if (jSecStr != null) {
                        // Log.v(TAG, "Uit string: " + jSecStr);
                        sentry.setKey(secondKey);
                        sentry.setValue(jSecStr);
                    } else if (jSecDbl != null) {
                        // Log.v(TAG, "Uit string: " + jSecStr);
                        sentry.setKey(secondKey);
                        sentry.setValue(Double.toString(jSecDbl));
                    } else if (jSecLng != null) {
                        // Log.v(TAG, "Uit string: " + jSecStr);
                        sentry.setKey(secondKey);
                        sentry.setValue(Long.toString(jSecLng));
                    }
                    settings.add(sentry);
                }
                originEntry.setSettings(settings);
            }
        } catch (JSONException e) {
        }
    }
}

From source file:com.wormsim.tracking.TrackedDouble.java

@Override
public String toBetweenVarianceString() {
    return Double.toString(this.getBetweenVariance());
}

From source file:com.netflix.curator.framework.recipes.queue.TestDistributedIdQueue.java

@Test
public void testOrdering() throws Exception {
    final int ITEM_QTY = 100;

    DistributedIdQueue<TestQueueItem> queue = null;
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    client.start();//from   w  w  w .  j  a v  a  2s.  c  om
    try {
        BlockingQueueConsumer<TestQueueItem> consumer = new BlockingQueueConsumer<TestQueueItem>(
                Mockito.mock(ConnectionStateListener.class));

        queue = QueueBuilder.builder(client, consumer, serializer, QUEUE_PATH).buildIdQueue();
        queue.start();

        List<String> ids = Lists.newArrayList();
        for (int i = 0; i < ITEM_QTY; ++i) {
            String id = Double.toString(Math.random());
            ids.add(id);
            queue.put(new TestQueueItem(id), id);
        }

        int iteration = 0;
        while (consumer.size() < ITEM_QTY) {
            Assert.assertTrue(++iteration < ITEM_QTY);
            Thread.sleep(1000);
        }

        int i = 0;
        for (TestQueueItem item : consumer.getItems()) {
            Assert.assertEquals(item.str, ids.get(i++));
        }
    } finally {
        IOUtils.closeQuietly(queue);
        IOUtils.closeQuietly(client);
    }
}

From source file:com.hp.hpl.jena.sparql.util.Utils.java

static public String stringForm(double d) {
    if (Double.isInfinite(d)) {
        if (d < 0)
            return "-INF";
        return "INF";
    }/*from ww  w  . j  a v a  2  s  . co m*/

    if (Double.isNaN(d))
        return "NaN";

    // Otherwise, SPARQL form always has "e0"
    String x = Double.toString(d);
    if ((x.indexOf('e') != -1) || (x.indexOf('E') != -1))
        return x;
    // Renormalize?
    return x + "e0";
}

From source file:geva.Operator.RampedFullGrowInitialiser.java

@Override
public void setProperties(Properties p) {
    super.setProperties(p);
    double value;
    String key = Constants.GROW_PROBABILITY;
    try {/*from www .j av  a 2  s. c  o  m*/
        value = Double.parseDouble(p.getProperty(key));
        if (value < 0.0 || value > 1.0) {
            throw new BadParameterException(key);
        }
    } catch (Exception e) {
        value = 0.5;
        p.setProperty(key, Double.toString(value));
        logger.warn(e + " using default: " + value, e);
    }
    this.growProb = value;
    int valueI;
    key = Constants.MAX_DEPTH;
    try {
        valueI = Integer.parseInt(p.getProperty(key));
        if (valueI < 1) {
            throw new BadParameterException(key);
        }
    } catch (Exception e) {
        valueI = 10;
        p.setProperty(key, Integer.toString(valueI));
        logger.warn(e + " using default: " + valueI, e);
    }
    this.maxDepth = valueI;
}

From source file:de.kopis.glacier.util.VaultInventoryPrinter.java

private String humanReadableSize(final String size) throws IllegalArgumentException {
    final String[] sanitizedSize = sanitize(size);
    double sizeAsDouble = 0;
    try {//from   w  ww .ja  va  2 s.  c  o m
        // parse as US value, because WTF? java default?
        sizeAsDouble = NumberFormat.getInstance(Locale.US).parse(sanitizedSize[0]).doubleValue();
    } catch (final ParseException e) {
        throw new IllegalArgumentException("Can not parse Number", e);
    }
    String humanReadableSize = "";
    String sizeClass = sanitizedSize[1];
    if (sizeAsDouble > 1024) {
        sizeClass = getLargerSizeClass(sanitizedSize[1]);
        humanReadableSize = humanReadableSize(sizeAsDouble / 1024.0 + " " + sizeClass);
    } else {
        humanReadableSize = round(Double.toString(sizeAsDouble), 2, BigDecimal.ROUND_UP) + sizeClass;
    }
    return humanReadableSize;
}

From source file:net.sf.sessionAnalysis.SessionVisitorSessionLengthNanosStatistics.java

public void writeSessionsOverTime(final String outputDir) throws IOException {
    FileWriter fw = new FileWriter(
            outputDir + "/" + this.getClass().getSimpleName() + "-sessionLengthsNanoSeconds.csv");
    BufferedWriter writer = new BufferedWriter(fw);

    writer.write("lengthNanos");
    writer.newLine();/*from  w ww  . j a  v  a  2  s .  c  o m*/
    for (double l : this.computeLengthVector()) {
        writer.write(Double.toString(l));
        writer.newLine();
    }

    writer.close();
    fw.close();
}

From source file:com.dianping.cat.report.page.business.graph.CustomDataCalculator.java

public double[] calculate(String pattern, List<CustomInfo> customInfos, Map<String, double[]> businessItemData,
        int totalSize) {
    double[] result = new double[totalSize];

    for (int i = 0; i < totalSize; i++) {
        try {/*www  . j a v a  2 s.co m*/
            String expression = pattern;

            for (CustomInfo customInfo : customInfos) {
                String customPattern = customInfo.getPattern();
                String itemId = m_keyHelper.generateKey(customInfo.getKey(), customInfo.getDomain(),
                        customInfo.getType());
                double[] sourceData = businessItemData.get(itemId);

                if (sourceData != null) {
                    expression = expression.replace(customPattern, Double.toString(sourceData[i]));
                }
            }

            result[i] = calculate(expression);
        } catch (JexlException ex) {
            // Ignore
        } catch (Exception e) {
            Cat.logError(e);
        }
    }
    return result;
}

From source file:ixa.pipe.wikify.DBpediaSpotlightClient.java

public Document extract(Text text, String host, String port) throws AnnotationException {

    LOG.info("Querying API.");
    String spotlightResponse = "";
    Document doc = null;//from   ww w  .  ja  v  a2s  .c o m
    try {
        String url = host + ":" + port + "/rest/annotate";
        PostMethod method = new PostMethod(url);
        method.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
        NameValuePair[] params = { new NameValuePair("text", text.text()),
                new NameValuePair("confidence", Double.toString(CONFIDENCE)),
                new NameValuePair("support", Integer.toString(SUPPORT)),
                new NameValuePair("coreferenceResolution", Boolean.toString(COREFERENCE)) };
        method.setRequestBody(params);
        method.setRequestHeader(new Header("Accept", "text/xml"));
        spotlightResponse = request(method);
        doc = loadXMLFromString(spotlightResponse);
    } catch (javax.xml.parsers.ParserConfigurationException ex) {
    } catch (org.xml.sax.SAXException ex) {
    } catch (java.io.IOException ex) {
    }

    return doc;
}