Package org.gitlab4j.api
Class Pager<T>
java.lang.Object
org.gitlab4j.api.Pager<T>
- Type Parameters:
T
- the GitLab4J type contained in the List.
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.api.Constants
Constants.ActionType, Constants.ApplicationScope, Constants.ArchiveFormat, Constants.AutoDevopsDeployStrategy, Constants.BuildGitStrategy, Constants.CommitBuildState, Constants.ContributorOrderBy, Constants.DeploymentOrderBy, Constants.DeploymentStatus, Constants.DeployTokenScope, Constants.Encoding, Constants.EpicOrderBy, Constants.EventScope, Constants.GroupOrderBy, Constants.GroupSearchScope, Constants.ImpersonationState, Constants.IssueOrderBy, Constants.IssueScope, Constants.IssueState, Constants.JobScope, Constants.LineType, Constants.MergeRequestOrderBy, Constants.MergeRequestScope, Constants.MergeRequestSearchIn, Constants.MergeRequestState, Constants.MilestoneState, Constants.PackageOrderBy, Constants.PackageStatus, Constants.PipelineOrderBy, Constants.PipelineScope, Constants.ProjectOrderBy, Constants.ProjectSearchScope, Constants.SearchScope, Constants.SortOrder, Constants.SquashOption, Constants.StateEvent, Constants.TagOrderBy, Constants.TargetType, Constants.TodoAction, Constants.TodoState, Constants.TodoType, Constants.TokenType
-
Field Summary
Fields inherited from interface org.gitlab4j.api.Constants
NEXT_PAGE_HEADER, PAGE_HEADER, PAGE_PARAM, PER_PAGE, PER_PAGE_PARAM, PREV_PAGE_HEADER, TOTAL_HEADER, TOTAL_PAGES_HEADER
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionall()
Gets all the items from each page as a single List instance.current()
Returns the current page of List.first()
Returns the first page of List.int
Get the current page of the iteration.int
Get the items per page value.int
Get the total number of items (T instances) returned by the GitLab API.int
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.last()
Returns the last page of List.Creates a Stream instance for lazily streaming items from the GitLab server.next()
Returns the next List in the iteration containing the next page of objects.page
(int pageNumber) Returns the specified page of List.previous()
Returns the previous page of List.void
remove()
This method is not implemented and will throw an UnsupportedOperationException if called.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 Details
-
Pager
public Pager(AbstractApi api, Class<T> type, int itemsPerPage, jakarta.ws.rs.core.MultivaluedMap<String, String> queryParams, Object... pathArgs) throws GitLabApiExceptionCreates a Pager instance to access the API through the specified path and query parameters.- Parameters:
api
- the AbstractApi implementation to communicate throughtype
- the GitLab4J type that will be contained in the ListitemsPerPage
- items per pagequeryParams
- HTTP query paramspathArgs
- HTTP path arguments- Throws:
GitLabApiException
- if any error occurs
-
-
Method Details
-
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. -
next
Returns the next List in the iteration containing the next page of objects.- Specified by:
next
in interfaceIterator<T>
- Returns:
- the next List in the iteration
- Throws:
NoSuchElementException
- if the iteration has no more elementsRuntimeException
- 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 interfaceIterator<T>
- Throws:
UnsupportedOperationException
- when invoked
-
first
Returns the first page of List. Will rewind the iterator.- Returns:
- the first page of List
-
last
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
Returns the previous page of List. Will set the iterator to the previous page.- Returns:
- the previous page of List
-
current
Returns the current page of List.- Returns:
- the current page of List
-
page
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 elementsRuntimeException
- if a GitLab API error occurs, will contain a wrapped GitLabApiException with the details of the error
-
all
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
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:
IllegalStateException
- if Stream has already been issuedGitLabApiException
- if any other error occurs
-
lazyStream
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
-