Class Pager<T>

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

    public class Pager<T>
    extends java.lang.Object
    implements java.util.Iterator<java.util.List<T>>, org.gitlab4j.models.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());
           }
       }
     
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface org.gitlab4j.models.Constants

        org.gitlab4j.models.Constants.ActionType, org.gitlab4j.models.Constants.ApplicationScope, org.gitlab4j.models.Constants.ArchiveFormat, org.gitlab4j.models.Constants.AutoCancelPendingPipelines, org.gitlab4j.models.Constants.AutoDevopsDeployStrategy, org.gitlab4j.models.Constants.BuildGitStrategy, org.gitlab4j.models.Constants.CommitBuildState, org.gitlab4j.models.Constants.ContributorOrderBy, org.gitlab4j.models.Constants.DefaultBranchProtectionLevel, org.gitlab4j.models.Constants.DeploymentOrderBy, org.gitlab4j.models.Constants.DeploymentStatus, org.gitlab4j.models.Constants.DeployTokenScope, org.gitlab4j.models.Constants.Encoding, org.gitlab4j.models.Constants.EpicOrderBy, org.gitlab4j.models.Constants.EventScope, org.gitlab4j.models.Constants.GroupOrderBy, org.gitlab4j.models.Constants.GroupSearchScope<T extends java.lang.Object>, org.gitlab4j.models.Constants.ImpersonationState, org.gitlab4j.models.Constants.IssueOrderBy, org.gitlab4j.models.Constants.IssueScope, org.gitlab4j.models.Constants.IssueState, org.gitlab4j.models.Constants.JobScope, org.gitlab4j.models.Constants.LineType, org.gitlab4j.models.Constants.MergeRequestOrderBy, org.gitlab4j.models.Constants.MergeRequestScope, org.gitlab4j.models.Constants.MergeRequestSearchIn, org.gitlab4j.models.Constants.MergeRequestState, org.gitlab4j.models.Constants.MilestoneState, org.gitlab4j.models.Constants.PackageOrderBy, org.gitlab4j.models.Constants.PackageStatus, org.gitlab4j.models.Constants.PipelineOrderBy, org.gitlab4j.models.Constants.PipelineScope, org.gitlab4j.models.Constants.PipelineSource, org.gitlab4j.models.Constants.ProjectAccessTokenScope, org.gitlab4j.models.Constants.ProjectCreationLevel, org.gitlab4j.models.Constants.ProjectFeatureVisibilityAccessLevel, org.gitlab4j.models.Constants.ProjectOrderBy, org.gitlab4j.models.Constants.ProjectSearchScope<T extends java.lang.Object>, org.gitlab4j.models.Constants.SearchScope<T extends java.lang.Object>, org.gitlab4j.models.Constants.SortOrder, org.gitlab4j.models.Constants.SquashOption, org.gitlab4j.models.Constants.StateEvent, org.gitlab4j.models.Constants.SubgroupCreationLevel, org.gitlab4j.models.Constants.TagOrderBy, org.gitlab4j.models.Constants.TargetType, org.gitlab4j.models.Constants.TodoAction, org.gitlab4j.models.Constants.TodoState, org.gitlab4j.models.Constants.TodoType, org.gitlab4j.models.Constants.TokenType
    • Field Summary

      • Fields inherited from interface org.gitlab4j.models.Constants

        NEXT_PAGE_HEADER, PAGE_HEADER, PAGE_PARAM, PER_PAGE, PER_PAGE_PARAM, PREV_PAGE_HEADER, TOTAL_HEADER, TOTAL_PAGES_HEADER
    • Constructor Summary

      Constructors 
      Constructor Description
      Pager​(AbstractApi api, java.lang.Class<T> type, int itemsPerPage, jakarta.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.String> queryParams, java.lang.Object... pathArgs)
      Creates a Pager instance to access the API through the specified path and query parameters.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<T> all()
      Gets all the items from each page as a single List instance.
      java.util.List<T> current()
      Returns the current page of List.
      java.util.List<T> first()
      Returns the first page of List.
      int getCurrentPage()
      Get the current page of the iteration.
      int getItemsPerPage()
      Get the items per page value.
      int getTotalItems()
      Get the total number of items (T instances) returned by the GitLab API.
      int getTotalPages()
      Get the total number of pages returned by the GitLab API.
      boolean hasNext()
      Returns the true if there are additional pages to iterate over, otherwise returns false.
      java.util.List<T> last()
      Returns the last page of List.
      java.util.stream.Stream<T> lazyStream()
      Creates a Stream instance for lazily streaming items from the GitLab server.
      java.util.List<T> next()
      Returns the next List in the iteration containing the next page of objects.
      java.util.List<T> page​(int pageNumber)
      Returns the specified page of List.
      java.util.List<T> previous()
      Returns the previous page of List.
      void remove()
      This method is not implemented and will throw an UnsupportedOperationException if called.
      java.util.stream.Stream<T> stream()
      Builds and returns a Stream instance which is pre-populated with all items from all pages.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Iterator

        forEachRemaining
    • Constructor Detail

      • Pager

        public Pager​(AbstractApi api,
                     java.lang.Class<T> type,
                     int itemsPerPage,
                     jakarta.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.String> queryParams,
                     java.lang.Object... pathArgs)
              throws GitLabApiException
        Creates a Pager instance to access the API through the specified path and query parameters.
        Parameters:
        api - the AbstractApi implementation to communicate through
        type - the GitLab4J type that will be contained in the List
        itemsPerPage - items per page
        queryParams - HTTP query params
        pathArgs - HTTP path arguments
        Throws:
        GitLabApiException - if any error occurs
    • 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 java.util.Iterator<T>
        Returns:
        true if there are additional pages to iterate over, otherwise returns false
      • next

        public java.util.List<T> next()
        Returns the next List in the iteration containing the next page of objects.
        Specified by:
        next in interface java.util.Iterator<T>
        Returns:
        the next List in the iteration
        Throws:
        java.util.NoSuchElementException - if the iteration has no more elements
        java.lang.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 java.util.Iterator<T>
        Throws:
        java.lang.UnsupportedOperationException - when invoked
      • first

        public java.util.List<T> first()
        Returns the first page of List. Will rewind the iterator.
        Returns:
        the first page of List
      • last

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

        public java.util.List<T> previous()
        Returns the previous page of List. Will set the iterator to the previous page.
        Returns:
        the previous page of List
      • current

        public java.util.List<T> current()
        Returns the current page of List.
        Returns:
        the current page of List
      • page

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

        public java.util.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
      • stream

        public java.util.stream.Stream<T> stream()
                                          throws GitLabApiException,
                                                 java.lang.IllegalStateException
        Builds and returns a Stream instance which is pre-populated with all items from all pages.
        Returns:
        a Stream instance which is pre-populated with all items from all pages
        Throws:
        java.lang.IllegalStateException - if Stream has already been issued
        GitLabApiException - if any other error occurs
      • lazyStream

        public java.util.stream.Stream<T> lazyStream()
                                              throws java.lang.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:
        java.lang.IllegalStateException - if Stream has already been issued