Class 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 AsyncCustomPager implements 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
         }
    • 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.
      boolean hasNext()
      Returns whether there is a next page available.
      boolean hasPrevious()
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AsyncCustomPager

        public AsyncCustomPager()
    • 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 API
        client - The async HTTP client to use for subsequent requests
        requestOptions - Request options for authentication, headers, etc.
        Returns:
        A CompletableFuture containing the new AsyncCustomPager instance
      • hasNext

        public boolean hasNext()
        Description copied from interface: BiDirectionalPage
        Returns whether there is a next page available.
        Specified by:
        hasNext in interface BiDirectionalPage<T>
        Returns:
        true if next page exists and can be fetched
      • hasPrevious

        public boolean hasPrevious()
        Description copied from interface: BiDirectionalPage
        Returns whether there is a previous page available.
        Specified by:
        hasPrevious in interface BiDirectionalPage<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: BiDirectionalPage
        Fetches and returns the next page.
        Specified by:
        nextPage in interface BiDirectionalPage<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: BiDirectionalPage
        Fetches and returns the previous page.
        Specified by:
        previousPage in interface BiDirectionalPage<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: BiDirectionalPage
        Returns the items in the current page.
        Specified by:
        getItems in interface BiDirectionalPage<T>
        Returns:
        list of items in this page
      • getResponse

        public <R> java.util.Optional<R> getResponse()
        Description copied from interface: BiDirectionalPage
        Returns the full response object for accessing pagination metadata.
        Specified by:
        getResponse in interface BiDirectionalPage<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