@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 <T> JsonObjectBuilder set(final JsonFieldDefinition<T> fieldDefinition, @Nullable final T value, final Predicate<JsonField> predicate) { requireNonNull(fieldDefinition, "The definition of the JSON field to set the value for must not be null!"); checkPredicate(predicate); final JsonPointer pointer = fieldDefinition.getPointer(); pointer.getLeaf() .map(leafKey -> JsonFactory.newField(leafKey, JsonFactory.getAppropriateValue(value), fieldDefinition)) .filter(predicate) .ifPresent(jsonField -> setFieldInHierarchy(this, pointer, jsonField)); return this; }
@Override public <T> JsonObjectBuilder set(final JsonFieldDefinition<T> fieldDefinition, @Nullable final T value, final Predicate<JsonField> predicate) { requireNonNull(fieldDefinition, "The definition of the JSON field to set the value for must not be null!"); checkPredicate(predicate); final JsonPointer pointer = fieldDefinition.getPointer(); pointer.getLeaf() .map(leafKey -> JsonFactory.newField(leafKey, JsonFactory.getAppropriateValue(value), fieldDefinition)) .filter(predicate) .ifPresent(jsonField -> setFieldInHierarchy(this, pointer, jsonField)); return this; }
@Override public ImmutableJsonObjectBuilder set(final CharSequence key, final JsonValue value, final Predicate<JsonField> predicate) { final JsonPointer pointer = JsonFactory.getNonEmptyPointer(key); checkValue(value); checkPredicate(predicate); pointer.getLeaf() .map(leafKey -> JsonFactory.newField(leafKey, value)) .filter(predicate) .ifPresent(jsonField -> setFieldInHierarchy(this, pointer, jsonField)); return this; }
@Override public ImmutableJsonObjectBuilder set(final CharSequence key, final JsonValue value, final Predicate<JsonField> predicate) { final JsonPointer pointer = JsonFactory.getNonEmptyPointer(key); checkValue(value); checkPredicate(predicate); pointer.getLeaf() .map(leafKey -> JsonFactory.newField(leafKey, value)) .filter(predicate) .ifPresent(jsonField -> setFieldInHierarchy(this, pointer, jsonField)); return this; }