Package com.azure.core.http.rest
Class PagedIterable<T>
java.lang.Object
com.azure.core.util.IterableStream<T>
com.azure.core.util.paging.ContinuablePagedIterable<String,T,P>
com.azure.core.http.rest.PagedIterableBase<T,PagedResponse<T>>
com.azure.core.http.rest.PagedIterable<T>
- Type Parameters:
T
- The type of value contained in thisIterableStream
.
- All Implemented Interfaces:
Iterable<T>
This class provides utility to iterate over
PagedResponse
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(", "))));
- See Also:
-
Constructor Summary
ConstructorDescriptionPagedIterable
(PagedFlux<T> pagedFlux) Creates instance givenPagedFlux
.PagedIterable
(Function<Integer, PagedResponse<T>> firstPageRetriever) Creates an instance ofPagedIterable
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 ofPagedIterable
that is capable of retrieving multiple pages with of a given page size.PagedIterable
(Supplier<PagedResponse<T>> firstPageRetriever) Creates an instance ofPagedIterable
that consists of only a single page.PagedIterable
(Supplier<PagedResponse<T>> firstPageRetriever, Function<String, PagedResponse<T>> nextPageRetriever) Creates an instance ofPagedIterable
. -
Method Summary
Modifier and TypeMethodDescription<S> PagedIterable<S>
Maps this PagedIterable instance of T to a PagedIterable instance of type S as per the provided mapper function.Methods inherited from class com.azure.core.util.paging.ContinuablePagedIterable
iterableByPage, iterableByPage, iterableByPage, iterableByPage, iterator, stream, streamByPage, streamByPage, streamByPage, streamByPage
Methods inherited from class com.azure.core.util.IterableStream
of
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
PagedIterable
Creates instance givenPagedFlux
.- Parameters:
pagedFlux
- to use as iterable
-
PagedIterable
Creates an instance ofPagedIterable
that consists of only a single page. This constructor takes aSupplier
that return the single page ofT
.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:
firstPageRetriever
- Supplier that retrieves the first page.
-
PagedIterable
Creates an instance ofPagedIterable
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:
firstPageRetriever
- Function that retrieves the first page.
-
PagedIterable
public PagedIterable(Supplier<PagedResponse<T>> firstPageRetriever, Function<String, PagedResponse<T>> nextPageRetriever) Creates an instance ofPagedIterable
. The constructor takes aSupplier
andFunction
. TheSupplier
returns the first page ofT
, theFunction
retrieves subsequent pages ofT
.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:
firstPageRetriever
- Supplier that retrieves the first pagenextPageRetriever
- Function that retrieves the next page given a continuation token
-
PagedIterable
public PagedIterable(Function<Integer, PagedResponse<T>> firstPageRetriever, BiFunction<String, Integer, PagedResponse<T>> nextPageRetriever) Creates an instance ofPagedIterable
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:
firstPageRetriever
- Function that retrieves the first page.nextPageRetriever
- BiFunction that retrieves the next page given a continuation token and page size.
-
-
Method Details
-
mapPage
Maps this PagedIterable instance of T to a PagedIterable instance of type S as per the provided mapper function.- Type Parameters:
S
- The mapped type.- Parameters:
mapper
- The mapper function to convert from type T to type S.- Returns:
- A PagedIterable of type S.
-