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:com.sciaps.utils.ImportExportSpectrumCSV.java

public void exportSpectrumFile(File saveFile, RawDataSpectrum spectrum) throws IOException {
    if (spectrum == null || saveFile == null) {
        logger_.warn("", "will not save spectrum csv file");
        return;//from w  ww . j a  v a 2 s. c  o m
    }

    BufferedWriter bout = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(saveFile)));
    try {
        bout.append("wavelength, intensity");
        bout.newLine();

        double[][] data = spectrum.getRawData();

        for (int i = 0; i < data[0].length; i++) {
            bout.append(Double.toString(data[0][i]));
            bout.append(", ");
            bout.append(Double.toString(data[1][i]));
            bout.newLine();
        }
    } finally {
        bout.close();
    }

    logger_.info("saved spectrum csv file to " + saveFile.getAbsolutePath());
}

From source file:com.comcast.cdn.traffic_control.traffic_router.core.loc.Geolocation.java

public Map<String, String> getProperties() {
    final Map<String, String> map = new HashMap<String, String>();
    map.put("latitude", Double.toString(latitude));
    map.put("longitude", Double.toString(longitude));
    map.put("postalCode", postalCode);
    map.put("city", city);
    map.put("countryCode", countryCode);
    map.put("countryName", countryName);
    return map;//from   w  ww. ja va 2 s .c o m
}

From source file:org.envirocar.tools.TrackToCSV.java

public InputStream convert(InputStream in) throws IOException {
    FeatureCollection fc = new ObjectMapper().readValue(in, FeatureCollection.class);

    List<String> properties = new ArrayList<String>();

    for (Feature feature : fc.getFeatures()) {
        for (String key : feature.getProperties().getPhenomenons().keySet()) {
            if (!properties.contains(key)) {
                properties.add(key);/*w  w w  .  j a v  a  2s . c  o  m*/
            }
        }
    }

    List<String> spaceTimeProperties = new ArrayList<String>();
    spaceTimeProperties.add("longitude");
    spaceTimeProperties.add("latitude");
    spaceTimeProperties.add("time");

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));

    bw.append(createCSVHeader(properties, spaceTimeProperties));
    bw.newLine();

    for (Feature feature : fc.getFeatures()) {
        for (int i = 0; i < properties.size(); i++) {
            String key = properties.get(i);
            Map<?, ?> value = (Map<?, ?>) feature.getProperties().getPhenomenons().get(key);
            bw.append(value != null ? value.get("value").toString() : Double.toString(Double.NaN));
            bw.append(delimiter);
        }

        Point coord = (Point) feature.getGeometry();
        bw.append(Double.toString(coord.getCoordinates().getLongitude()));
        bw.append(delimiter);
        bw.append(Double.toString(coord.getCoordinates().getLatitude()));
        bw.append(delimiter);
        bw.append(feature.getProperties().getTime());

        bw.newLine();
    }

    bw.flush();
    bw.close();

    return new ByteArrayInputStream(out.toByteArray());
}

From source file:matrix.TextUrlMatrix.java

public void textUrlMatrix()
        throws UnsupportedEncodingException, FileNotFoundException, IOException, ParseException {

    double a = 0.7;
    CosSim cossim = new CosSim();
    JSONParser jParser = new JSONParser();
    BufferedReader in = new BufferedReader(new InputStreamReader(
            new FileInputStream("/Users/nSabri/Desktop/tweetMatris/userTweets.json"), "ISO-8859-9"));
    JSONArray jArray = (JSONArray) jParser.parse(in);
    BufferedReader in2 = new BufferedReader(new InputStreamReader(
            new FileInputStream("/Users/nSabri/Desktop/tweetMatris/userTweetsUrls.json"), "ISO-8859-9"));
    JSONArray jArray2 = (JSONArray) jParser.parse(in2);
    File fout = new File("/Users/nSabri/Desktop/textUrlMatris.csv");
    FileOutputStream fos = new FileOutputStream(fout);
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));

    for (int i = 0; i < 100; i++) {

        for (int j = 0; j < 100; j++) {

            JSONObject tweet1text = (JSONObject) jArray.get(i);
            JSONObject tweet2text = (JSONObject) jArray.get(j);
            JSONObject tweet1url = (JSONObject) jArray2.get(i);
            JSONObject tweet2url = (JSONObject) jArray2.get(j);
            String tweetText1 = tweet1text.get("tweets").toString();
            String tweetText2 = tweet2text.get("tweets").toString();
            String tweetUrl1 = tweet1url.get("title").toString() + tweet1url.get("meta").toString();
            String tweetUrl2 = tweet2url.get("title").toString() + tweet1url.get("meta").toString();

            double CosSimValueText = cossim.Cosine_Similarity_Score(tweetText1, tweetText2);

            double CosSimValueUrl = cossim.Cosine_Similarity_Score(tweetUrl1, tweetUrl2);

            double TextUrlSimValue = (a * CosSimValueText) + ((1 - a) * CosSimValueUrl);

            TextUrlSimValue = Double.parseDouble(new DecimalFormat("##.###").format(TextUrlSimValue));

            bw.write(Double.toString(TextUrlSimValue) + ", ");

        }//from w ww  .  ja  v  a  2s  .co m
        bw.newLine();
    }
    bw.close();

}

From source file:ml.shifu.shifu.core.binning.EqualPopulationBinningTest.java

@Test
public void testObjectSeri() {
    Random rd = new Random(System.currentTimeMillis());

    EqualPopulationBinning binning = new EqualPopulationBinning(10);
    for (int i = 0; i < 10000; i++) {
        binning.addData(Double.toString(rd.nextGaussian() % 1000));
    }//ww w  . j a v a  2 s  .c  o  m

    String binningStr = binning.objToString();
    String originalBinningData = binning.getDataBin().toString();

    ModelConfig modelConfig = new ModelConfig();
    modelConfig.getStats().setBinningMethod(BinningMethod.EqualPositive);

    ColumnConfig columnConfig = new ColumnConfig();
    columnConfig.setColumnType(ColumnType.N);

    AbstractBinning<?> otherBinning = AbstractBinning.constructBinningFromStr(modelConfig, columnConfig,
            binningStr);
    String newBinningData = otherBinning.getDataBin().toString();

    Assert.assertEquals(originalBinningData, newBinningData);
}

From source file:com.mobiaware.auction.provider.impl.CSVExportService.java

@Override
public void exportFunds(final int auctionUid, final Writer writer) throws IOException {
    List<User> users = _dataService.getUsers(auctionUid, 0, 9999, null, null);

    if (users == null) {
        throw new NotFoundException();
    }/*from w ww  . j  a  va  2  s  .c  o  m*/

    CSVWriter csvwriter = null;
    try {
        csvwriter = new CSVWriter(writer, ',');

        String[] array = { "bidder_number", "value" };
        csvwriter.writeNext(array);

        for (User user : users) {
            List<Fund> funds = _dataService.getFundsByUser(user.getUid());
            for (Fund fund : funds) {
                array[0] = user.getBidderNumber();
                array[1] = Double.toString(fund.getBidPrice());
                csvwriter.writeNext(array);
            }
        }
    } finally {
        IOUtils.closeQuietly(csvwriter);
    }

}

From source file:com.googlecode.fascinator.common.solr.SolrDoc.java

/**
 * Gets the String value of the specified field.
 *
 * <ul>//from  w w  w  .j ava2 s  . c  o  m
 *   <li>Fields that are not found will always return null.</li>
 *   <li>Single valued fields will return the value found.</li>
 *   <li>Multi valued fields return all concatenated values (bracketed
 * and quoted) if more then one entry is found, otherwise it will be
 * simply the first entry.</li>
 * </ul>
 *
 * @param field : The field name to query
 * @return String : The value found, possibly null
 */
public String get(String field) {
    Object object = this.getPath(field);

    // Doesn't exist
    if (object == null)
        return null;

    // This node is an array
    if (object instanceof JSONArray) {
        List<String> array = JsonSimple.getStringList((JSONArray) object);
        if (array.size() == 1) {
            return (String) array.get(0);
        } else {
            return "[\"" + StringUtils.join(array, "\", \"") + "\"]";
        }
    }

    // Much simpler
    if (object instanceof String) {
        return (String) object;
    }

    // Some fields can be float/double such as "score"
    if (object instanceof Double) {
        return Double.toString((Double) object);
    }

    // Shouldn't occur in a valid Solr response
    return null;
}

From source file:com.fengduo.bee.commons.util.NumberParser.java

public static double div(double a, double b, int scale) {
    if (scale < 0) {
        throw new IllegalArgumentException("The scale must be a positive integer or zero");
    }//from  ww w.  j  ava2s  .  c om
    BigDecimal b1 = new BigDecimal(Double.toString(a));
    BigDecimal b2 = new BigDecimal(Double.toString(b));
    return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
}

From source file:net.kaczmarzyk.spring.data.jpa.domain.LessThanTest.java

@Test
public void filtersByDoubleValue() {
    assertFilterContainsOnlyExpectedMembers("weightDouble",
            Double.toString(margeSimpson.getWeightDouble() + 0.0001), margeSimpson);
    assertFilterContainsOnlyExpectedMembers("weightDouble", Double.toString(margeSimpson.getWeightDouble()));
}

From source file:org.csware.ee.utils.Tools.java

public static double multiply(double v1, double v2) {
    BigDecimal b1 = new BigDecimal(Double.toString(v1));
    BigDecimal b2 = new BigDecimal(Double.toString(v2));
    return b1.multiply(b2).doubleValue();
}