/** * Method that will try to convert value of this node to a Java <b>double</b>. * Numbers are coerced using default Java rules; booleans convert to 0.0 (false) * and 1.0 (true), and Strings are parsed using default Java language integer * parsing rules. *<p> * If representation can not be converted to an int (including structured types * like Objects and Arrays), * default value of <b>0.0</b> will be returned; no exceptions are thrown. * * @since 1.9 (replaces <code>getValueAsDouble</code>) */ public double asDouble() { return asDouble(0.0); }
/** * Method that will try to convert value of this node to a Java <b>double</b>. * Numbers are coerced using default Java rules; booleans convert to 0.0 (false) * and 1.0 (true), and Strings are parsed using default Java language integer * parsing rules. *<p> * If representation can not be converted to an int (including structured types * like Objects and Arrays), * default value of <b>0.0</b> will be returned; no exceptions are thrown. * * @since 1.6 * * @deprecated Since 1.9, use {@link #asDouble} instead */ @Deprecated public double getValueAsDouble() { return asDouble(0.0); }
/** * Method that will try to convert value of this node to a Java <b>double</b>. * Numbers are coerced using default Java rules; booleans convert to 0.0 (false) * and 1.0 (true), and Strings are parsed using default Java language integer * parsing rules. *<p> * If representation can not be converted to an int (including structured types * like Objects and Arrays), * specified <b>defaultValue</b> will be returned; no exceptions are thrown. * * @since 1.6 * * @deprecated Since 1.9, use {@link #asDouble} instead */ @Deprecated public double getValueAsDouble(double defaultValue) { return asDouble(defaultValue); }
return node.asLong(); } else if (node.isDouble()) { return node.asDouble(); } else { System.err.println("ERROR What is this!? " + node.getNumberType());
/** * Method that will try to convert value of this node to a Java <b>double</b>. * Numbers are coerced using default Java rules; booleans convert to 0.0 (false) * and 1.0 (true), and Strings are parsed using default Java language integer * parsing rules. *<p> * If representation can not be converted to an int (including structured types * like Objects and Arrays), * default value of <b>0.0</b> will be returned; no exceptions are thrown. * * @since 1.9 (replaces <code>getValueAsDouble</code>) */ public double asDouble() { return asDouble(0.0); }
assertEquals("fcfs", pool2.get("schedulingPolicy").asText()); assertEquals(7, pool2.get("parallelism").asInt()); assertEquals(0.7, pool2.get("allocFraction").asDouble(), 0.00001); assertTrue(pool2.get("triggers").isArray()); assertEquals(0, pool2.get("triggers").size()); assertEquals("fair", pool1.get("schedulingPolicy").asText()); assertEquals(3, pool1.get("parallelism").asInt()); assertEquals(0.3, pool1.get("allocFraction").asDouble(), 0.00001); assertTrue(pool1.get("triggers").isArray()); assertEquals(1, pool1.get("triggers").size());
/** * Method that will try to convert value of this node to a Java <b>double</b>. * Numbers are coerced using default Java rules; booleans convert to 0.0 (false) * and 1.0 (true), and Strings are parsed using default Java language integer * parsing rules. *<p> * If representation can not be converted to an int (including structured types * like Objects and Arrays), * specified <b>defaultValue</b> will be returned; no exceptions are thrown. * * @since 1.6 * * @deprecated Since 1.9, use {@link #asDouble} instead */ @Deprecated public double getValueAsDouble(double defaultValue) { return asDouble(defaultValue); }
/** * Method that will try to convert value of this node to a Java <b>double</b>. * Numbers are coerced using default Java rules; booleans convert to 0.0 (false) * and 1.0 (true), and Strings are parsed using default Java language integer * parsing rules. *<p> * If representation can not be converted to an int (including structured types * like Objects and Arrays), * default value of <b>0.0</b> will be returned; no exceptions are thrown. * * @since 1.6 * * @deprecated Since 1.9, use {@link #asDouble} instead */ @Deprecated public double getValueAsDouble() { return asDouble(0.0); }
public double asDouble() { return delegate.asDouble(); }
public double asDouble(final double defaultValue) { return delegate.asDouble(defaultValue); }
@Override protected FloatBuffer deserialize(final ArrayNode input) throws JsonProcessingException { final FloatBuffer result = FloatBuffer.allocate(input.size()); for(final JsonNode node: input) result.put((float) node.asDouble()); return result; } }
@Override public String parseTicker(JsonNode node, Pair pair) throws IOException, NoMarketDataException { for(JsonNode n : node.get("quotes")){ if(n.get("ticker").asText().toUpperCase().equals(pair.getCoin()) && n.get("base").asText().toUpperCase().equals(pair.getExchange())){ if(pair.getExchange().equals("USD") || pair.getExchange().equals("CAD")) return Double.toString(n.get("last").asDouble()/100); else return Double.toString(n.get("last").asDouble()/1000000); } } throw new NoMarketDataException(pair); }
@Override protected DoubleBuffer deserialize(final ArrayNode input) throws JsonProcessingException { final DoubleBuffer result = DoubleBuffer.allocate(input.size()); for(final JsonNode node: input) result.put(node.asDouble()); return result; } }
@Override Float parse() throws ParseException { final JsonNode value = node.path(BOOST_PROPERTY); if (value.isFloatingPointNumber()) { return (float) value.asDouble(); } throw new ParseException("Invalid property '" + BOOST_PROPERTY + "': value is not a float"); }
@Override Float parse() throws ParseException { final JsonNode value = node.path(BOOST_PROPERTY); if (value.isFloatingPointNumber()) { return (float) value.asDouble(); } throw new ParseException("Invalid property '" + BOOST_PROPERTY + "': value is not a float"); }
@Test public void parseReturnsCorrectJsonNode() throws Exception { JsonNode jsonNode = Json.parse(JSON_STRING); assertThat(jsonNode.get("key").asText(), is(equalTo("value"))); assertThat(jsonNode.get("1").asText(), is(equalTo("value2"))); assertThat(jsonNode.get("3").asBoolean(), is(equalTo(true))); assertThat(jsonNode.get("double").asDouble(), is(equalTo(1.2))); assertThat(jsonNode.get("").asText(), is(equalTo("null"))); }
@Test public void parseNonStandardJsonReturnsCorrectJsonNode() throws Exception { JsonNode jsonNode = Json.parse(NONSTANDARD_JSON_STRING); assertThat(jsonNode.get("key").asText(), is(equalTo("value"))); assertThat(jsonNode.get("1").asText(), is(equalTo("value2"))); assertThat(jsonNode.get("3").asBoolean(), is(equalTo(true))); assertThat(jsonNode.get("double").asDouble(), is(equalTo(1.2))); assertThat(jsonNode.get("").asText(), is(equalTo("null"))); }
@Test public void toJsonCreatesValidJsonNode() throws Exception { JsonNode jsonNode = Json.toJson(createData()); assertThat(jsonNode.get("key").asText(), is(equalTo("value"))); assertThat(jsonNode.get("1").asText(), is(equalTo("value2"))); assertThat(jsonNode.get("3").asBoolean(), is(equalTo(true))); assertThat(jsonNode.get("double").asDouble(), is(equalTo(1.2))); assertThat(jsonNode.get("").asText(), is(equalTo("null"))); }