java.lang.Object
org.springframework.data.gemfire.repository.query.support.PagingUtils

public abstract class PagingUtils extends Object
Utility class used to work with Collection, Page and Pageable objects.
Since:
2.4.0
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final Function<org.springframework.data.repository.query.QueryMethod,Boolean>
     
    static final String
     
    static final String
     
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    assertPageable(org.springframework.data.domain.Pageable pageable)
    Asserts that the Pageable object is valid.
    static <T> List<T>
    getPagedList(List<T> list, org.springframework.data.domain.Pageable pageable)
    Gets a page from the given List.
    static org.springframework.data.domain.Pageable
    getPageRequest(org.springframework.data.repository.query.QueryMethod queryMethod, Object... arguments)
    Finds the page request argument from an array of arguments passed to the given QueryMethod.
    static int
    getQueryResultSetEndIndexForPage(org.springframework.data.domain.Pageable pageable)
    Null-safe method used to determine the end index in the query result set for populating the content of the Page.
    static int
    getQueryResultSetLimitForPage(org.springframework.data.domain.Pageable pageable)
    Null-safe method used to determine the maximum results that would be returned by a query given the Pageable object specifying the requested Page.
    static int
    getQueryResultSetStartIndexForPage(org.springframework.data.domain.Pageable pageable)
    Null-safe method used to determine the starting index in the query result set for populating the content of the Page.
    static boolean
    isPageOne(org.springframework.data.domain.Pageable pageable)
    Null-safe method to determine whether the given page request is for page one.
    static boolean
    isPagingPresent(org.springframework.data.repository.query.QueryMethod queryMethod)
    Null-safe method used to determine whether the given QueryMethod represents (models) a paged query.
    protected static int
    normalize(int pageNumber)
    Normalizes 0 index based page numbers (i.e.
    static int
    normalizePageNumber(org.springframework.data.domain.Page<?> page)
    Null-safe method used to normalize 0 index based page numbers (i.e.
    static int
    normalizePageNumber(org.springframework.data.domain.Pageable pageable)
    Null-safe method used to normalize 0 index based page numbers (i.e.
    protected static long
    nullSafeSize(Iterable<?> iterable)
    Null-safe method to determine the size (number of elements) of the Iterable.
    static <T> org.springframework.data.domain.Page<T>
    toPage(List<T> list, org.springframework.data.domain.Pageable pageable)
    Gets a Page view from the given List based on the Pageable object (page request).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • INVALID_PAGE_NUMBER_MESSAGE

      public static final String INVALID_PAGE_NUMBER_MESSAGE
      See Also:
    • INVALID_PAGE_SIZE_MESSAGE

      public static final String INVALID_PAGE_SIZE_MESSAGE
      See Also:
    • NON_NULL_PAGEABLE_MESSAGE

      public static final String NON_NULL_PAGEABLE_MESSAGE
      See Also:
    • DEFAULT_IS_PAGE_QUERY_FUNCTION

      protected static final Function<org.springframework.data.repository.query.QueryMethod,Boolean> DEFAULT_IS_PAGE_QUERY_FUNCTION
  • Constructor Details

    • PagingUtils

      public PagingUtils()
  • Method Details

    • assertPageable

      public static void assertPageable(@NonNull org.springframework.data.domain.Pageable pageable)
      Asserts that the Pageable object is valid.
      Parameters:
      pageable - Pageable object to evaluate.
      Throws:
      IllegalArgumentException - if Pageable is null or page number is less than 0 or the page size is less than 1.
      See Also:
      • Pageable
    • isPageOne

      public static boolean isPageOne(@NonNull org.springframework.data.domain.Pageable pageable)
      Null-safe method to determine whether the given page request is for page one.
      Parameters:
      pageable - page request to evaluate.
      Returns:
      a boolean value indicating whether the given page request is for page one.
      See Also:
      • Pageable
    • isPagingPresent

      public static boolean isPagingPresent(@Nullable org.springframework.data.repository.query.QueryMethod queryMethod)
      Null-safe method used to determine whether the given QueryMethod represents (models) a paged query.
      Parameters:
      queryMethod - QueryMethod to evaluate for paging.
      Returns:
      a boolean value indicating whether the given QueryMethod represents (models) a paged query.
      See Also:
      • QueryMethod
    • getPagedList

      @NonNull public static <T> List<T> getPagedList(@NonNull List<T> list, @NonNull org.springframework.data.domain.Pageable pageable)
      Gets a page from the given List. This method is null-safe, and guards against a null List and Pageable.
      Type Parameters:
      T - type of the List elements; must not be null.
      Parameters:
      list - List from which to extract a page of elements; must not be null.
      pageable - Pageable object encapsulating the details for the page requested.
      Returns:
      a sub-List containing the contents for the requested page.
      See Also:
    • getPageRequest

      @NonNull public static org.springframework.data.domain.Pageable getPageRequest(@NonNull org.springframework.data.repository.query.QueryMethod queryMethod, @NonNull Object... arguments)
      Finds the page request argument from an array of arguments passed to the given QueryMethod.
      Parameters:
      queryMethod - invoked QueryMethod; must not be null.
      arguments - array of arguments passed to the QueryMethod; must not be null.
      Returns:
      the page request argument in the array of arguments passed to the QueryMethod.
      Throws:
      IllegalArgumentException - if QueryMethod is null, or the QueryMethod parameter count is not equal to the argument count, or the indexed QueryMethod argument is not an instance of Pageable.
      IllegalStateException - if the QueryMethod does not have a Pageable parameter.
      See Also:
      • QueryMethod
      • Pageable
    • getQueryResultSetStartIndexForPage

      public static int getQueryResultSetStartIndexForPage(@Nullable org.springframework.data.domain.Pageable pageable)
      Null-safe method used to determine the starting index in the query result set for populating the content of the Page.
      Parameters:
      pageable - Pageable object encapsulating the details of the requested Page.
      Returns:
      the start index in the query result set to populate the content of the Page.
      See Also:
    • getQueryResultSetEndIndexForPage

      public static int getQueryResultSetEndIndexForPage(@Nullable org.springframework.data.domain.Pageable pageable)
      Null-safe method used to determine the end index in the query result set for populating the content of the Page.
      Parameters:
      pageable - Pageable object encapsulating the details of the requested Page.
      Returns:
      the end index in the query result set to populate the content of the Page.
      See Also:
    • getQueryResultSetLimitForPage

      public static int getQueryResultSetLimitForPage(@Nullable org.springframework.data.domain.Pageable pageable)
      Null-safe method used to determine the maximum results that would be returned by a query given the Pageable object specifying the requested Page.
      Parameters:
      pageable - Pageable object encapsulating the details of the requested Page.
      Returns:
      the maximum results that would be returned by a query given the Pageable object specifying the requested Page.
      See Also:
    • normalizePageNumber

      public static int normalizePageNumber(@Nullable org.springframework.data.domain.Page<?> page)
      Null-safe method used to normalize 0 index based page numbers (i.e. 0, 1, 2, ...) to natural page numbers (i.e. 1, 2, 3, ...) using the given Page.
      Parameters:
      page - Page used to determine the page number to normalize.
      Returns:
      the normalized page number from the 0 index based page number.
      See Also:
    • normalizePageNumber

      public static int normalizePageNumber(@Nullable org.springframework.data.domain.Pageable pageable)
      Null-safe method used to normalize 0 index based page numbers (i.e. 0, 1, 2, ...) to natural page numbers (i.e. 1, 2, 3, ...) using the given Pageable.
      Parameters:
      pageable - Pageable used to determine the page number to normalize.
      Returns:
      the normalized page number from the 0 index based page number.
      See Also:
    • normalize

      protected static int normalize(int pageNumber)
      Normalizes 0 index based page numbers (i.e. 0, 1, 2, ...) to natural page numbers (i.e. 1, 2, 3, ...).
      Parameters:
      pageNumber - The page number to normalize.
      Returns:
      the normalized page number from the 0 index based page number.
    • nullSafeSize

      protected static long nullSafeSize(@Nullable Iterable<?> iterable)
      Null-safe method to determine the size (number of elements) of the Iterable. The Iterable object may be an array, a Collection or simply a stream backing, pure Iterable object.
      Parameters:
      iterable - Iterable object to evaluate.
      Returns:
      the size (number of elements) contained by the Iterable object. If the Iterable object is null, then this method will return 0.
      See Also:
    • toPage

      @NonNull public static <T> org.springframework.data.domain.Page<T> toPage(@NonNull List<T> list, @NonNull org.springframework.data.domain.Pageable pageable)
      Gets a Page view from the given List based on the Pageable object (page request).
      Type Parameters:
      T - type of the List elements.
      Parameters:
      list - List of content from which to extract a Page; must not be null.
      pageable - Pageable object encapsulating the details of the Page requested; must not be null.
      Returns:
      a non-null Page view from the given List based on the Pageable object (page request).
      See Also: