@Override public JsonNode digest(final JsonNode schema) { final SortedSet<JsonNode> set = Sets.newTreeSet(COMPARATOR); for (final JsonNode element: schema.get(keyword)) set.add(element); return FACTORY.arrayNode().addAll(set); }
private static JsonNode sortedSet(final JsonNode node) { final List<JsonNode> list = Lists.newArrayList(node); Collections.sort(list, new Comparator<JsonNode>() { @Override public int compare(final JsonNode o1, final JsonNode o2) { return o1.textValue().compareTo(o2.textValue()); } }); final ArrayNode ret = FACTORY.arrayNode(); ret.addAll(list); return ret; } }
private static JsonNode sortedSet(final JsonNode node) { final SortedSet<JsonNode> set = Sets.newTreeSet(new Comparator<JsonNode>() { @Override public int compare(final JsonNode o1, final JsonNode o2) { return o1.textValue().compareTo(o2.textValue()); } }); set.addAll(Sets.newHashSet(node)); final ArrayNode ret = FACTORY.arrayNode(); ret.addAll(set); return ret; } }
private ObjectNode mergeObjectNodes(ObjectNode targetNode, ObjectNode updateNode) { Iterator<String> fieldNames = updateNode.fieldNames(); while (fieldNames.hasNext()) { String fieldName = fieldNames.next(); JsonNode targetValue = targetNode.get(fieldName); JsonNode updateValue = updateNode.get(fieldName); if (targetValue == null) { // Target node doesn't have this field from update node: just add it targetNode.set(fieldName, updateValue); } else { // Both nodes have the same field: merge the values if (targetValue.isObject() && updateValue.isObject()) { // Both values are objects: recurse targetNode.set(fieldName, mergeObjectNodes((ObjectNode) targetValue, (ObjectNode) updateValue)); } else if (targetValue.isArray() && updateValue.isArray()) { // Both values are arrays: concatenate them to be merged later ((ArrayNode) targetValue).addAll((ArrayNode) updateValue); } else { // Values have different types: use the one from the update node targetNode.set(fieldName, updateValue); } } } return targetNode; }
@Override public JsonNode digest(final JsonNode schema) { final ObjectNode ret = FACTORY.objectNode(); final ArrayNode required = FACTORY.arrayNode(); ret.put(keyword, required); final List<JsonNode> list = Lists.newArrayList(schema.get(keyword)); Collections.sort(list, new Comparator<JsonNode>() { @Override public int compare(final JsonNode o1, final JsonNode o2) { return o1.textValue().compareTo(o2.textValue()); } }); required.addAll(list); return ret; } }
protected void type(ObjectNode parent, TypeCapability capability) { ObjectNode type = nodeFactory.objectNode(); type.put("type", "action"); Type defaultType = capability.getDefault(); if (defaultType != null) { type.put("default", defaultType.getId()); } ArrayNode values = nodeFactory.arrayNode(); values.addAll(capability.getContent().stream().map(this::mapType) .collect(Collectors.toList())); type.set("values", values); parent.set("type", type); }
protected void dependencies(ObjectNode parent, DependenciesCapability capability) { ObjectNode dependencies = nodeFactory.objectNode(); dependencies.put("type", capability.getType().getName()); ArrayNode values = nodeFactory.arrayNode(); values.addAll(capability.getContent().stream().map(this::mapDependencyGroup) .collect(Collectors.toList())); dependencies.set("values", values); parent.set(capability.getId(), dependencies); }
protected void singleSelect(ObjectNode parent, SingleSelectCapability capability) { ObjectNode single = nodeFactory.objectNode(); single.put("type", capability.getType().getName()); DefaultMetadataElement defaultType = capability.getDefault(); if (defaultType != null) { single.put("default", defaultType.getId()); } ArrayNode values = nodeFactory.arrayNode(); values.addAll(capability.getContent().stream().map(this::mapValue) .collect(Collectors.toList())); single.set("values", values); parent.set(capability.getId(), single); }
requestJson.putArray("points").addAll(createPointList(ghRequest.getFromPoints())); requestJson.putArray("point_hints").addAll(createStringList(ghRequest.getFromPointHints())); } else { ArrayNode fromPointList = createPointList(ghRequest.getFromPoints()); ArrayNode toPointList = createPointList(ghRequest.getToPoints()); requestJson.putArray("from_points").addAll(fromPointList); requestJson.putArray("from_point_hints").addAll(createStringList(ghRequest.getFromPointHints())); requestJson.putArray("to_points").addAll(toPointList); requestJson.putArray("to_point_hints").addAll(createStringList(ghRequest.getToPointHints())); requestJson.putArray("out_arrays").addAll(outArrayListJson); requestJson.put("vehicle", ghRequest.getVehicle()); requestJson.put("elevation", hasElevation);
private static void merge(ObjectNode to, ObjectNode from) { Iterator<String> newFieldNames = from.fieldNames(); while (newFieldNames.hasNext()) { String newFieldName = newFieldNames.next(); JsonNode oldVal = to.get(newFieldName); JsonNode newVal = from.get(newFieldName); if (oldVal == null || oldVal.isNull()) { to.set(newFieldName, newVal); } else if (oldVal.isArray() && newVal.isArray()) { ((ArrayNode) oldVal).removeAll(); ((ArrayNode) oldVal).addAll((ArrayNode) newVal); } else if (oldVal.isObject() && newVal.isObject()) { merge((ObjectNode) oldVal, (ObjectNode) newVal); } else if (!(newVal == null || newVal.isNull())) { to.set(newFieldName, newVal); } } } }
private ObjectNode addIncludedSection(ObjectNode rootNode, Map<String, ObjectNode> includedDataMap) { if (!includedDataMap.isEmpty()) { ArrayNode includedArray = objectMapper.createArrayNode(); includedArray.addAll(includedDataMap.values()); rootNode.set(INCLUDED, includedArray); } return rootNode; }
public static ArrayNode asArrayNode(final ObjectMapper mapper, final List<JsonNode> values) { final ArrayNode result = mapper.createArrayNode(); result.addAll(values); return result; }
@Override public JsonNode createArray(Collection<JsonNode> elements) { ArrayNode array = JsonNodeFactory.instance.arrayNode(); array.addAll(elements); return array; }
private ArrayNode flattenResults() { final JsonNodeFactory factory = JsonNodeFactory.instance; ArrayNode flatArray = factory.arrayNode(); for (Map.Entry<Integer, ArrayNode> entry : results.entrySet()) { flatArray.addAll(entry.getValue()); } return flatArray; }
public static ArrayNode asArrayNode(final ObjectMapper mapper, final List<JsonNode> values) { final ArrayNode result = mapper.createArrayNode(); result.addAll(values); return result; }
@Override public void build(ObjectNode targetNode, List<JsonNode> innerNodes) { final ArrayNode subTrees = JSON_NODE_FACTORY.arrayNode(); subTrees.addAll(innerNodes); targetNode.put("and", subTrees); } },
private <E extends Enum<E>> ArrayNode enumCaseArray(E[] values) { ArrayNode arrayNode = nf.arrayNode(); arrayNode.addAll(Schema.enumCases(values)); return arrayNode; }
@Override public List<JsonNode> apply(final Scope scope, final JsonNode in) throws JsonQueryException { final ArrayNode array = new ArrayNode(scope.getObjectMapper().getNodeFactory()); if (q != null) array.addAll(q.apply(scope, in)); return Collections.singletonList((JsonNode) array); }
@Override public List<JsonNode> apply(final Scope scope, final JsonNode in) throws JsonQueryException { final ArrayNode array = new ArrayNode(scope.getObjectMapper().getNodeFactory()); if (q != null) array.addAll(q.apply(scope, in)); return Collections.singletonList((JsonNode) array); }