/** * Returns a new mutable builder with a fluent API for a {@code JsonArray}. The returned builder is already * initialised with the data of the this JSON array. This method is useful if an existing JSON array should be * strongly modified but the amount of creating objects should be kept low at the same time. * * @return a new JSON array builder with pre-filled data of this JSON array. */ default JsonArrayBuilder toBuilder() { return JsonFactory.newArrayBuilder(this); }
/** * Returns a new mutable builder with a fluent API for a {@code JsonArray}. * * @return a new JSON array builder. */ static JsonArrayBuilder newBuilder() { return JsonFactory.newArrayBuilder(); }
/** * Returns a new mutable builder with a fluent API for a {@code JsonArray}. * * @return a new JSON array builder. */ static JsonArrayBuilder newBuilder() { return JsonFactory.newArrayBuilder(); }
/** * Returns a new mutable builder with a fluent API for a {@code JsonArray}. The returned builder is already * initialised with the data of the this JSON array. This method is useful if an existing JSON array should be * strongly modified but the amount of creating objects should be kept low at the same time. * * @return a new JSON array builder with pre-filled data of this JSON array. */ default JsonArrayBuilder toBuilder() { return JsonFactory.newArrayBuilder(this); }
@Override public JsonArray toJson() { final JsonArrayBuilder jsonArrayBuilder = JsonFactory.newArrayBuilder(); permissions.forEach(jsonArrayBuilder::add); return jsonArrayBuilder.build(); }
/** * Returns a new instance of {@code ImmutableSearchResultBuilder}. * * @return a new builder. */ public static ImmutableSearchResultBuilder newInstance() { return new ImmutableSearchResultBuilder(JsonFactory.newArrayBuilder(), SearchResult.NO_NEXT_PAGE); }
/** * Returns a new instance of {@code ImmutableSearchResultBuilder}. * * @return a new builder. */ public static ImmutableSearchResultBuilder newInstance() { return new ImmutableSearchResultBuilder(JsonFactory.newArrayBuilder(), SearchResult.NO_NEXT_PAGE); }
/** * 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()); }
/** * Returns a new instance of {@code ImmutableSearchResultBuilder} which is initialised with the properties of the * given Search result. * * @param searchResult the search result which provides the initial properties of the returned builder. * @return the new builder. * @throws NullPointerException if {@code searchResult} is null. */ public static ImmutableSearchResultBuilder of(final SearchResult searchResult) { checkNotNull(searchResult, "search result"); final JsonArrayBuilder jsonArrayBuilder = JsonFactory.newArrayBuilder(searchResult.getItems()); return new ImmutableSearchResultBuilder(jsonArrayBuilder, searchResult.getNextPageOffset()); }
/** * Returns a new instance of {@code ImmutableSearchResultBuilder} which is initialised with the properties of the * given Search result. * * @param searchResult the search result which provides the initial properties of the returned builder. * @return the new builder. * @throws NullPointerException if {@code searchResult} is null. */ public static ImmutableSearchResultBuilder of(final SearchResult searchResult) { checkNotNull(searchResult, "search result"); final JsonArrayBuilder jsonArrayBuilder = JsonFactory.newArrayBuilder(searchResult.getItems()); return new ImmutableSearchResultBuilder(jsonArrayBuilder, searchResult.getNextPageOffset()); }
@Override public JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> predicate) { final JsonArrayBuilder jsonArrayBuilder = JsonFactory.newArrayBuilder(); searchNamespaceResultEntries.forEach((id, entry) -> jsonArrayBuilder.add(entry.toJson())); final JsonArray jsonArray = jsonArrayBuilder.build(); return JsonFactory.newObjectBuilder() .set(SCHEMA_VERSION, schemaVersion.toInt(), predicate) .set(NAMESPACES, jsonArray, predicate) .build(); }
@Override public JsonObject toJson(final Predicate<JsonField> predicate) { final JsonSchemaVersion jsonSchemaVersion = JsonSchemaVersion.V_1; final JsonArrayBuilder jsonArrayBuilder = JsonFactory.newArrayBuilder(); searchNamespaceResultEntries.forEach((id, entry) -> jsonArrayBuilder.add(entry.toJson())); final JsonArray jsonArray = jsonArrayBuilder.build(); return JsonFactory.newObjectBuilder() .set(SCHEMA_VERSION, jsonSchemaVersion.toInt(), predicate) .set(NAMESPACES, jsonArray, predicate) .build(); }
@Override public JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> predicate) { final JsonArrayBuilder jsonArrayBuilder = JsonFactory.newArrayBuilder(); searchNamespaceResultEntries.forEach((id, entry) -> jsonArrayBuilder.add(entry.toJson())); final JsonArray jsonArray = jsonArrayBuilder.build(); return JsonFactory.newObjectBuilder() .set(SCHEMA_VERSION, schemaVersion.toInt(), predicate) .set(NAMESPACES, jsonArray, predicate) .build(); }
@Override public JsonObject toJson(final Predicate<JsonField> predicate) { final JsonSchemaVersion jsonSchemaVersion = JsonSchemaVersion.V_1; final JsonArrayBuilder jsonArrayBuilder = JsonFactory.newArrayBuilder(); searchNamespaceResultEntries.forEach((id, entry) -> jsonArrayBuilder.add(entry.toJson())); final JsonArray jsonArray = jsonArrayBuilder.build(); return JsonFactory.newObjectBuilder() .set(SCHEMA_VERSION, jsonSchemaVersion.toInt(), predicate) .set(NAMESPACES, jsonArray, predicate) .build(); }
private static JsonArray mergeJsonArrays(final JsonArray array1, final JsonArray array2) { final JsonArray longerArray = array1.getSize() >= array2.getSize() ? array1 : array2; final int longerSize = longerArray.getSize(); final int shorterSize = Math.min(array1.getSize(), array2.getSize()); final JsonArrayBuilder builder = JsonFactory.newArrayBuilder(); for (int i = 0; i < shorterSize; ++i) { builder.add(mergeJsonValues(getOrThrow(array1, i), getOrThrow(array2, i))); } for (int i = shorterSize; i < longerSize; ++ i) { builder.add(getOrThrow(longerArray, i)); } return builder.build(); }