Class 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 CustomPager implements 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.
      boolean hasNext()
      Returns whether there is a next page available.
      boolean hasPrevious()
      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.
      • 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 Detail

      • CustomPager

        public CustomPager()
    • 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 API
        client - The HTTP client to use for subsequent requests
        requestOptions - 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: 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
      • 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
      • iterator

        public java.util.Iterator<T> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<T>