Class Pager<T>

  • Type Parameters:
    T - the GitLab4J type contained in the List.
    All Implemented Interfaces:
    Iterator<List<T>>, Constants

    public class Pager<T>
    extends Object
    implements Iterator<List<T>>, Constants

    This class defines an Iterator implementation that is used as a paging iterator for all API methods that return a List of objects. It hides the details of interacting with the GitLab API when paging is involved simplifying accessing large lists of objects.

    Example usage:

       // Get a Pager instance that will page through the projects with 10 projects per page
       Pager<Project> projectPager = gitlabApi.getProjectsApi().getProjectsPager(10);
    
       // Iterate through the pages and print out the name and description
       while (projectsPager.hasNext())) {
           List<Project> projects = projectsPager.next();
           for (Project project : projects) {
               System.out.println(project.getName() + " : " + project.getDescription());
           }
       }
     
    • Method Detail

      • getItemsPerPage

        public int getItemsPerPage()
        Get the items per page value.
        Returns:
        the items per page value
      • getTotalPages

        public int getTotalPages()
        Get the total number of pages returned by the GitLab API.
        Returns:
        the total number of pages returned by the GitLab API, or -1 if the Kaminari limit of 10,000 has been exceeded
      • getTotalItems

        public int getTotalItems()
        Get the total number of items (T instances) returned by the GitLab API.
        Returns:
        the total number of items (T instances) returned by the GitLab API, or -1 if the Kaminari limit of 10,000 has been exceeded
      • getCurrentPage

        public int getCurrentPage()
        Get the current page of the iteration.
        Returns:
        the current page of the iteration
      • hasNext

        public boolean hasNext()
        Returns the true if there are additional pages to iterate over, otherwise returns false.
        Specified by:
        hasNext in interface Iterator<T>
        Returns:
        true if there are additional pages to iterate over, otherwise returns false
      • next

        public List<T> next()
        Returns the next List in the iteration containing the next page of objects.
        Specified by:
        next in interface Iterator<T>
        Returns:
        the next List in the iteration
        Throws:
        NoSuchElementException - if the iteration has no more elements
        RuntimeException - if a GitLab API error occurs, will contain a wrapped GitLabApiException with the details of the error
      • remove

        public void remove()
        This method is not implemented and will throw an UnsupportedOperationException if called.
        Specified by:
        remove in interface Iterator<T>
        Throws:
        UnsupportedOperationException - when invoked
      • previous

        public List<T> previous()
                         throws GitLabApiException
        Returns the previous page of List. Will set the iterator to the previous page.
        Returns:
        the previous page of List
        Throws:
        GitLabApiException - if any error occurs
      • page

        public List<T> page​(int pageNumber)
        Returns the specified page of List.
        Parameters:
        pageNumber - the page to get
        Returns:
        the specified page of List
        Throws:
        NoSuchElementException - if the iteration has no more elements
        RuntimeException - if a GitLab API error occurs, will contain a wrapped GitLabApiException with the details of the error
      • all

        public List<T> all()
                    throws GitLabApiException
        Gets all the items from each page as a single List instance.
        Returns:
        all the items from each page as a single List instance
        Throws:
        GitLabApiException - if any error occurs
      • lazyStream

        public Stream<T> lazyStream()
                             throws IllegalStateException
        Creates a Stream instance for lazily streaming items from the GitLab server.
        Returns:
        a Stream instance for lazily streaming items from the GitLab server
        Throws:
        IllegalStateException - if Stream has already been issued