Package org.kiwiproject.spring.data
Class KiwiPaging
- java.lang.Object
-
- org.kiwiproject.spring.data.KiwiPaging
-
public class KiwiPaging extends Object
Static utilities to allow simple construction of Spring DataSortandPageableobjects.
-
-
Constructor Summary
Constructors Constructor Description KiwiPaging()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.springframework.data.domain.SortconstructSortChain(List<org.springframework.data.domain.Sort> sorts)Accepts a list of Sort properties and chains them together in order.static org.springframework.data.domain.SortconstructSortChain(org.springframework.data.domain.Sort... sorts)Accepts a varargs of Sort properties and chains them together in order.static org.springframework.data.domain.SortconstructSortChainFromPairs(Object... directionAndFieldPairs)Creates aSortchain from a varargs list of sort direction and field pairs.static List<org.springframework.data.domain.Sort>constructSortListFromPairs(Object... directionAndFieldPairs)Constructs a list of Sort properties from a varargs of sort direction and field pairs.static org.springframework.data.domain.PageablecreatePageable(int pageNumber, int sizePerPage, Object... sortDirectionAndFieldNamePairs)Constructs aPageableobject using a page number and size, as well as an arbitrary varargs of Sort direction and Field name pairs.static org.springframework.data.domain.PageablecreatePageable(PagingParams pagedRequest)Constructs aPageableobject using aPagingParamsas input.
-
-
-
Method Detail
-
createPageable
public static org.springframework.data.domain.Pageable createPageable(PagingParams pagedRequest)
Constructs aPageableobject using aPagingParamsas input.Since Spring's
Pageableassumes zero-based page numbering, thePagingParamsshould use that same convention or else the page numbering will be wrong.- Parameters:
pagedRequest- the paging parameters to use for thePageable- Returns:
- new
Pageableinstance
-
createPageable
public static org.springframework.data.domain.Pageable createPageable(int pageNumber, int sizePerPage, Object... sortDirectionAndFieldNamePairs)Constructs aPageableobject using a page number and size, as well as an arbitrary varargs of Sort direction and Field name pairs.Since Spring's
Pageableassumes zero-based page numbering, thePagingParamsshould use that same convention or else the page numbering will be wrong.- Parameters:
pageNumber- current page number, numbered from zerosizePerPage- number of elements per pagesortDirectionAndFieldNamePairs- sort direction and field pairs (must be an even number of arguments)- Returns:
- a Pageable instance that defines the current page attributes as well as the combined Sort characteristics
- Implementation Note:
- Any pairs containing a null direction and/or property are ignored, so it is safe to call this
method with varargs such as
{ ASC, "lastName", ASC, null }or{ ASC, null, ASC, null}or even{ null, null, null, null}
-
constructSortChainFromPairs
public static org.springframework.data.domain.Sort constructSortChainFromPairs(Object... directionAndFieldPairs)
Creates aSortchain from a varargs list of sort direction and field pairs. Automatically chains the Sort objects in the order that they were provided.- Parameters:
directionAndFieldPairs- sort direction and field pairs (must be an even number of arguments)- Returns:
- a new Sort instance, or
nullif the given varargs is empty
-
constructSortListFromPairs
public static List<org.springframework.data.domain.Sort> constructSortListFromPairs(Object... directionAndFieldPairs)
Constructs a list of Sort properties from a varargs of sort direction and field pairs.- Parameters:
directionAndFieldPairs- sort direction and field pairs (must be an even number of arguments)- Returns:
- a List of Sort properties, never
null
-
constructSortChain
public static org.springframework.data.domain.Sort constructSortChain(org.springframework.data.domain.Sort... sorts)
Accepts a varargs of Sort properties and chains them together in order.- Parameters:
sorts- the list of Sort properties- Returns:
- a new Sort instance, or
nullif the given varargs is empty
-
constructSortChain
public static org.springframework.data.domain.Sort constructSortChain(List<org.springframework.data.domain.Sort> sorts)
Accepts a list of Sort properties and chains them together in order.- Parameters:
sorts- the list of Sort properties- Returns:
- a new Sort instance, or
nullif the given list is empty
-
-