Package com.intercom.api.core.pagination
Class AsyncCustomPager<T>
- java.lang.Object
-
- com.intercom.api.core.pagination.AsyncCustomPager<T>
-
- Type Parameters:
T- The type of items in the page
- All Implemented Interfaces:
BiDirectionalPage<T>
public class AsyncCustomPager<T> extends java.lang.Object implements BiDirectionalPage<T>
Skeleton implementation for custom asynchronous bidirectional pagination. THIS CLASS MUST BE IMPLEMENTED BY THE USER. This file is added to .fernignore and will not be regenerated. Replace this skeleton implementation with your custom async pagination logic that handles your API's specific pagination structure (e.g., HATEOAS links). Example implementation for HATEOAS-style async pagination:{@code public class AsyncCustomPagerimplements BiDirectionalPage { private final List items; private final String nextUrl; private final String previousUrl; private final AsyncHttpClient client; public AsyncCustomPager(Response response, AsyncHttpClient client, ...) { this.items = response.getData(); this.nextUrl = response.getLinks().getNext(); this.previousUrl = response.getLinks().getPrevious(); // ... store other needed context }
-
-
Constructor Summary
Constructors Constructor Description AsyncCustomPager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> java.util.concurrent.CompletableFuture<AsyncCustomPager<T>>createAsync(java.lang.Object initialResponse, okhttp3.OkHttpClient client, java.lang.Object requestOptions)Create an AsyncCustomPager from an initial response.java.util.concurrent.CompletableFuture<java.lang.Void>forEachPageAsync(java.util.function.Function<java.util.List<T>,java.util.concurrent.CompletionStage<java.lang.Void>> pageProcessor)Process each page asynchronously as it arrives.java.util.concurrent.CompletableFuture<java.util.List<T>>getAllItemsAsync()Asynchronously iterate through all pages starting from current.java.util.List<T>getItems()Returns the items in the current page.<R> java.util.Optional<R>getResponse()Returns the full response object for accessing pagination metadata.booleanhasNext()Returns whether there is a next page available.booleanhasPrevious()Returns whether there is a previous page available.BiDirectionalPage<T>nextPage()Fetches and returns the next page.java.util.concurrent.CompletableFuture<BiDirectionalPage<T>>nextPageAsync()Asynchronously fetch the next page.BiDirectionalPage<T>previousPage()Fetches and returns the previous page.java.util.concurrent.CompletableFuture<BiDirectionalPage<T>>previousPageAsync()Asynchronously fetch the previous page.
-
-
-
Method Detail
-
createAsync
public static <T> java.util.concurrent.CompletableFuture<AsyncCustomPager<T>> createAsync(java.lang.Object initialResponse, okhttp3.OkHttpClient client, java.lang.Object requestOptions)
Create an AsyncCustomPager from an initial response.- Parameters:
initialResponse- The first page response from the APIclient- The async HTTP client to use for subsequent requestsrequestOptions- Request options for authentication, headers, etc.- Returns:
- A CompletableFuture containing the new AsyncCustomPager instance
-
hasNext
public boolean hasNext()
Description copied from interface:BiDirectionalPageReturns whether there is a next page available.- Specified by:
hasNextin interfaceBiDirectionalPage<T>- Returns:
- true if next page exists and can be fetched
-
hasPrevious
public boolean hasPrevious()
Description copied from interface:BiDirectionalPageReturns whether there is a previous page available.- Specified by:
hasPreviousin interfaceBiDirectionalPage<T>- Returns:
- true if previous page exists and can be fetched
-
nextPageAsync
public java.util.concurrent.CompletableFuture<BiDirectionalPage<T>> nextPageAsync()
Asynchronously fetch the next page.- Returns:
- A CompletableFuture that completes with the next page
- Throws:
java.util.NoSuchElementException- if no next page exists (wrapped in CompletableFuture)
-
previousPageAsync
public java.util.concurrent.CompletableFuture<BiDirectionalPage<T>> previousPageAsync()
Asynchronously fetch the previous page.- Returns:
- A CompletableFuture that completes with the previous page
- Throws:
java.util.NoSuchElementException- if no previous page exists (wrapped in CompletableFuture)
-
nextPage
public BiDirectionalPage<T> nextPage() throws java.io.IOException
Description copied from interface:BiDirectionalPageFetches and returns the next page.- Specified by:
nextPagein interfaceBiDirectionalPage<T>- Returns:
- the next page
- Throws:
java.io.IOException- if the HTTP request fails
-
previousPage
public BiDirectionalPage<T> previousPage() throws java.io.IOException
Description copied from interface:BiDirectionalPageFetches and returns the previous page.- Specified by:
previousPagein interfaceBiDirectionalPage<T>- Returns:
- the previous page
- Throws:
java.io.IOException- if the HTTP request fails
-
getItems
public java.util.List<T> getItems()
Description copied from interface:BiDirectionalPageReturns the items in the current page.- Specified by:
getItemsin interfaceBiDirectionalPage<T>- Returns:
- list of items in this page
-
getResponse
public <R> java.util.Optional<R> getResponse()
Description copied from interface:BiDirectionalPageReturns the full response object for accessing pagination metadata.- Specified by:
getResponsein interfaceBiDirectionalPage<T>- Returns:
- Optional containing the response, or empty if unavailable
-
getAllItemsAsync
public java.util.concurrent.CompletableFuture<java.util.List<T>> getAllItemsAsync()
Asynchronously iterate through all pages starting from current. Returns a CompletableFuture that completes with all items from all pages.- Returns:
- CompletableFuture containing all items across all pages
-
forEachPageAsync
public java.util.concurrent.CompletableFuture<java.lang.Void> forEachPageAsync(java.util.function.Function<java.util.List<T>,java.util.concurrent.CompletionStage<java.lang.Void>> pageProcessor)
Process each page asynchronously as it arrives.- Parameters:
pageProcessor- Function to process each page- Returns:
- CompletableFuture that completes when all pages are processed
-
-