Class KiwiPaging

java.lang.Object
org.kiwiproject.spring.data.KiwiPaging

public final class KiwiPaging extends Object
Static utilities to allow simple construction of Spring Data Sort and Pageable objects.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    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.
    static org.springframework.data.domain.Sort
    constructSortChainFromPairs(Object... directionAndFieldPairs)
    Creates a Sort chain 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.Pageable
    createPageable(int pageNumber, int sizePerPage, Object... sortDirectionAndFieldNamePairs)
    Constructs a Pageable object using a page number and size, as well as an arbitrary varargs of Sort direction and Field name pairs.
    static org.springframework.data.domain.Pageable
    Constructs a Pageable object using a PagingParams as input.

    Methods inherited from class java.lang.Object

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

    • createPageable

      public static org.springframework.data.domain.Pageable createPageable(PagingParams pagedRequest)
      Constructs a Pageable object using a PagingParams as input.

      Since Spring's Pageable assumes zero-based page numbering, the PagingParams should use that same convention or else the page numbering will be wrong.

      Parameters:
      pagedRequest - the paging parameters to use for the Pageable
      Returns:
      new Pageable instance
    • createPageable

      public static org.springframework.data.domain.Pageable createPageable(int pageNumber, int sizePerPage, Object... sortDirectionAndFieldNamePairs)
      Constructs a Pageable object using a page number and size, as well as an arbitrary varargs of Sort direction and Field name pairs.

      Since Spring's Pageable assumes zero-based page numbering, the PagingParams should use that same convention or else the page numbering will be wrong.

      Parameters:
      pageNumber - current page number, numbered from zero
      sizePerPage - number of elements per page
      sortDirectionAndFieldNamePairs - 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 a Sort chain 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 null if 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 null if 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 null if the given list is empty