本文整理了Java中com.fasterxml.jackson.databind.JsonNode.spliterator()
方法的一些代码示例,展示了JsonNode.spliterator()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.spliterator()
方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.JsonNode
类名称:JsonNode
方法名:spliterator
暂无
代码示例来源:origin: Graylog2/graylog2-server
public IndexSetStats getForIndexSet(final IndexSet indexSet) {
final Set<String> closedIndices = indices.getClosedIndices(indexSet);
final List<JsonNode> primaries = StreamSupport.stream(indices.getIndexStats(indexSet).spliterator(), false)
.map(json -> json.get("primaries"))
.collect(Collectors.toList());
final long documents = primaries.stream()
.map(json -> json.path("docs").path("count").asLong())
.reduce(0L, Long::sum);
final long size = primaries.stream()
.map(json -> json.path("store").path("size_in_bytes").asLong())
.reduce(0L, Long::sum);
return IndexSetStats.create(primaries.size() + closedIndices.size(), documents, size);
}
}
代码示例来源:origin: Graylog2/graylog2-server
private <T extends JestResult> T checkForFailedShards(T result) throws FieldTypeException {
// unwrap shard failure due to non-numeric mapping. this happens when searching across index sets
// if at least one of the index sets comes back with a result, the overall result will have the aggregation
// but not considered failed entirely. however, if one shard has the error, we will refuse to respond
// otherwise we would be showing empty graphs for non-numeric fields.
final JsonNode shards = result.getJsonObject().path("_shards");
final double failedShards = shards.path("failed").asDouble();
if (failedShards > 0) {
final List<String> errors = StreamSupport.stream(shards.path("failures").spliterator(), false)
.map(failure -> failure.path("reason").path("reason").asText())
.filter(s -> !s.isEmpty())
.collect(Collectors.toList());
final List<String> nonNumericFieldErrors = errors.stream()
.filter(error -> error.startsWith("Expected numeric type on field"))
.collect(Collectors.toList());
if (!nonNumericFieldErrors.isEmpty()) {
throw new FieldTypeException("Unable to perform search query", nonNumericFieldErrors);
}
throw new ElasticsearchException("Unable to perform search query", errors);
}
return result;
}
代码示例来源:origin: Graylog2/graylog2-server
public ScrollChunk nextChunk() throws IOException {
final JestResult search;
final List<ResultMessage> hits;
if (initialResult == null) {
search = getNextScrollResult();
hits = StreamSupport.stream(search.getJsonObject().path("hits").path("hits").spliterator(), false)
.map(hit -> ResultMessage.parseFromSource(hit.path("_id").asText(),
hit.path("_index").asText(),
objectMapper.convertValue(hit.get("_source"), TypeReferences.MAP_STRING_OBJECT)))
.collect(Collectors.toList());
} else {
// make sure to return the initial hits, see https://github.com/Graylog2/graylog2-server/issues/2126
search = initialResult;
hits = initialResult.getHits(Map.class, false).stream()
.map(hit -> ResultMessage.parseFromSource(hit.id, hit.index, (Map<String, Object>)hit.source))
.collect(Collectors.toList());
this.initialResult = null;
}
if (hits.size() == 0) {
// scroll exhausted
LOG.debug("[{}] Reached end of scroll results.", queryHash, getOriginalQuery());
return null;
}
LOG.debug("[{}][{}] New scroll id {}, number of hits in chunk: {}", queryHash, chunkId, getScrollIdFromResult(search), hits.size());
scrollId = getScrollIdFromResult(search); // save the id for the next request.
return new ScrollChunk(hits, fields, chunkId++);
}
代码示例来源:origin: Graylog2/graylog2-server
/**
* Retrieves all indices in the given {@link IndexSet}.
* <p>
* If any status filter parameter are present, only indices with the given status are returned.
*
* @param indexSet the index set
* @param statusFilter only indices with the given status are returned. (available: "open", "close")
* @return the set of indices in the given index set
*/
public Set<String> getIndices(final IndexSet indexSet, final String... statusFilter) {
final List<String> status = Arrays.asList(statusFilter);
final Cat catRequest = new Cat.IndicesBuilder()
.addIndex(indexSet.getIndexWildcard())
.setParameter("h", "index,status")
.build();
final CatResult result = JestUtils.execute(jestClient, catRequest,
() -> "Couldn't get index list for index set <" + indexSet.getConfig().id() + ">");
return StreamSupport.stream(result.getJsonObject().path("result").spliterator(), false)
.filter(cat -> status.isEmpty() || status.contains(cat.path("status").asText()))
.map(cat -> cat.path("index").asText())
.collect(Collectors.toSet());
}
代码示例来源:origin: apache/geode
if (regionsNode != null) {
if (regionsNode.isArray()) {
regionNames = StreamSupport.stream(regionsNode.spliterator(), false).map(JsonNode::asText)
.collect(Collectors.joining(","));
} else {
代码示例来源:origin: apache/geode
if (regionsNode != null) {
if (regionsNode.isArray()) {
regionNames = StreamSupport.stream(regionsNode.spliterator(), false).map(JsonNode::asText)
.collect(Collectors.joining(","));
} else {
代码示例来源:origin: org.n52.faroe/faroe-json
protected Stream<JsonNode> createStream(JsonNode node) {
return StreamSupport.stream(node.spliterator(), false);
}
代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-bulk
protected static ArrayList<Serializable> toList(JsonNode value) {
// we declare method return type as ArrayList to be compliant with Serializable in params map
// spliterator calls iterator which is a bridge method of JsonNode#elements
return StreamSupport.stream(value.spliterator(), false)
.map(BulkParameters::toSerializable)
.collect(Collectors.toCollection(ArrayList::new));
}
代码示例来源:origin: SeaseLtd/rated-ranking-evaluator
/**
* Streams out all members of a given JSON node.
*
* @param source the parent JSON node.
* @return a stream consisting of all children of the given JSON node.
*/
private Stream<JsonNode> all(final JsonNode source, final String name) {
return ofNullable(source.get(name))
.map(node -> StreamSupport.stream(node.spliterator(), false))
.orElseGet(() -> Stream.of(source));
}
代码示例来源:origin: HotelsDotCom/styx
private static List<RouteHandlerConfig> styxHttpPipeline(JsonNode pipeline) {
return stream(pipeline.spliterator(), false)
.map(ConfigFactory::toRoutingConfigNode)
.collect(Collectors.toList());
}
代码示例来源:origin: pl.allegro.tech/embedded-elasticsearch
private Stream<String> parseDocuments(String body) {
try {
JsonNode jsonNode = OBJECT_MAPPER.readTree(body);
return StreamSupport.stream(jsonNode.get("hits").get("hits").spliterator(), false)
.map(hitNode -> hitNode.get("_source"))
.map(JsonNode::toString);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
代码示例来源:origin: excelsior-oss/restler
private List<Object> mapToProxies(JsonNode objects, Class<?> elementClass) {
return StreamSupport.stream(objects.spliterator(), false).
map(o -> makeObject(elementClass, o)).
collect(Collectors.toList());
}
代码示例来源:origin: allegro/hermes
@Override
public Object[] parseArrayValue(JsonNode node) {
if(!node.isArray()) {
throw new ParseException("Element value was expected to be an array");
}
return stream(node.spliterator(), false)
.map(this::parseValue)
.toArray();
}
代码示例来源:origin: org.n52.wps/engine
private Set<Format> getFormatsFromProperties() {
JsonNode node = getProperties().path("formats");
return StreamSupport.stream(node.spliterator(), false).map(this::parseFormat).filter(x -> !x.isEmpty()).collect(
toCollection(LinkedHashSet::new));
}
代码示例来源:origin: org.graylog2/graylog2-server
public IndexSetStats getForIndexSet(final IndexSet indexSet) {
final Set<String> closedIndices = indices.getClosedIndices(indexSet);
final List<JsonNode> primaries = StreamSupport.stream(indices.getIndexStats(indexSet).spliterator(), false)
.map(json -> json.get("primaries"))
.collect(Collectors.toList());
final long documents = primaries.stream()
.map(json -> json.path("docs").path("count").asLong())
.reduce(0L, Long::sum);
final long size = primaries.stream()
.map(json -> json.path("store").path("size_in_bytes").asLong())
.reduce(0L, Long::sum);
return IndexSetStats.create(primaries.size() + closedIndices.size(), documents, size);
}
}
代码示例来源:origin: neo4j/neo4j-ogm
private void throwExceptionOnErrorEntry(JsonParser pointingToErrors) throws IOException {
if (pointingToErrors == null) {
return;
}
JsonNode errorsNode = mapper.readTree(pointingToErrors);
Optional<JsonNode> optionalErrorNode = StreamSupport.stream(errorsNode.spliterator(), false)
.findFirst();
if (optionalErrorNode.isPresent()) {
JsonNode errorNode = optionalErrorNode.get();
throw new CypherException(errorNode.findValue("code").asText(), errorNode.findValue("message").asText());
}
}
代码示例来源:origin: io.syndesis.rest/rest-dao
@Test
public void thereShouldBeNoDuplicateNames() {
final Map<String, Long> namesWithCount = StreamSupport.stream(deployment.spliterator(), true)
.filter(data -> "connector".equals(data.get("kind").asText()))
.flatMap(connector -> StreamSupport.stream(connector.get("data").get("actions").spliterator(), true))
.map(action -> action.get("name").asText()).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
final Map<String, Long> multipleNames = namesWithCount.entrySet().stream().filter(e -> e.getValue() > 1)
.collect(Collectors.toMap(Entry::getKey, Entry::getValue));
assertThat(multipleNames).as("Expected unique action names").isEmpty();
}
代码示例来源:origin: io.syndesis.rest/rest-dao
@Test
public void thereShouldBeNoDuplicateMavenCoordinates() {
final Map<String, Long> coordinatesWithCount = StreamSupport.stream(deployment.spliterator(), true)
.filter(data -> "connector".equals(data.get("kind").asText()))
.flatMap(connector -> StreamSupport.stream(connector.get("data").get("actions").spliterator(), true))
.filter(action -> action.get("descriptor").get("camelConnectorGAV") != null)
.map(action -> action.get("descriptor").get("camelConnectorGAV").asText())
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
final Map<String, Long> multipleCoordinates = coordinatesWithCount.entrySet().stream()
.filter(e -> e.getValue() > 1)
.collect(Collectors.toMap(Entry::getKey, Entry::getValue));
assertThat(multipleCoordinates).as("Expected connector GAV coordinates to be unique").isEmpty();
}
代码示例来源:origin: Javacord/Javacord
@Override
default CompletableFuture<MessageSet> getPins() {
return new RestRequest<MessageSet>(getApi(), RestMethod.GET, RestEndpoint.PINS)
.setUrlParameters(getIdAsString())
.execute(result -> {
Collection<Message> pins = StreamSupport.stream(result.getJsonBody().spliterator(), false)
.map(pinJson -> ((DiscordApiImpl) getApi()).getOrCreateMessage(this, pinJson))
.collect(Collectors.toList());
return new MessageSetImpl(pins);
});
}
代码示例来源:origin: elastic/apm-agent-java
private List<JsonNode> getStackTrace() throws IOException {
final Transaction transaction = tracer.startTransaction();
final Span span = transaction.createSpan();
span.end();
transaction.end();
return StreamSupport.stream(objectMapper
.readTree(serializer.toJsonString(span))
.get("stacktrace")
.spliterator(), false)
.collect(Collectors.toList());
}
内容来源于网络,如有侵权,请联系作者删除!