@Override public SearchResult build() { final JsonArray searchResultsJsonArray = jsonArrayBuilder.build(); return ImmutableSearchResult.of(searchResultsJsonArray, offset); }
@Override public SearchResultBuilder add(final JsonValue value, final JsonValue... furtherValues) { jsonArrayBuilder.add(value, furtherValues); return this; }
@Override public SearchResultBuilder addAll(final Iterable<? extends JsonValue> values) { jsonArrayBuilder.addAll(values); return this; }
@Override public SearchResultBuilder remove(final JsonValue value) { jsonArrayBuilder.remove(value); return this; }
@Override public SearchResultBuilder remove(final JsonValue value) { jsonArrayBuilder.remove(value); return this; }
@Override public SearchResult build() { final JsonArray searchResultsJsonArray = jsonArrayBuilder.build(); return ImmutableSearchResult.of(searchResultsJsonArray, offset); }
@Override public SearchResultBuilder add(final JsonValue value, final JsonValue... furtherValues) { jsonArrayBuilder.add(value, furtherValues); return this; }
@Override public SearchResultBuilder addAll(final Iterable<? extends JsonValue> values) { jsonArrayBuilder.addAll(values); return this; }
@Override public JsonArray toJson() { final JsonArrayBuilder jsonArrayBuilder = JsonFactory.newArrayBuilder(); permissions.forEach(jsonArrayBuilder::add); return 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); }
/** * Returns a new mutable builder for a {@code JsonArray} which is already initialised with the given values. * * @param values the values of the JSON array to be created. This might be an existing JSON array as well. * @return a new JSON array builder. * @throws NullPointerException if {@code values} is {@code null}. */ public static JsonArrayBuilder newArrayBuilder(final Iterable<? extends JsonValue> values) { return newArrayBuilder().addAll(values); }
/** * Returns an instance of {@code JsonArray} which contains the given values. * This method tries to determine the appropriate {@link JsonValue}-counterpart for each * item of the specified Iterable. * * @param values the values of the returned JsonArray. {@code null} items are * @return the JsonArray. * @throws NullPointerException if {@code values} is {@code null}. * @throws JsonParseException if any item of {@code values} cannot be converted to * {@code JsonValue}. */ static <T> JsonArray of(final Iterable<T> values) { requireNonNull(values, "The values of the array must not be null!"); if (values instanceof JsonValue) { return JsonFactory.newArrayBuilder().add((JsonValue) values).build(); } return StreamSupport.stream(values.spliterator(), false) .map(JsonFactory::getAppropriateValue) .collect(JsonCollectors.valuesToArray()); }
private Builder() { this(JsonArray.newBuilder().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); }
/** * Returns a new mutable builder for a {@code JsonArray} which is already initialised with the given values. * * @param values the values of the JSON array to be created. This might be an existing JSON array as well. * @return a new JSON array builder. * @throws NullPointerException if {@code values} is {@code null}. */ public static JsonArrayBuilder newArrayBuilder(final Iterable<? extends JsonValue> values) { final JsonArrayBuilder result = ImmutableJsonArrayBuilder.newInstance(); result.addAll(values); return result; }
/** * Returns an instance of {@code JsonArray} which contains the given values. * This method tries to determine the appropriate {@link JsonValue}-counterpart for each * given value. * * @param value the mandatory value of the returned JsonArray. * @param furtherValues further optional values of the returned JsonArray. * @return the JsonArray. * @throws NullPointerException if {@code furtherValues} is {@code null}. * @throws JsonParseException if either {@code value} or any item of {@code furtherValues} * cannot be converted to {@code JsonValue}. */ @SuppressWarnings("unchecked") static <T> JsonArray of(@Nullable final T value, final T... furtherValues) { final JsonArrayBuilder arrayBuilder = newBuilder(); arrayBuilder.add(JsonFactory.getAppropriateValue(value)); for (final T furtherValue : furtherValues) { arrayBuilder.add(JsonFactory.getAppropriateValue(furtherValue)); } return arrayBuilder.build(); }