PagedIterable<T> Class
- java.
lang. Object - com.
azure. core. util. IterableStream<T> - com.
azure. core. util. paging. ContinuablePagedIterable<C,T,P> - com.
azure. core. http. rest. PagedIterableBase<T,P> - com.
azure. core. http. rest. PagedIterable<T>
- com.
- com.
- com.
- com.
Type Parameters
- T
The type of value contained in this IterableStream.
public class PagedIterable
extends PagedIterableBase<T,PagedResponse<T>>
This class provides utility to iterate over PagedResponse<T> using Stream and Iterable interfaces.
Code sample using Stream by page
// process the streamByPage
pagedIterableResponse.streamByPage().forEach(resp -> {
System.out.printf("Response headers are %s. Url %s and status code %d %n", resp.getHeaders(),
resp.getRequest().getUrl(), resp.getStatusCode());
resp.getElements().forEach(value -> System.out.printf("Response value is %d %n", value));
});
Code sample using Iterable by page
// process the iterableByPage
pagedIterableResponse.iterableByPage().forEach(resp -> {
System.out.printf("Response headers are %s. Url %s and status code %d %n", resp.getHeaders(),
resp.getRequest().getUrl(), resp.getStatusCode());
resp.getElements().forEach(value -> System.out.printf("Response value is %d %n", value));
});
Code sample using Iterable by page and while loop
// iterate over each page
for (PagedResponse<Integer> resp : pagedIterableResponse.iterableByPage()) {
System.out.printf("Response headers are %s. Url %s and status code %d %n", resp.getHeaders(),
resp.getRequest().getUrl(), resp.getStatusCode());
resp.getElements().forEach(value -> System.out.printf("Response value is %d %n", value));
}
Code sample using Iterable by page and continuation token
String continuationToken = getContinuationToken();
pagedIterable
.iterableByPage(continuationToken)
.forEach(page -> System.out.printf("Processing page containing item values: %s%n",
page.getElements().stream().map(String::valueOf).collect(Collectors.joining(", "))));
Constructor Summary
Constructor | Description |
---|---|
PagedIterable(PagedFlux<T> pagedFlux) |
Creates instance given PagedFlux<T>. |
PagedIterable(Function<Integer,PagedResponse<T>> firstPageRetriever) |
Creates an instance of PagedIterable<T> that consists of only a single page with a given element count. |
PagedIterable(Function<Integer,PagedResponse<T>> firstPageRetriever, BiFunction<String,Integer,PagedResponse<T>> nextPageRetriever) |
Creates an instance of PagedIterable<T> that is capable of retrieving multiple pages with of a given page size. |
PagedIterable(Supplier<PagedResponse<T>> firstPageRetriever) |
Creates an instance of PagedIterable<T> that consists of only a single page. |
PagedIterable(Supplier<PagedResponse<T>> firstPageRetriever, Function<String,PagedResponse<T>> nextPageRetriever) |
Creates an instance of PagedIterable<T>. |
Method Summary
Modifier and Type | Method and Description |
---|---|
Paged |
mapPage(Function<T,S> mapper)
Maps this Paged |
Methods inherited from IterableStream
Methods inherited from ContinuablePagedIterable
Methods inherited from java.lang.Object
Constructor Details
PagedIterable
public PagedIterable(PagedFlux
Creates instance given PagedFlux<T>.
Parameters:
PagedIterable
public PagedIterable(Function
Creates an instance of PagedIterable<T> that consists of only a single page with a given element count.
Code sample
// A function that fetches the single page of data from a source/service.
Function<Integer, Mono<PagedResponse<Integer>>> singlePageRetriever = pageSize ->
getFirstPageWithSize(pageSize);
PagedFlux<Integer> singlePageFluxWithPageSize = new PagedFlux<Integer>(singlePageRetriever);
Parameters:
PagedIterable
public PagedIterable(Function
Creates an instance of PagedIterable<T> that is capable of retrieving multiple pages with of a given page size.
Code sample
// A function that fetches the first page of data from a source/service.
Function<Integer, PagedResponse<Integer>> firstPageRetriever = pageSize -> getPage(pageSize);
// A function that fetches subsequent pages of data from a source/service given a continuation token.
BiFunction<String, Integer, PagedResponse<Integer>> nextPageRetriever = (continuationToken, pageSize) ->
getPage(continuationToken, pageSize);
PagedIterable<Integer> pagedIterableWithPageSize = new PagedIterable<>(firstPageRetriever, nextPageRetriever);
Parameters:
PagedIterable
public PagedIterable(Supplier
Creates an instance of PagedIterable<T> that consists of only a single page. This constructor takes a Supplier
that return the single page of T
.
Code sample
// A supplier that fetches the first page of data from source/service
Supplier<PagedResponse<Integer>> firstPageRetrieverFunction = () -> getFirstPage();
PagedIterable<Integer> pagedIterableInstance = new PagedIterable<>(firstPageRetrieverFunction,
nextPageRetriever);
Parameters:
PagedIterable
public PagedIterable(Supplier
Creates an instance of PagedIterable<T>. The constructor takes a Supplier
and Function
. The Supplier
returns the first page of T
, the Function
retrieves subsequent pages of T
.
Code sample
// A supplier that fetches the first page of data from source/service
Supplier<PagedResponse<Integer>> firstPageRetriever = () -> getFirstPage();
// A function that fetches subsequent pages of data from source/service given a continuation token
Function<String, PagedResponse<Integer>> nextPageRetriever =
continuationToken -> getNextPage(continuationToken);
PagedIterable<Integer> pagedIterable = new PagedIterable<>(firstPageRetriever,
nextPageRetriever);
Parameters:
Method Details
mapPage
public PagedIterable mapPage(Function
Maps this PagedIterable instance of T to a PagedIterable instance of type S as per the provided mapper function.
Parameters:
Returns:
Applies to
Azure SDK for Java