@Override public SearchResultBuilder add(final JsonValue value, final JsonValue... furtherValues) { jsonArrayBuilder.add(value, furtherValues); return this; }
@Override public SearchResultBuilder add(final JsonValue value, final JsonValue... furtherValues) { jsonArrayBuilder.add(value, furtherValues); 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); }
/** * <p> * Returns a {@code Collector} that accumulates the values of input JSON fields into a new {@code JsonArray}. The * keys are hereby dismissed. * </p> * <p> * <em>Caution:</em> Due to the fact that each field of a JSON object can have a different type the resulting * array will also consist of values of different types! * </p> * * @return a {@code Collector} which collects the values of all the JSON fields into a {@code JsonArray}, in * encounter order. */ public static Collector<JsonField, JsonArrayBuilder, JsonArray> fieldValuesToArray() { return Collector.of(JsonFactory::newArrayBuilder, (arrayBuilder, field) -> arrayBuilder.add(field.getValue()), JsonArrayBuilder::addAll, JsonArrayBuilder::build); }
/** * <p> * Returns a {@code Collector} that accumulates the values of input JSON fields into a new {@code JsonArray}. The * keys are hereby dismissed. * </p> * <p> * <em>Caution:</em> Due to the fact that each field of a JSON object can have a different type the resulting * array will also consist of values of different types! * </p> * * @return a {@code Collector} which collects the values of all the JSON fields into a {@code JsonArray}, in * encounter order. */ public static Collector<JsonField, JsonArrayBuilder, JsonArray> fieldValuesToArray() { return Collector.of(JsonFactory::newArrayBuilder, (arrayBuilder, field) -> arrayBuilder.add(field.getValue()), JsonArrayBuilder::addAll, JsonArrayBuilder::build); }
/** * 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 JsonArray getChildrenAsArray() { // performance shortcut if (children.isEmpty()) { return JsonFactory.newArray(); } final JsonArrayBuilder arrayBuilder = JsonArray.newBuilder(); children.forEach(child -> arrayBuilder.add(child.toJson())); return arrayBuilder.build(); }
private JsonArray getChildrenAsArray() { // performance shortcut if (children.isEmpty()) { return JsonFactory.newArray(); } final JsonArrayBuilder arrayBuilder = JsonArray.newBuilder(); children.forEach(child -> arrayBuilder.add(child.toJson())); return arrayBuilder.build(); }
private JsonArray getDetailsAsArray() { // performance shortcut if (details.isEmpty()) { return JsonFactory.newArray(); } final JsonArrayBuilder arrayBuilder = JsonArray.newBuilder(); details.forEach(detailMessage -> arrayBuilder.add(detailMessage.toJson())); return arrayBuilder.build(); }
private JsonArray getDetailsAsArray() { // performance shortcut if (details.isEmpty()) { return JsonFactory.newArray(); } final JsonArrayBuilder arrayBuilder = JsonArray.newBuilder(); details.forEach(detailMessage -> arrayBuilder.add(detailMessage.toJson())); return arrayBuilder.build(); }
/** * 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(); }
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(); }
@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 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(); }