/** * Creates a response to a {@link RetrieveThings} command. * * @param things the retrieved Things. * @param fieldSelector the JsonFieldSelector to apply to the passed things when transforming to JSON. * @param predicate the predicate to apply to the things when transforming to JSON. * @param namespace the namespace of this retrieve things request * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if any argument is {@code null}. */ public static RetrieveThingsResponse of(final List<Thing> things, @Nullable final JsonFieldSelector fieldSelector, @Nullable final Predicate<JsonField> predicate, @Nullable final String namespace, final DittoHeaders dittoHeaders) { final JsonArray thingsArray = checkNotNull(things, PROPERTY_NAME_THINGS).stream() .map(thing -> getJsonFields(fieldSelector, predicate, dittoHeaders, thing)) .collect(JsonCollectors.valuesToArray()); return new RetrieveThingsResponse(HttpStatusCode.OK, thingsArray, thingsArray.toString(), namespace, dittoHeaders); }
/** * Creates a response to a {@link RetrieveThings} command. * * @param things the retrieved Things. * @param fieldSelector the JsonFieldSelector to apply to the passed things when transforming to JSON. * @param predicate the predicate to apply to the things when transforming to JSON. * @param namespace the namespace of this retrieve things request * @param dittoHeaders the headers of the preceding command. * @return the response. * @throws NullPointerException if any argument is {@code null}. */ public static RetrieveThingsResponse of(final List<Thing> things, @Nullable final JsonFieldSelector fieldSelector, @Nullable final Predicate<JsonField> predicate, @Nullable final String namespace, final DittoHeaders dittoHeaders) { final JsonArray thingsArray = checkNotNull(things, PROPERTY_NAME_THINGS).stream() .map(thing -> getJsonFields(fieldSelector, predicate, dittoHeaders, thing)) .collect(JsonCollectors.valuesToArray()); return new RetrieveThingsResponse(HttpStatusCode.OK, thingsArray, thingsArray.toString(), namespace, dittoHeaders); }