@Override public ImmutableJsonObjectBuilder setAll(final Iterable<JsonField> fields) { requireNonNull(fields, "The JSON fields to be set must not be null!"); for (final JsonField jsonField : fields) { this.fields.put(jsonField.getKeyName(), jsonField); } return this; }
@Override public ImmutableJsonObjectBuilder setAll(final Iterable<JsonField> fields) { requireNonNull(fields, "The JSON fields to be set must not be null!"); for (final JsonField jsonField : fields) { this.fields.put(jsonField.getKeyName(), jsonField); } return this; }
@Override public ImmutableJsonObjectBuilder set(final JsonField field, final Predicate<JsonField> predicate) { requireNonNull(field, "The field to be set must not be null!"); if (predicate.test(field)) { fields.put(field.getKeyName(), field); } return this; }
@Override public ImmutableJsonObjectBuilder set(final JsonField field, final Predicate<JsonField> predicate) { requireNonNull(field, "The field to be set must not be null!"); if (predicate.test(field)) { fields.put(field.getKeyName(), field); } return this; }
/** * Returns a {@code Collector} that accumulates the key names of input JSON fields into a new {@code JsonArray}. The * values are hereby dismissed. * * @return a {@code Collector} which collects the key names of all the JSON fields into a {@code JsonArray}, in * encounter order. */ public static Collector<JsonField, JsonArrayBuilder, JsonArray> fieldKeysToArray() { return Collector.of(JsonFactory::newArrayBuilder, (arrayBuilder, field) -> arrayBuilder.add(field.getKeyName()), JsonArrayBuilder::addAll, JsonArrayBuilder::build); }
/** * Returns a {@code Collector} that accumulates the key names of input JSON fields into a new {@code JsonArray}. The * values are hereby dismissed. * * @return a {@code Collector} which collects the key names of all the JSON fields into a {@code JsonArray}, in * encounter order. */ public static Collector<JsonField, JsonArrayBuilder, JsonArray> fieldKeysToArray() { return Collector.of(JsonFactory::newArrayBuilder, (arrayBuilder, field) -> arrayBuilder.add(field.getKeyName()), JsonArrayBuilder::addAll, JsonArrayBuilder::build); }
@Override public ImmutableJsonObject set(final JsonField field) { requireNonNull(field, "The JSON field to be set must not be null!"); ImmutableJsonObject result = this; final JsonField existingField = fields.get(field.getKeyName()); if (!field.equals(existingField)) { final Map<String, JsonField> fieldsCopy = copyFields(); fieldsCopy.put(field.getKeyName(), field); result = new ImmutableJsonObject(fieldsCopy); } return result; }
@Override public void endObject(final List<JsonField> jsonFields) { final List<JsonField> jsonObjectBuilder = jsonObjectBuilders.poll(); if (null != jsonObjectBuilder) { defaultHandler.endObject(jsonObjectBuilder); } else { final Map<String, JsonField> linkedHashMap = new LinkedHashMap<>(jsonFields.size()); for (final JsonField jsonField : jsonFields) { linkedHashMap.put(jsonField.getKeyName(), jsonField); } value = linkedHashMap; } level--; }
@Override public ImmutableJsonObjectBuilder setAll(final Iterable<JsonField> fields, final Predicate<JsonField> predicate) { requireNonNull(fields, "The JSON fields to be set must not be null!"); checkPredicate(predicate); StreamSupport.stream(fields.spliterator(), false) .filter(field -> !field.getDefinition().isPresent() || predicate.test(field)) .forEach(fieldToBeSet -> this.fields.put(fieldToBeSet.getKeyName(), fieldToBeSet)); return this; }
@Override public ImmutableJsonObjectBuilder setAll(final Iterable<JsonField> fields, final Predicate<JsonField> predicate) { requireNonNull(fields, "The JSON fields to be set must not be null!"); checkPredicate(predicate); StreamSupport.stream(fields.spliterator(), false) .filter(field -> !field.getDefinition().isPresent() || predicate.test(field)) .forEach(fieldToBeSet -> this.fields.put(fieldToBeSet.getKeyName(), fieldToBeSet)); return this; }
@Override public ImmutableJsonObject set(final JsonField field) { requireNonNull(field, "The JSON field to be set must not be null!"); ImmutableJsonObject result = this; final JsonField existingField = fieldMap.getOrNull(field.getKeyName()); if (!field.equals(existingField)) { result = new ImmutableJsonObject(fieldMap.put(field.getKeyName(), field)); } return result; }
private static List<Document> createFlatFeaturesRepresentation(final Iterable<JsonField> properties, final String featureId) { final List<Document> flatFeatures = new ArrayList<>(); properties.forEach(field -> toFlatFeaturesList(PersistenceConstants.SLASH + field.getKeyName(), featureId, field.getValue(), flatFeatures)); return flatFeatures; }
SoftReferencedFieldMap putAll(final Iterable<JsonField> jsonFields) { final Map<String, JsonField> fieldsCopy = copyFields(); jsonFields.forEach(jsonField -> fieldsCopy.put(jsonField.getKeyName(), jsonField)); return of(fieldsCopy); }
private static List<Document> createFlatFeaturesRepresentation(final Iterable<JsonField> properties, final String featureId) { final List<Document> flatFeatures = new ArrayList<>(); properties.forEach(field -> toFlatFeaturesList(PersistenceConstants.SLASH + field.getKeyName(), featureId, field.getValue(), flatFeatures)); return flatFeatures; }
@Override public JsonObject setAll(final Iterable<JsonField> fields) { requireNonNull(fields, "The JSON fields to add must not be null!"); final JsonObject result; if (isEmpty(fields)) { result = this; } else { final Map<String, JsonField> fieldsCopy = copyFields(); fields.forEach(jsonField -> fieldsCopy.put(jsonField.getKeyName(), jsonField)); result = new ImmutableJsonObject(fieldsCopy); } return result; }
private static Document objectToDocument(final Iterable<JsonField> jsonObject) { final Document subDocument = new Document(); jsonObject.forEach(field -> { final String key = KeyEscapeUtil.escape(field.getKeyName()); final Object value = toValue(field.getValue()); subDocument.append(key, value); }); return subDocument; }
private static Document objectToDocument(final Iterable<JsonField> jsonObject) { final Document subDocument = new Document(); jsonObject.forEach(field -> { final String key = KeyEscapeUtil.escape(field.getKeyName()); final Object value = toValue(field.getValue()); subDocument.append(key, value); }); return subDocument; }
@Override protected String createStringRepresentation() { final com.eclipsesource.json.JsonObject minJsonObject = new com.eclipsesource.json.JsonObject(); fields.values().forEach(field -> minJsonObject.add(field.getKeyName(), JsonFactory.convert(field.getValue()))); return minJsonObject.toString(); }
protected static Map<String, String> toMap(final JsonValueContainer<JsonField> jsonObject) { checkNotNull(jsonObject, "JSON object"); final Map<String, String> result = new HashMap<>(jsonObject.getSize()); jsonObject.forEach(jsonField -> { final JsonValue jsonValue = jsonField.getValue(); final String stringValue = jsonValue.isString() ? jsonValue.asString() : jsonValue.toString(); result.put(jsonField.getKeyName(), stringValue); }); return result; }
protected static Map<String, String> toMap(final JsonValueContainer<JsonField> jsonObject) { checkNotNull(jsonObject, "JSON object"); final Map<String, String> result = new HashMap<>(jsonObject.getSize()); jsonObject.forEach(jsonField -> { final JsonValue jsonValue = jsonField.getValue(); final String stringValue = jsonValue.isString() ? jsonValue.asString() : jsonValue.toString(); result.put(jsonField.getKeyName(), stringValue); }); return result; }