List of usage examples for com.fasterxml.jackson.databind.node DoubleNode DoubleNode
public DoubleNode(double paramDouble)
From source file:com.mapr.synth.samplers.GammaSampler.java
@Override public JsonNode sample() { return new DoubleNode(rand.nextDouble()); }
From source file:com.redhat.lightblue.query.ValueTest.java
/** * Test of toJson method, of class Value. */// ww w .ja v a 2s . c o m @Test public void testToJson() throws IOException { // if in int range returns IntNode Value instance = new Value(10L); JsonNode expResult = new IntNode(10); JsonNode result = instance.toJson(); assertEquals(expResult, result); instance = new Value(Long.MAX_VALUE); expResult = new LongNode(Long.MAX_VALUE); result = instance.toJson(); assertEquals(expResult, result); instance = new Value(10.0D); expResult = new DoubleNode(10.0D); result = instance.toJson(); assertEquals(expResult, result); instance = new Value(3.0F); expResult = new FloatNode(3.0F); result = instance.toJson(); assertEquals(expResult, result); }
From source file:es.bsc.amon.util.tree.TreeNodeFactory.java
public static JsonNode toJson(TreeNode n) { JsonNode json = null;// w w w .ja v a2s. c om if (n instanceof ObjNode) { json = new ObjectNode(JsonNodeFactory.instance); for (Map.Entry<String, TreeNode> e : ((ObjNode) n).properties.entrySet()) { ((ObjectNode) json).put(e.getKey(), toJson(e.getValue())); } } else if (n instanceof NodeArray) { json = new ArrayNode(JsonNodeFactory.instance); for (TreeNode ne : ((NodeArray) n).elements) { ((ArrayNode) json).add(toJson(ne)); } } else if (n instanceof StringValue) { json = new TextNode(((StringValue) n).value); } else if (n instanceof NumberValue) { Number val = ((NumberValue) n).value; if (val instanceof Byte || val instanceof Short || val instanceof Integer || val instanceof Long) { json = new LongNode(val.longValue()); } else { json = new DoubleNode(val.doubleValue()); } } else throw new RuntimeException("You should not reach this"); return json; }
From source file:com.mapr.synth.samplers.RandomWalkSampler.java
@Override public JsonNode sample() { double step = rand.nextGaussian() * sd.sample().asDouble(); double newState = state.addAndGet(step); if (verbose) { ObjectNode r = new ObjectNode(JsonNodeFactory.withExactBigDecimals(false)); r.set("value", new DoubleNode(newState)); r.set("step", new DoubleNode(step)); return r; } else {/*from ww w. ja v a 2s .c o m*/ return new DoubleNode(newState); } }
From source file:com.squarespace.template.JsonUtilsTest.java
private JsonNode json(double value) { return new DoubleNode(value); }
From source file:net.hamnaberg.json.ValueImpl.java
private static JsonNode getJsonValue(Value value) { if (value.isNumeric()) { Number number = value.asNumber(); if (number instanceof BigDecimal) { return new DecimalNode((BigDecimal) number); }/*from w w w.ja v a 2 s . c o m*/ return new DoubleNode(value.asNumber().doubleValue()); } else if (value.isString()) { return new TextNode(value.asString()); } else if (value.isBoolean()) { return BooleanNode.valueOf(value.asBoolean()); } return NullNode.getInstance(); }
From source file:com.aol.one.patch.DefaultPatcherTest.java
@Test public void testReplaceForSuccess() throws PatchException { List<PatchOperation> operations = new ArrayList<>(); TextNode strNode = new TextNode("1.1String"); DoubleNode doubleNode = new DoubleNode(10.1d); LongNode longNode = new LongNode(200L); TextNode childStrNode = new TextNode("2.1String"); DoubleNode childDoubleNode = new DoubleNode(102.1); operations.add(new ReplaceOperation("/doubleField", doubleNode)); operations.add(new ReplaceOperation("/strField", strNode)); operations.add(new ReplaceOperation("/longField", longNode)); operations.add(new ReplaceOperation("/child/strField", childStrNode)); operations.add(new ReplaceOperation("/child/doubleField", childDoubleNode)); patcher.patch(testObject, operations); assertThat(testObject.getDoubleField(), is(doubleNode.asDouble())); assertThat(testObject.getStrField(), is(strNode.asText())); assertThat(testObject.getLongField(), is(longNode.longValue())); verify(testObject).setStrField(strNode.asText()); verify(testObject).setDoubleField(doubleNode.doubleValue()); // replacement of long field via setLongField verify(testObject).setLongField(longNode.longValue()); // child//from ww w. ja v a 2s . com assertThat(childTestObject.getDoubleField(), is(childDoubleNode.asDouble())); assertThat(childTestObject.getStrField(), is(childStrNode.asText())); verify(childTestObject).setStrField(childStrNode.textValue()); verify(childTestObject).setDoubleField(childDoubleNode.doubleValue()); }
From source file:com.mapr.synth.samplers.RandomWalkSampler.java
@SuppressWarnings("UnusedDeclaration") public void setPrecision(final JsonNode value) throws IOException { if (value.isObject()) { sd = new FieldSampler() { FieldSampler base = FieldSampler.newSampler(value.toString()); @Override/*from ww w.ja v a 2 s . c om*/ public JsonNode sample() { return new DoubleNode(Math.sqrt(1 / base.sample().asDouble())); } }; } else { this.sd = constant(Math.sqrt(1 / value.asDouble())); } init(); }
From source file:net.smartcosmos.extension.geospatial.client.GeospatialClientIT.java
private void createGeospatialEntry() throws ServiceException, JsonProcessingException { ServerContext context = new ServerContext(USERNAME, PASSWORD, "http://localhost:8080"); IGeospatialClient client = GeospatialFactory.createClient(context); /*/*from ww w .j a v a 2s . c o m*/ { "type": "Feature", "bbox": [-180.0, -90.0, 180.0, 90.0], "geometry": { "type": "Polygon", "coordinates": [ [ [-180.0, 10.0], [20.0, 90.0], [180.0, -5.0], [-30.0, -90.0] ] ] } } */ ObjectMapper mapper = new ObjectMapper(); ArrayNode corner1 = mapper.createArrayNode(); DoubleNode corner1X = new DoubleNode(-180.0d); DoubleNode corner1Y = new DoubleNode(10.0d); corner1.add(corner1X).add(corner1Y); ArrayNode corner2 = mapper.createArrayNode(); DoubleNode corner2X = new DoubleNode(20.0d); DoubleNode corner2Y = new DoubleNode(90.0d); corner2.add(corner2X).add(corner2Y); ArrayNode corner3 = mapper.createArrayNode(); DoubleNode corner3X = new DoubleNode(180.0d); DoubleNode corner3Y = new DoubleNode(-5.0d); corner3.add(corner3X).add(corner3Y); ArrayNode corner4 = mapper.createArrayNode(); DoubleNode corner4X = new DoubleNode(-30.0d); DoubleNode corner4Y = new DoubleNode(-90.0d); corner4.add(corner4X).add(corner4Y); ArrayNode box1 = mapper.createArrayNode(); box1.add(corner1).add(corner2).add(corner3).add(corner4); ArrayNode coordinates = mapper.createArrayNode(); coordinates.add(box1); GeometricShape shape = new GeometricShape().setType(GeometricType.Feature) .setBbox(new float[] { -180.0f, -90.0f, 180.0f, 90.0f }) .setGeometry(new GeometricShape().setType(GeometricType.Polygon).setCoordinates(coordinates)); // String jsonOutput = mapper.writeValueAsString(shape); // System.out.println(jsonOutput); IGeospatialEntry entry = new GeospatialBuilder(shape).setType("foo").setName("bar").setDescription("baaq") .setActive(true).build(); ResponseEntity responseEntity = client.create(entry); responseEntity.log(); }
From source file:com.mapr.synth.samplers.RandomWalkSampler.java
@SuppressWarnings("UnusedDeclaration") public void setVariance(final JsonNode value) throws IOException { if (value.isObject()) { sd = new FieldSampler() { FieldSampler base = FieldSampler.newSampler(value.toString()); @Override/*from ww w.jav a 2 s.c o m*/ public JsonNode sample() { return new DoubleNode(Math.sqrt(base.sample().asDouble())); } }; } else { this.sd = constant(Math.sqrt(value.asDouble())); } init(); }