java.lang.Object
com.broadleafcommerce.data.tracking.core.filtering.PageHelper

public class PageHelper extends Object
Provides helper methods for working with Page, and the Broadleaf counterpart of UntotalledPage that should result from a UnnumberedPageable or NarrowedPageable request. This type of conversion is only necessary when using NarrowedPageable or UnnumberedPageable with a repository that does NOT inherit from TrackableRepository. TrackableRepository already has built-in support for returning the right type of page response based on the pageable request.
Author:
Jeff Fischer
  • Constructor Details

    • PageHelper

      public PageHelper()
  • Method Details

    • of

      public static <T> org.springframework.data.domain.Page<T> of(org.springframework.data.domain.Page<T> page)
      Convert a Page instance to UntotalledPage if applicable. Otherwise, return the page instance that was passed in. The conversion is gauged based on the type of of Pageable instance resident in the page. If the pageable is a UnnumberedPageable or NarrowedPageable instance, the page is converted to a UntotalledPage. Also, if the page is converted, the internal pageable is converted for offset if the isForward value is false. In this case, the pageSize is added to the offset to create the new offset. This is to compensate for the offset change made in of(Pageable).
      Type Parameters:
      T - The type of records in the page
      Parameters:
      page - The page instance to convert, if applicable
      Returns:
      The converted page (or the original page if not converted)
    • of

      public static org.springframework.data.domain.Pageable of(org.springframework.data.domain.Pageable pageable)
      If the Pageable instance is actually a NarrowedPageable, convert the offset appropriately based on the NarrowedPageable.isForward() value. Notably, subtract the pageSize from the offset to arrive at the reduced offset if the isForward value is false. Otherwise, leave the pageable alone if the isForward value is true, or if the pageable is not an instance of NarrowedPageable. This method is generally only employed by use cases where NarrowedPageable is being applied against a repository that does NOT inherit from TrackableRepository.
      Parameters:
      pageable - The Pageable instance to convert, if applicable
      Returns:
      the converted pageable (or the original pageable if not converted)