/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. */ @Override public String toString() { return ToString.builder("QueryResponse").add("Items", items()).add("Count", count()).add("ScannedCount", scannedCount()) .add("LastEvaluatedKey", lastEvaluatedKey()).add("ConsumedCapacity", consumedCapacity()).build(); }
@Override public int hashCode() { int hashCode = 1; hashCode = 31 * hashCode + Objects.hashCode(items()); hashCode = 31 * hashCode + Objects.hashCode(count()); hashCode = 31 * hashCode + Objects.hashCode(scannedCount()); hashCode = 31 * hashCode + Objects.hashCode(lastEvaluatedKey()); hashCode = 31 * hashCode + Objects.hashCode(consumedCapacity()); return hashCode; }
public <T> Optional<T> getValueForField(String fieldName, Class<T> clazz) { switch (fieldName) { case "Items": return Optional.ofNullable(clazz.cast(items())); case "Count": return Optional.ofNullable(clazz.cast(count())); case "ScannedCount": return Optional.ofNullable(clazz.cast(scannedCount())); case "LastEvaluatedKey": return Optional.ofNullable(clazz.cast(lastEvaluatedKey())); case "ConsumedCapacity": return Optional.ofNullable(clazz.cast(consumedCapacity())); default: return Optional.empty(); } }
/** * Returns an iterable to iterate through the paginated {@link QueryResponse#items()} member. The returned iterable * is used to iterate through the results across all response pages and not a single page. * * This method is useful if you are interested in iterating over the paginated member in the response pages instead * of the top level pages. Similar to iteration over pages, this method internally makes service calls to get the * next list of results until the iteration stops or there are no more results. */ public final SdkIterable<Map<String, AttributeValue>> items() { Function<QueryResponse, Iterator<Map<String, AttributeValue>>> getIterator = response -> { if (response != null && response.items() != null) { return response.items().iterator(); } return Collections.emptyIterator(); }; return PaginatedItemsIterable.builder().pagesIterable(this).itemIteratorFunction(getIterator).build(); }
/** * Returns a publisher that can be used to get a stream of data. You need to subscribe to the publisher to request * the stream of data. The publisher has a helper forEach method that takes in a {@link java.util.function.Consumer} * and then applies that consumer to each response returned by the service. */ public final SdkPublisher<Map<String, AttributeValue>> items() { Function<QueryResponse, Iterator<Map<String, AttributeValue>>> getIterator = response -> { if (response != null && response.items() != null) { return response.items().iterator(); } return Collections.emptyIterator(); }; return PaginatedItemsPublisher.builder().nextPageFetcher(new QueryResponseFetcher()).iteratorFunction(getIterator) .isLastPage(isLastPage).build(); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof QueryResponse)) { return false; } QueryResponse other = (QueryResponse) obj; return Objects.equals(items(), other.items()) && Objects.equals(count(), other.count()) && Objects.equals(scannedCount(), other.scannedCount()) && Objects.equals(lastEvaluatedKey(), other.lastEvaluatedKey()) && Objects.equals(consumedCapacity(), other.consumedCapacity()); }