@Override public double getDoubleValue() throws IOException, JsonParseException { return currentNumericNode().doubleValue(); }
@Override public float getFloatValue() throws IOException, JsonParseException { return (float) currentNumericNode().doubleValue(); }
private boolean defaultValueEquals(JsonNode thatDefaultValue) { if (defaultValue == null) return thatDefaultValue == null; if (thatDefaultValue == null) return false; if (Double.isNaN(defaultValue.doubleValue())) return Double.isNaN(thatDefaultValue.doubleValue()); return defaultValue.equals(thatDefaultValue); }
public ListAssert<Double> hasJsonArrayOfDoubles() throws IOException { JsonNode array = getJsonObject(); List<Double> list = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { list.add(array.get(i).doubleValue()); } return assertThat(list); }
@Override public double getDouble() { try { if (value.isNumber()) { return value.doubleValue(); } if (value.isValueNode()) { return parseDouble(value.asText()); } } catch (NumberFormatException ignore) { // ignore } throw new PrestoException( DECODER_CONVERSION_NOT_SUPPORTED, format("could not parse value '%s' as '%s' for column '%s'", value.asText(), columnHandle.getType(), columnHandle.getName())); }
private void parseJson(String data) throws ParserConfigurationException, SAXException, IOException { ArrayList<BikeRentalStation> out = new ArrayList<BikeRentalStation>(); // Jackson ObjectMapper to read in JSON // TODO: test against real data ObjectMapper mapper = new ObjectMapper(); for (JsonNode stationNode : mapper.readTree(data)) { BikeRentalStation brStation = new BikeRentalStation(); // We need string IDs but they are in JSON as numbers. Avoid null from textValue(). See pull req #1450. brStation.id = String.valueOf(stationNode.get("id").intValue()); brStation.x = stationNode.get("lng").doubleValue() / 1000000.0; brStation.y = stationNode.get("lat").doubleValue() / 1000000.0; brStation.name = new NonLocalizedString(stationNode.get("name").textValue()); brStation.bikesAvailable = stationNode.get("bikes").intValue(); brStation.spacesAvailable = stationNode.get("free").intValue(); if (brStation != null && brStation.id != null) { out.add(brStation); } } synchronized (this) { stations = out; } }
return (D) Double.valueOf(jsonNode.doubleValue());
return ValueReference.of(value.booleanValue()); } else if (valueType == ValueType.DOUBLE && value.isDouble()) { return ValueReference.of(value.doubleValue()); } else if (valueType == ValueType.FLOAT && value.isFloat()) { return ValueReference.of(value.floatValue());
return e.decimalValue(); } else if (e.isDouble()) { return e.doubleValue(); } else if (e.isFloat()) { return e.floatValue();
if (timeout != null) { if (timeout.isNumber()) { this.timeouts = new double[]{timeout.doubleValue()}; } else { LOG.error("The 'timeout' configuration option should be a number of seconds."); int i = 0; for (JsonNode node : timeouts) { this.timeouts[i++] = node.doubleValue();
return (new FloatWritable(value.floatValue())); case DOUBLE: return (new DoubleWritable(value.doubleValue())); case DECIMAL: return (new HiveDecimalWritable(HiveDecimal.create(value.decimalValue())));
@Test public void getMeter() throws Exception { registry.meter(name("foo").tag("bar", "baz").build()).mark(); final MockHttpServletResponse resp = new MockHttpServletResponse(); servlet.doGet(new MockHttpServletRequest(), resp); final double mean_rate = JsonUtils.getMapper().readTree(resp.getContentAsString()).get(0).get("values").get("mean_rate").doubleValue(); assertTrue("Expected m1 rate of > 0, but got " + mean_rate, mean_rate > 0); }
if (!n.isNumber()) throw new AvroTypeException("Non-numeric default value for float: "+n); e.writeFloat((float) n.doubleValue()); break; case DOUBLE: if (!n.isNumber()) throw new AvroTypeException("Non-numeric default value for double: "+n); e.writeDouble(n.doubleValue()); break; case BOOLEAN:
case VALUE_NUMBER_FLOAT: out.writeIndex(JsonType.DOUBLE.ordinal()); out.writeDouble(node.doubleValue()); break; case VALUE_STRING:
return e.decimalValue(); } else if (e.isDouble()) { return e.doubleValue(); } else if (e.isFloat()) { return e.floatValue();
private QuantityValue parseQuantityValue(JsonNode node) throws DecodingException { return new QuantityValue(node.path(JSONConstants.VALUE).doubleValue(), node.path(JSONConstants.UOM).textValue()); }
@Override public void apply(Context ctx, Arguments args, Variables variables) throws CodeExecuteException { Variable var = variables.first(); double subtotalCents = var.node().path("subtotalCents").doubleValue(); StringBuilder buf = new StringBuilder(); buf.append("<span class=\"sqs-cart-subtotal\">"); CommerceUtils.writeLegacyMoneyString(subtotalCents, buf); buf.append("</span>"); var.set(buf); } }
public JsonNode call(JsonNode input, JsonNode[] arguments) { JsonNode number = arguments[0]; if (number.isNull()) return NullNode.instance; else if (!number.isNumber()) throw new JsltException("round() cannot round a non-number: " + number); return new LongNode(Math.round(number.doubleValue())); } }
protected SweAbstractDataComponent decodeQuantity(JsonNode node) { SweQuantity swe = new SweQuantity(); if (node.hasNonNull(JSONConstants.VALUE)) { swe.setValue(node.path(JSONConstants.VALUE).doubleValue()); } return swe.setUom(node.path(JSONConstants.UOM).textValue()); }
@Override public void configure(JsonNode config) { ObjectNode defaultConfig = defaultConfig(); setAllMissingFields((ObjectNode) config, defaultConfig); checkConfig((ObjectNode)config); this.config = (ObjectNode) config; maxRetries = config.get(MAX_RETRIES).intValue(); initialDelay = config.get(INITIAL_DELAY).intValue(); maxDelay = config.get(MAX_DELAY).intValue(); backoffFactor = config.get(BACKOFF_FACTOR).doubleValue(); }