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 String toString() 

Source Link

Document

Returns a string representation of this Double object.

Usage

From source file:com.yoncabt.abys.core.util.EBRConf.java

public Double getValue(String key, Double defaultValue) {
    String ret = getValueFromAll(key, defaultValue == null ? null : defaultValue.toString());
    return ret == null ? null : Double.valueOf(ret);
}

From source file:ml.shifu.shifu.util.JexlTest.java

@Test
public void testDoubleFormat() {
    Double a = Double.NaN;
    DecimalFormat df = new DecimalFormat("##.######");

    Assert.assertEquals("NaN", a.toString());
    Assert.assertFalse(df.format(a).equals("NaN"));
}

From source file:org.killbill.billing.plugin.avatax.client.AvaTaxClient.java

public GeoTaxResult estimateTax(final Double latitude, final Double longitude, final Double saleAmount)
        throws AvaTaxClientException {
    try {//from w  ww . ja  v a 2s.com
        return doCall(GET, url + "/1.0/tax/" + latitude.toString() + "," + longitude.toString() + "/get", null,
                ImmutableMap.<String, String>of("saleamount", saleAmount.toString()), GeoTaxResult.class);
    } catch (final InterruptedException e) {
        throw new AvaTaxClientException(e);
    } catch (final ExecutionException e) {
        throw new AvaTaxClientException(e);
    } catch (final TimeoutException e) {
        throw new AvaTaxClientException(e);
    } catch (final IOException e) {
        throw new AvaTaxClientException(e);
    } catch (final URISyntaxException e) {
        throw new AvaTaxClientException(e);
    } catch (final InvalidRequest e) {
        try {
            return deserializeResponse(e.getResponse(), GeoTaxResult.class);
        } catch (final IOException e1) {
            throw new AvaTaxClientException(e1);
        }
    }
}

From source file:org.drools.planner.benchmark.statistic.BestScoreStatistic.java

private CharSequence writeCsvStatistic(File solverStatisticFilesDirectory, String baseName) {
    List<TimeToBestScoresLine> timeToBestScoresLineList = extractTimeToBestScoresLineList();
    File csvStatisticFile = new File(solverStatisticFilesDirectory, baseName + "Statistic.csv");
    Writer writer = null;//  www. java 2 s .  c  o  m
    try {
        writer = new OutputStreamWriter(new FileOutputStream(csvStatisticFile), "utf-8");
        writer.append("\"TimeMillisSpend\"");
        for (String configName : configNameList) {
            writer.append(",\"").append(configName.replaceAll("\\\"", "\\\"")).append("\"");
        }
        writer.append("\n");
        for (TimeToBestScoresLine timeToBestScoresLine : timeToBestScoresLineList) {
            writer.write(Long.toString(timeToBestScoresLine.getTimeMillisSpend()));
            for (String configName : configNameList) {
                writer.append(",");
                Score score = timeToBestScoresLine.getConfigNameToScoreMap().get(configName);
                if (score != null) {
                    Double scoreGraphValue = scoreDefinition.translateScoreToGraphValue(score);
                    if (scoreGraphValue != null) {
                        writer.append(scoreGraphValue.toString());
                    }
                }
            }
            writer.append("\n");
        }
    } catch (IOException e) {
        throw new IllegalArgumentException("Problem writing csvStatisticFile: " + csvStatisticFile, e);
    } finally {
        IOUtils.closeQuietly(writer);
    }
    return "  <p><a href=\"" + csvStatisticFile.getName() + "\">CVS file</a></p>\n";
}

From source file:blue.soundObject.jmask.ItemList.java

public Element saveAsXML() {
    Element retVal = new Element("generator");
    retVal.setAttribute("type", getClass().getName());

    retVal.addElement(XMLUtilities.writeInt("listType", getListType()));
    retVal.addElement(XMLUtilities.writeInt("index", index));
    retVal.addElement(XMLUtilities.writeInt("direction", direction));

    Element items = new Element("listItems");

    for (Iterator it = listItems.iterator(); it.hasNext();) {
        Double item = (Double) it.next();

        items.addElement("item").setText(item.toString());
    }//from   w  w w .  ja  v  a  2  s .c  o m

    retVal.addElement(items);

    return retVal;
}

From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.util.CSVFileReader.java

public int read(BufferedReader csvReader, SDIOMetadata smd, PrintWriter pwout) throws IOException {
    dbgLog.warning("CSVFileReader: Inside CSV File Reader");

    //DataTable csvData = new DataTable();
    int varQnty = 0;

    try {/*www.  j av  a2 s.  c om*/
        varQnty = new Integer(smd.getFileInformation().get("varQnty").toString());
    } catch (Exception ex) {
        //return -1;
        throw new IOException("CSV File Reader: Could not obtain varQnty from the dataset metadata.");
    }

    if (varQnty == 0) {
        //return -1;
        throw new IOException("CSV File Reader: varQnty=0 in the dataset metadata!");
    }

    String[] caseRow = new String[varQnty];

    String line;
    String[] valueTokens;

    int lineCounter = 0;

    boolean[] isCharacterVariable = smd.isStringVariable();
    boolean[] isContinuousVariable = smd.isContinuousVariable();
    boolean[] isDateVariable = smd.isDateVariable();

    dbgLog.fine("CSV reader; varQnty: " + varQnty);
    dbgLog.fine("CSV reader; delimiter: " + delimiterChar);

    while ((line = csvReader.readLine()) != null) {
        // chop the line:
        line = line.replaceFirst("[\r\n]*$", "");
        valueTokens = line.split("" + delimiterChar, -2);

        if (valueTokens == null) {
            throw new IOException("Failed to read line " + (lineCounter + 1) + " of the Data file.");

        }

        if (valueTokens.length != varQnty) {
            throw new IOException("Reading mismatch, line " + (lineCounter + 1) + " of the Data file: "
                    + varQnty + " delimited values expected, " + valueTokens.length + " found.");
        }

        //dbgLog.fine("case: "+lineCounter);

        for (int i = 0; i < varQnty; i++) {
            //dbgLog.fine("value: "+valueTokens[i]);

            if (isCharacterVariable[i]) {
                // String. Adding to the table, quoted.
                // Empty strings stored as " " (one white space):
                if (valueTokens[i] != null && (!valueTokens[i].equals(""))) {
                    String charToken = valueTokens[i];
                    // Dealing with quotes: 
                    // remove the leading and trailing quotes, if present:
                    charToken = charToken.replaceFirst("^\"", "");
                    charToken = charToken.replaceFirst("\"$", "");
                    // escape the remaining ones:
                    charToken = charToken.replace("\"", "\\\"");
                    // final pair of quotes:
                    if (isDateVariable == null || (!isDateVariable[i])) {
                        charToken = "\"" + charToken + "\"";
                    }
                    caseRow[i] = charToken;
                } else {
                    if (isDateVariable == null || (!isDateVariable[i])) {
                        caseRow[i] = "\" \"";
                    } else {
                        caseRow[i] = "";
                    }
                }

            } else if (isContinuousVariable[i]) {
                // Numeric, Double:
                // special cases first: R NA (missing value) and NaN
                // (Not A Number value):
                dbgLog.fine("CSV reader; double value: " + valueTokens[i]);
                if (valueTokens[i] != null && valueTokens[i].equalsIgnoreCase("NA")) {
                    caseRow[i] = "";
                } else if (valueTokens[i] != null && valueTokens[i].equalsIgnoreCase("NaN")) {
                    caseRow[i] = "NaN";
                } else {
                    try {
                        Double testDoubleValue = new Double(valueTokens[i]);
                        caseRow[i] = testDoubleValue.toString();//valueTokens[i];
                    } catch (Exception ex) {
                        dbgLog.fine("caught exception reading numeric value; variable: " + i + ", case: "
                                + lineCounter + "; value: " + valueTokens[i]);

                        //dataTable[i][lineCounter] = (new Double(0)).toString();
                        caseRow[i] = "";
                    }
                }
            } else {
                // Numeric, Integer:
                // One special case first: R NA (missing value) needs to be 
                // converted into the DVN's missing value - an empty String;
                // (strictly speaking, this isn't necessary - an attempt to 
                // create an Integer object from the String "NA" would
                // result in an exception, that would be intercepted below,
                // with the same end result)
                if (valueTokens[i] != null && valueTokens[i].equalsIgnoreCase("NA")) {
                    caseRow[i] = "";
                } else {
                    try {
                        Integer testIntegerValue = new Integer(valueTokens[i]);
                        caseRow[i] = testIntegerValue.toString();
                    } catch (Exception ex) {
                        dbgLog.fine("caught exception reading numeric value; variable: " + i + ", case: "
                                + lineCounter + "; value: " + valueTokens[i]);

                        //dataTable[i][lineCounter] = "0";
                        caseRow[i] = "";
                    }
                }
            }
        }

        pwout.println(StringUtils.join(caseRow, "\t"));

        lineCounter++;
    }

    //csvData.setData(dataTable);
    //return csvData;

    pwout.close();
    return lineCounter;
}

From source file:ch.zhaw.icclab.tnova.expressionsolver.OTFlyEval.java

String findMin(LinkedList<Double> paramList) {
    Double min = paramList.peekFirst();
    for (int i = 0; i < paramList.size(); i++) {
        if (min > paramList.get(i))
            min = paramList.get(i);//w  w w.  j  a  v a 2s.  c o m
    }
    return min.toString();
}

From source file:ch.zhaw.icclab.tnova.expressionsolver.OTFlyEval.java

String findMax(LinkedList<Double> paramList) {
    Double max = paramList.peekFirst();
    for (int i = 0; i < paramList.size(); i++) {
        if (max < paramList.get(i))
            max = paramList.get(i);//from   www.j  a  va  2 s.  c  om
    }
    return max.toString();
}

From source file:org.drools.planner.benchmark.statistic.bestscore.BestScoreStatistic.java

private CharSequence writeCsvStatistic(File solverStatisticFilesDirectory, String baseName) {
    List<BestScoreScvLine> scvLineList = extractCsvLineList();
    File csvStatisticFile = new File(solverStatisticFilesDirectory, baseName + "BestScoreStatistic.csv");
    Writer writer = null;/*from  ww w .  ja  va 2  s .  c o  m*/
    try {
        writer = new OutputStreamWriter(new FileOutputStream(csvStatisticFile), "utf-8");
        writer.append("\"TimeMillisSpend\"");
        for (String configName : configNameList) {
            writer.append(",\"").append(configName.replaceAll("\\\"", "\\\"")).append("\"");
        }
        writer.append("\n");
        for (BestScoreScvLine line : scvLineList) {
            writer.write(Long.toString(line.getTimeMillisSpend()));
            for (String configName : configNameList) {
                writer.append(",");
                Score score = line.getConfigNameToScoreMap().get(configName);
                if (score != null) {
                    Double scoreGraphValue = scoreDefinition.translateScoreToGraphValue(score);
                    if (scoreGraphValue != null) {
                        writer.append(scoreGraphValue.toString());
                    }
                }
            }
            writer.append("\n");
        }
    } catch (IOException e) {
        throw new IllegalArgumentException("Problem writing csvStatisticFile: " + csvStatisticFile, e);
    } finally {
        IOUtils.closeQuietly(writer);
    }
    return "  <p><a href=\"" + csvStatisticFile.getName() + "\">CVS file</a></p>\n";
}

From source file:org.envirocar.harvest.DummyTrackCreator.java

private void publishTracks() throws ClientProtocolException, IOException {
    int count = 0;
    Double lat = -89.195;
    Double lon = -179.195;//from w  ww . j  a va2s .  c o m

    StringBuilder sb;
    Integer lonCount = 10000;
    while (lon < 180) {
        sb = new StringBuilder();
        sb.append(startTemplate.replace("${trackId}", lonCount.toString()));

        while (lat < 90) {
            sb.append(featureTemplate.replace("${lat}", lat.toString()).replace("${lon}", lon.toString()));
            count++;
            lat += 0.15;
        }

        sb.deleteCharAt(sb.length() - 1);
        sb.append(endTemplate);

        pushToConsumer(sb.toString());

        lat = -89.125;
        lon += 0.15;
        lonCount++;

        logger.info("finished longitude {}; pushed track #: {} ", lon, (lonCount - 10000));
    }

    logger.info("Total feature count: {}", count);
}