List of usage examples for com.fasterxml.jackson.databind.node ArrayNode size
public int size()
From source file:org.apache.taverna.scufl2.translator.t2flow.defaultactivities.SpreadsheetActivityParser.java
private void makeRange(SpreadsheetRange range, ObjectNode rangeJson) { rangeJson.put("start", range.getStart().longValue()); rangeJson.put("end", range.getEnd().longValue()); ArrayNode excludes = rangeJson.arrayNode(); for (SpreadsheetRange excludesRange : range.getExcludes().getExclude()) { ObjectNode exclude = rangeJson.objectNode(); makeRange(excludesRange, exclude); excludes.add(exclude);//from w w w.jav a2 s .c o m } if (excludes.size() > 0) rangeJson.put("excludes", excludes); }
From source file:com.marklogic.entityservices.TestEsEntityTypeSPARQL.java
@Test public void testSPARQLEntityTypeDoc() throws JsonGenerationException, JsonMappingException, IOException { // This test verifies that EntityType doc SchemaCompleteEntityType-0.0.1 has all the ET in it and version and title String assertTypeDocHasRDFType = "PREFIX t: <http://marklogic.com/testing-entity-type#> " + "SELECT ?p ?o " + "WHERE { t:SchemaCompleteEntityType-0.0.1 ?p ?o }" + "order by ?s"; JacksonHandle handle2 = queryMgr.executeSelect(queryMgr.newQueryDefinition(assertTypeDocHasRDFType), new JacksonHandle()); JsonNode results2 = handle2.get();/*from w w w . j a v a 2 s . c o m*/ // to see on System.out //new ObjectMapper().writerWithDefaultPrettyPrinter().writeValue(System.out, results2); ArrayNode bindings2 = (ArrayNode) results2.get("results").get("bindings"); //logger.info(bindings2.toString()); assertEquals(6, bindings2.size()); // Verify that Entity type doc has RDF type in it. assertEquals("http://www.w3.org/1999/02/22-rdf-syntax-ns#type", bindings2.get(0).get("p").get("value").asText()); assertEquals("http://marklogic.com/entity-services#Model", bindings2.get(0).get("o").get("value").asText()); // Verify that Entity type doc has EnityType OrderDetails in it. assertEquals("http://marklogic.com/entity-services#definitions", bindings2.get(1).get("p").get("value").asText()); assertEquals("http://marklogic.com/testing-entity-type/SchemaCompleteEntityType-0.0.1/OrderDetails", bindings2.get(1).get("o").get("value").asText()); // Verify that Entity type doc has EnityType OrderDetails in it. assertEquals("http://marklogic.com/entity-services#definitions", bindings2.get(2).get("p").get("value").asText()); assertEquals( "http://marklogic.com/testing-entity-type/SchemaCompleteEntityType-0.0.1/SchemaCompleteEntityType", bindings2.get(2).get("o").get("value").asText()); // Verify that Entity type doc has version in it. assertEquals("http://marklogic.com/entity-services#version", bindings2.get(3).get("p").get("value").asText()); assertEquals("0.0.1", bindings2.get(3).get("o").get("value").asText()); // Verify that Entity type doc has title in it. assertEquals("http://marklogic.com/entity-services#description", bindings2.get(4).get("p").get("value").asText()); assertEquals( "All Schema Elements represented in this type. Collations and datatypes are all happy-path and valid.", bindings2.get(4).get("o").get("value").asText()); // Verify that Entity type doc has title in it. assertEquals("http://marklogic.com/entity-services#title", bindings2.get(5).get("p").get("value").asText()); assertEquals("SchemaCompleteEntityType", bindings2.get(5).get("o").get("value").asText()); }
From source file:io.amient.kafka.metrics.Dashboard.java
public ObjectNode newTarget(ObjectNode panel, String aliasPattern, String rawQuery) { ArrayNode targets = ((ArrayNode) panel.get("targets")); ObjectNode target = targets.addObject(); target.put("refId", Character.toString((char) (64 + targets.size()))); target.put("query", rawQuery); target.put("alias", aliasPattern); target.put("rawQuery", true); return target; }
From source file:org.pentaho.metaverse.impl.model.kettle.json.TransMetaJsonDeserializer.java
protected void deserializeParameters(TransMeta transMeta, JsonNode node, ObjectMapper mapper) throws IOException { ArrayNode paramsArrayNode = (ArrayNode) node.get(TransMetaJsonSerializer.JSON_PROPERTY_PARAMETERS); for (int i = 0; i < paramsArrayNode.size(); i++) { JsonNode paramNode = paramsArrayNode.get(i); ParamInfo param = mapper.readValue(paramNode.toString(), ParamInfo.class); try {// ww w . j a v a 2s .c o m transMeta.addParameterDefinition(param.getName(), param.getDefaultValue(), param.getDescription()); } catch (DuplicateParamException e) { LOGGER.warn(Messages.getString("WARNING.Deserialization.Trans.DuplicateParam", param.getName()), e); } } }
From source file:de.jlo.talendcomp.json.JsonComparator.java
/** * Checks if the array contains the given value * @param array the array which perhaps contains the value * @param value the value to search for//from w ww . jav a 2s .c o m * @return true or false * @throws Exception */ public boolean contains(ArrayNode array, JsonNode value, String jsonPath) throws Exception { if (jsonPath == null || jsonPath.trim().isEmpty()) { return contains(array, value); } else { JsonDocument doc = new JsonDocument(array); for (int i = 0, n = array.size(); i < n; i++) { JsonNode nodeInArray = array.get(i); JsonNode child1 = doc.getNode(nodeInArray, jsonPath); JsonNode child2 = doc.getNode(value, jsonPath); if (child1.equals(child2)) { return true; } } return false; } }
From source file:com.github.fge.jsonpatch.AddOperation.java
private JsonNode addToArray(final JsonPointer path, final JsonNode node) throws JsonPatchException { final JsonNode ret = node.deepCopy(); final ArrayNode target = (ArrayNode) path.parent().get(ret); final TokenResolver<JsonNode> token = Iterables.getLast(path); if (token.getToken().equals(LAST_ARRAY_ELEMENT)) { target.add(value);/*from w w w. j a va 2s. c o m*/ return ret; } final int size = target.size(); final int index; try { index = Integer.parseInt(token.toString()); } catch (NumberFormatException ignored) { throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.notAnIndex")); } if (index < 0 || index > size) throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.noSuchIndex")); target.insert(index, value); return ret; }
From source file:org.envirocar.server.rest.util.GeoJSON.java
protected Coordinate decodeCoordinate(ArrayNode list) throws GeometryConverterException { if (list.size() != 2) { throw new GeometryConverterException("coordinates may only have 2 dimensions"); }/*from ww w. j a va 2 s . co m*/ Number x = list.get(0).numberValue(); Number y = list.get(1).numberValue(); if (x == null || y == null) { throw new GeometryConverterException("x and y have to be numbers"); } return new Coordinate(x.doubleValue(), y.doubleValue()); }
From source file:com.redhat.lightblue.eval.ArrayProjector.java
/** * Sorts the given array node using the sort criteria given in this ArrayProjector * * @param array The array node to sort//w w w .ja v a 2 s . c o m * @param factory Json node factory * * If there is a sort criteria defined in <code>this</code>, the array elements are * sorted using that. * * @return A new ArrayNode containing the sorted elements, or if * there is no sort defined, the <code>array</code> itself */ public ArrayNode sortArray(ArrayNode array, JsonNodeFactory factory) { if (sort == null) { return array; } else { List<SortableElement> list = new ArrayList<>(array.size()); for (Iterator<JsonNode> itr = array.elements(); itr.hasNext();) { list.add(new SortableElement(itr.next(), sortFields)); } Collections.sort(list); ArrayNode newNode = factory.arrayNode(); for (SortableElement x : list) newNode.add(x.node); return newNode; } }
From source file:org.envirocar.server.rest.util.GeoJSON.java
protected Polygon decodePolygonCoordinates(ArrayNode coordinates) throws GeometryConverterException { if (coordinates.size() < 1) { throw new GeometryConverterException("missing polygon shell"); }/*from ww w . j a v a 2s. c o m*/ LinearRing shell = getGeometryFactory().createLinearRing(decodeCoordinates(toList(coordinates.get(0)))); LinearRing[] holes = new LinearRing[coordinates.size() - 1]; for (int i = 1; i < coordinates.size(); ++i) { holes[i - 1] = getGeometryFactory().createLinearRing(decodeCoordinates(toList(coordinates.get(i)))); } return getGeometryFactory().createPolygon(shell, holes); }
From source file:org.envirocar.server.rest.util.GeoJSON.java
@Override public MultiPolygon decodeMultiPolygon(JsonNode json) throws GeometryConverterException { ArrayNode coordinates = requireCoordinates(json); Polygon[] polygons = new Polygon[coordinates.size()]; for (int i = 0; i < coordinates.size(); ++i) { polygons[i] = decodePolygonCoordinates(toList(coordinates.get(i))); }//from w w w .j a v a 2s . co m return getGeometryFactory().createMultiPolygon(polygons); }