private void formatConditions(@Nullable JsonArray jsonConditions) { if (jsonConditions == null) { return; } StreamSupport.stream(jsonConditions.spliterator(), false) .map(JsonElement::getAsJsonObject) .filter(isConditionOnValidPeriod()) .forEach(this::formatCondition); }
public Optional<List<String>> readStringArrayIfPresent(String property) { if (jsonObject.has(property)) { try { Spliterator<JsonElement> iterator = jsonObject.getAsJsonArray(property).spliterator(); return Optional.of( StreamSupport.stream(iterator, false) .map(JsonElement::getAsString) .collect(Collectors.toList())); } catch (Exception e) { throw haltBecausePropertyIsNotAJsonStringArray(property, jsonObject); } } return Optional.empty(); }
public static QPMeasureData fromJson(String json) { return new QPMeasureData(StreamSupport.stream(new JsonParser().parse(json).getAsJsonArray().spliterator(), false) .map(jsonElement -> { JsonObject jsonProfile = jsonElement.getAsJsonObject(); return new QualityProfile( jsonProfile.get("key").getAsString(), jsonProfile.get("name").getAsString(), jsonProfile.get("language").getAsString(), UtcDateUtils.parseDateTime(jsonProfile.get("rulesUpdatedAt").getAsString())); }).collect(Collectors.toList())); }
@Override public Optional<Stream<JsonElement>> getStream(final JsonElement input) { if (input.isJsonArray()) { return Optional.of(StreamSupport.stream(input.getAsJsonArray().spliterator(), false)); } return Optional.empty(); }
} else if (input.isJsonArray()) { result = new JsonArray(); StreamSupport.stream(input.getAsJsonArray().spliterator(), false).forEach(result::add); } else { return input;
/** * Stream all of the {@link JsonObject}s in a {@link JsonArray}. * * @param features * a {@link JsonArray} containing only {@link JsonObject}s * @return a {@link Stream} containing all {@link JsonObject}s inside features. */ private Stream<JsonObject> objectStream(final JsonArray features) { return StreamSupport.stream(features.spliterator(), false) .map(JsonElement::getAsJsonObject); } }
@Nonnull @Override public Stream<GsonDataTree> asArray() { return StreamSupport.stream(this.element.getAsJsonArray().spliterator(), false) .map(GsonDataTree::new); }
@Nonnull @Override public Stream<GsonDataTree> asArray() { return StreamSupport.stream(this.element.getAsJsonArray().spliterator(), false) .map(GsonDataTree::new); }
@Override public List<?> extractResults(SerializationContext serializationContext) { JsonArray hits = jsonObject.get(JSON_HITS).getAsJsonArray(); return stream(hits.spliterator(), false) .map(hit -> hit.getAsJsonObject().get(JSON_HIT).toString()) .collect(Collectors.toList()); }
@Override public List<T> apply(final JsonElement json) { if (json == null) { return Collections.emptyList(); } else { return ImmutableList.copyOf( StreamSupport.stream(json.getAsJsonArray().spliterator(), false) .map(elementParser) .collect(Collectors.toList())); } } }
private void formatConditions(@Nullable JsonArray jsonConditions) { if (jsonConditions == null) { return; } StreamSupport.stream(jsonConditions.spliterator(), false) .map(JsonElement::getAsJsonObject) .filter(isConditionOnValidPeriod()) .forEach(this::formatCondition); }
/** * {@inheritDoc} */ @Override protected Stream<JsonObject> getStructureStream(String data) { return new JsonParser().parse(data) .getAsJsonObject() .entrySet() .stream() .map(e -> e.getValue().getAsJsonArray()) .flatMap(a -> StreamSupport.stream(a.spliterator(), false)) .map(JsonElement::getAsJsonObject); }
private List<BranchInfo> readResponse(final WsResponse wsResponse) throws IOException { try (Reader contentReader = wsResponse.contentReader()) { JsonObject map = GSON.fromJson(contentReader, JsonObject.class); return StreamSupport.stream(map.get("branches").getAsJsonArray().spliterator(), false) .map(this::createBranchInfo) .collect(Collectors.toList()); } }
private Set<String> parseTargetList(JsonObject json) { if (!json.has(ENTITIES_TO_TARGET)) { return Collections.emptySet(); } JsonArray targets = JsonUtils.getJsonArray(json, ENTITIES_TO_TARGET); return StreamSupport.stream(targets.spliterator(), false).map(e -> JsonUtils.getString(e, "")) .collect(Collectors.toCollection(HashSet::new)); } }
public static QPMeasureData fromJson(String json) { return new QPMeasureData(StreamSupport.stream(new JsonParser().parse(json).getAsJsonArray().spliterator(), false) .map(jsonElement -> { JsonObject jsonProfile = jsonElement.getAsJsonObject(); return new QualityProfile( jsonProfile.get("key").getAsString(), jsonProfile.get("name").getAsString(), jsonProfile.get("language").getAsString(), UtcDateUtils.parseDateTime(jsonProfile.get("rulesUpdatedAt").getAsString())); }).collect(Collectors.toList())); }
private Set<String> getTargetList(JsonObject json) { if (!json.has("entities_to_target")) { return Collections.emptySet(); } JsonArray targets = JsonUtils.getJsonArray(json, "entities_to_target"); return StreamSupport.stream(targets.spliterator(), false).map(e -> JsonUtils.getString(e, "")) .collect(Collectors.toCollection(HashSet::new)); }
private Set<String> getDependencies(JsonObject json) { JsonArray deps = JsonUtils.getJsonArray(json, "dependencies"); return StreamSupport.stream(deps.spliterator(), false).map(e -> JsonUtils.getString(e, "")).collect(Collectors.toSet()); } }
private Set<Ingredient> getResources(JsonObject json) { JsonArray res = JsonUtils.getJsonArray(json, "resources"); JsonContext context = new JsonContext(AncientWarfareCore.MOD_ID); return StreamSupport.stream(res.spliterator(), false).map(e -> CraftingHelper.getIngredient(e, context)).collect(Collectors.toSet()); }
private List<DnsRecord> getRecords(DnsZone zone) { try { JsonArray jsons = request(CLOUDFLARE_API_URL + "zones/" + zone.getId() + "/dns_records?per_page=100", "GET").getAsJsonArray(); return StreamSupport.stream(jsons.spliterator(), false).map(object -> DnsRecord.fromJson(object.getAsJsonObject())).collect(Collectors.toList()); } catch (Exception e) { TimoCloudCore.getInstance().severe("Error while getting DNS records via API. Check your API access data or internet connection."); e.printStackTrace(); return new ArrayList<>(); } }
public static Predicate<IBlockState> getBlockStateMatcher(JsonObject json, String arrayElement, String individualElement) { if (json.has(arrayElement)) { JsonArray stateMatchers = JsonUtils.getJsonArray(json, arrayElement); return new MultiBlockStateMatcher(StreamSupport.stream(stateMatchers.spliterator(), false) .map(e -> getBlockStateMatcher(JsonUtils.getJsonObject(e, individualElement))) .toArray(BlockStateMatcher[]::new)); } return getBlockStateMatcher(json, individualElement); }