Package com.intercom.api.core.pagination
Class CustomPager<T>
- java.lang.Object
-
- com.intercom.api.core.pagination.CustomPager<T>
-
- Type Parameters:
T- The type of items in the page
- All Implemented Interfaces:
BiDirectionalPage<T>,java.lang.Iterable<T>
public class CustomPager<T> extends java.lang.Object implements BiDirectionalPage<T>, java.lang.Iterable<T>
Skeleton implementation for custom 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 pagination logic that handles your API's specific pagination structure (e.g., HATEOAS links). Example implementation for HATEOAS-style pagination:{@code public class CustomPagerimplements BiDirectionalPage , Iterable { private final List items; private final String nextUrl; private final String previousUrl; private final OkHttpClient client; private final TypeReference > responseType; public CustomPager(Response response, OkHttpClient client, ...) { this.items = response.getData(); this.nextUrl = response.getLinks().getNext(); this.previousUrl = response.getLinks().getPrevious(); // ... store other needed context }
-
-
Constructor Summary
Constructors Constructor Description CustomPager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> CustomPager<T>create(java.lang.Object initialResponse, okhttp3.OkHttpClient client, java.lang.Object requestOptions)Create a CustomPager from an initial response.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.java.util.Iterator<T>iterator()BiDirectionalPage<T>nextPage()Fetches and returns the next page.BiDirectionalPage<T>previousPage()Fetches and returns the previous page.
-
-
-
Method Detail
-
create
public static <T> CustomPager<T> create(java.lang.Object initialResponse, okhttp3.OkHttpClient client, java.lang.Object requestOptions) throws java.io.IOException
Create a CustomPager from an initial response.- Parameters:
initialResponse- The first page response from the APIclient- The HTTP client to use for subsequent requestsrequestOptions- Request options for authentication, headers, etc.- Returns:
- A new CustomPager instance
- Throws:
java.io.IOException- if the request fails
-
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
-
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
-
-