Example usage for java.lang Double valueOf

List of usage examples for java.lang Double valueOf

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static Double valueOf(double d) 

Source Link

Document

Returns a Double instance representing the specified double value.

Usage

From source file:com.example.fypv2.dataprocessor.OsmDataProcessor.java

@Override
public List<Marker> load(String rawData, int taskId, int colour) throws JSONException {
    Element root = convertToXmlDocument(rawData).getDocumentElement();

    List<Marker> markers = new ArrayList<Marker>();
    NodeList nodes = root.getElementsByTagName("node");

    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        NamedNodeMap att = node.getAttributes();
        NodeList tags = node.getChildNodes();
        for (int j = 0; j < tags.getLength(); j++) {
            Node tag = tags.item(j);
            if (tag.getNodeType() != Node.TEXT_NODE) {
                String key = tag.getAttributes().getNamedItem("k").getNodeValue();
                if (key.equals("name")) {

                    String name = tag.getAttributes().getNamedItem("v").getNodeValue();
                    String id = att.getNamedItem("id").getNodeValue();
                    double lat = Double.valueOf(att.getNamedItem("lat").getNodeValue());
                    double lon = Double.valueOf(att.getNamedItem("lon").getNodeValue());

                    Log.v(MainFrame.TAG, "OSM Node: " + name + " lat " + lat + " lon " + lon + "\n");

                    Marker ma = new NavigationMarker(id, name, lat, lon, 0,
                            "http://www.openstreetmap.org/?node=" + id, taskId, colour);
                    markers.add(ma);/*w w  w.j  ava  2 s .  c  o m*/

                    // skip to next node
                    continue;
                }
            }
        }
    }
    return markers;
}

From source file:com.fredhopper.core.connector.index.generate.validator.IntAttributeValidator.java

@Override
protected void validateValue(final FhAttributeData attribute, final List<Violation> violations) {
    final Table<Optional<String>, Optional<Locale>, String> values = attribute.getValues();
    final Map<Optional<Locale>, String> valueMap = values.row(Optional.empty());
    if (CollectionUtils.isEmpty(valueMap) || valueMap.entrySet().size() != 1
            || !valueMap.containsKey(Optional.empty())) {
        rejectValue(attribute, violations, "The \"int\" attribute value cannot be localized.");
        return;/*from   ww w.  java  2s  .  com*/
    }

    final String value = valueMap.get(Optional.empty());
    try {
        if (StringUtils.isBlank(value) || !(Integer.parseInt(value) > 0
                && Double.valueOf(Integer.MAX_VALUE).compareTo(Double.valueOf(value)) > 0)) {
            rejectValue(attribute, violations,
                    "The \"int\" attribute value is not in the supported value range.");
        }
    } catch (final NumberFormatException ex) {
        rejectValue(attribute, violations, "The \"int\" attribute value does not have the appropriate format.");
    }
}

From source file:de.unidue.ltl.flextag.features.ngram.LuceneNgramUnitTest.java

private void evaluateExtractedFeatures(File output) throws Exception {
    Gson gson = new Gson();
    FeatureStore fs = gson.fromJson(FileUtils.readFileToString(new File(output, JsonDataWriter.JSON_FILE_NAME)),
            DenseFeatureStore.class);

    assertEquals(6, fs.getNumberOfInstances());
    Iterator<Instance> iterator = fs.getInstances().iterator();
    List<Feature> setFeats = new ArrayList<Feature>();
    while (iterator.hasNext()) {
        Instance next = iterator.next();
        List<Feature> arrayList = new ArrayList<Feature>(next.getFeatures());
        for (Feature f : arrayList) {
            Double d = Double.valueOf(f.getValue().toString());
            if (d.doubleValue() > 0) {
                setFeats.add(f);//from w  w  w  .  j a v a 2s . c  o m
            }
        }
    }

    assertEquals(5, setFeats.size());

}

From source file:de.hybris.platform.b2b.punchout.populators.impl.DefaultOrderRequestCartPopulator.java

private Double getDeliveryCost(final OrderRequestHeader source) {
    if (source.getShipping() != null) {
        return Double.valueOf(source.getShipping().getMoney().getvalue());
    }/*w  w  w  .j a  v  a  2  s .  c om*/
    return new Double(0D);
}

From source file:playground.yu.utils.charts.StackedBarChart.java

/**
 * @param columnKeys//from   w  ww  .j  a v  a 2  s . c  om
 *            [ck]
 * @param values
 *            [][ck]
 */
public void addSeries(String[] rowKeys, String[] columnKeys, double[][] values) {
    for (int rowIdx = 0; rowIdx < values.length; rowIdx++) {
        for (int columnIdx = 0; columnIdx < values[rowIdx].length; columnIdx++) {
            dataset.addValue(Double.valueOf(values[rowIdx][columnIdx]), rowKeys[rowIdx], columnKeys[columnIdx]);
        }
    }
}

From source file:com.acc.facades.storefinder.populators.SearchPagePointOfServiceDistancePopulator.java

protected String getStoreUrlQueryParams(final TARGET target) {
    if (target.getLocationText() != null && !target.getLocationText().isEmpty()) {
        // Build URL to position query
        return UriComponentsBuilder.fromPath("").queryParam("lat", Double.valueOf(target.getSourceLatitude()))
                .queryParam("long", Double.valueOf(target.getSourceLongitude()))
                .queryParam("q", target.getLocationText()).build().toString();
    }/*from  w  w  w  .  j av a2s .  c  o  m*/
    // Build URL to position query
    return UriComponentsBuilder.fromPath("").queryParam("lat", Double.valueOf(target.getSourceLatitude()))
            .queryParam("long", Double.valueOf(target.getSourceLongitude())).build().toString();
}

From source file:com.fredhopper.core.connector.index.generate.validator.FloatAttributeValidator.java

@Override
protected void validateValue(final FhAttributeData attribute, final List<Violation> violations) {
    final Table<Optional<String>, Optional<Locale>, String> values = attribute.getValues();
    final Map<Optional<Locale>, String> valueMap = values.row(Optional.empty());
    if (CollectionUtils.isEmpty(valueMap) || valueMap.entrySet().size() != 1
            || !valueMap.containsKey(Optional.empty())) {
        rejectValue(attribute, violations, "The \"float\" attribute value cannot be localized.");
        return;/*  ww w . j a  v a2 s.  c om*/
    }

    final String value = valueMap.get(Optional.empty());
    try {
        if (StringUtils.isBlank(value) || !(Float.parseFloat(value) > 0
                && Double.valueOf(Float.MAX_VALUE).compareTo(Double.valueOf(value)) > 0)) {
            rejectValue(attribute, violations,
                    "The \"float\" attribute value is not in the supported value range.");
        }
    } catch (final NumberFormatException ex) {
        rejectValue(attribute, violations,
                "The \"float\" attribute value does not have the appropriate format.");
    }
}

From source file:gov.nih.nci.caintegrator.domain.annotation.StringAnnotationValue.java

private void handleNumericType(AnnotationDefinition annotationDefinition) throws ValidationException {
    NumericAnnotationValue numericValue = new NumericAnnotationValue(this, annotationDefinition);
    if (StringUtils.isBlank(stringValue)) {
        return;/*w w  w.j  av a2  s. co  m*/
    }
    if (!NumberUtils.isNumber(stringValue)) {
        throw new ValidationException("Cannot convert String value '" + stringValue + "' to a number");
    }
    numericValue.setNumericValue(Double.valueOf(stringValue));
}

From source file:datafu.pig.stats.WilsonBinConf.java

/**
 * @param x The number of positive (success) outcomes
 * @param n The number of observations//from   www  .j  a va  2s  . c  o  m
 * @return The (lower,upper) confidence interval
 */
public Tuple binconf(Long x, Long n) throws IOException {
    NormalDistribution normalDist = new NormalDistributionImpl();

    if (x == null || n == null)
        return null;
    if (x < 0 || n < 0)
        throw new IllegalArgumentException("non-negative values expected");
    if (x > n)
        throw new IllegalArgumentException("invariant violation: number of successes > number of obs");
    if (n == 0)
        return tupleFactory.newTuple(ImmutableList.of(Double.valueOf(0), Double.valueOf(0)));

    try {
        double zcrit = -1.0 * normalDist.inverseCumulativeProbability(alpha / 2);
        double z2 = zcrit * zcrit;
        double p = x / (double) n;

        double a = p + z2 / 2 / n;
        double b = zcrit * Math.sqrt((p * (1 - p) + z2 / 4 / n) / n);
        double c = (1 + z2 / n);

        double lower = (a - b) / c;
        double upper = (a + b) / c;

        // Add corrections for when x is very close to n.  This improves the estimates.
        // For more info on wilson binomial confidence interval, see paper:
        // L.D. Brown, T.T. Cai and A. DasGupta, Interval estimation for a binomial proportion (with discussion), 
        //   _Statistical Science,_*16*:101-133, 2001. 
        // http://www-stat.wharton.upenn.edu/~tcai/paper/Binomial-StatSci.pdf

        if (x == 1)
            lower = -Math.log(1 - alpha) / n;
        if (x == (n - 1))
            upper = 1 + Math.log(1 - alpha) / n;

        return tupleFactory.newTuple(ImmutableList.of(lower, upper));
    } catch (MathException e) {
        throw new IOException("math error", e);
    }
}

From source file:com.nebhale.cyclinglibrary.web.PointControllerIntegrationTest.java

@Test
public void readJson() throws Exception {
    when(this.itemRepository.read(Long.valueOf(2)))
            .thenReturn(new Item(Long.valueOf(0), Long.valueOf(1), Long.valueOf(2), "test-name",
                    "test-short-name", new Point(Double.valueOf(3), Double.valueOf(4), Double.valueOf(5))));

    this.mockMvc/*  w  w  w.java2 s  .c  o  m*/
            .perform(get("/types/{typeId}/collections/{collectionId}/items/{itemId}/points", 0, 1, 2)
                    .accept(ApplicationMediaType.POINTS_JSON)) //
            .andExpect(status().isOk()) //
            .andExpect(content().contentType(ApplicationMediaType.POINTS_JSON)) //
            .andExpect(jsonPath("$..latitude").value(Double.valueOf(3))) //
            .andExpect(jsonPath("$..longitude").value(Double.valueOf(4))) //
            .andExpect(jsonPath("$..elevation").value(Double.valueOf(5)));
}