Class PageHelper
java.lang.Object
com.broadleafcommerce.data.tracking.core.filtering.PageHelper
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> org.springframework.data.domain.Page<T>of(org.springframework.data.domain.Page<T> page) Convert aPageinstance toUntotalledPageif applicable.static org.springframework.data.domain.Pageableof(org.springframework.data.domain.Pageable pageable) If thePageableinstance is actually aNarrowedPageable, convert the offset appropriately based on theNarrowedPageable.isForward()value.
-
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 aPageinstance toUntotalledPageif applicable. Otherwise, return the page instance that was passed in. The conversion is gauged based on the type of ofPageableinstance resident in the page. If the pageable is aUnnumberedPageableorNarrowedPageableinstance, the page is converted to aUntotalledPage. 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 inof(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 thePageableinstance is actually aNarrowedPageable, convert the offset appropriately based on theNarrowedPageable.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 ofNarrowedPageable. This method is generally only employed by use cases whereNarrowedPageableis being applied against a repository that does NOT inherit fromTrackableRepository.- Parameters:
pageable- The Pageable instance to convert, if applicable- Returns:
- the converted pageable (or the original pageable if not converted)
-