Class PaginationParameter

java.lang.Object
org.nuiton.util.pagination.PaginationParameter
All Implemented Interfaces:
java.io.Serializable

public class PaginationParameter
extends java.lang.Object
implements java.io.Serializable
This class represents the necessary information to do pagination (page number, size, ...).
Since:
3.0
Author:
Arnaud Thimel (Code Lutin)
See Also:
Serialized Form
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static class  PaginationParameter.PaginationParameterBuilder
    Class used to build an instance of PaginationParameter.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static PaginationParameter ALL
    An instance that represents a page of ALL elements
    protected static int ALL_PAGE_SIZE
    All results.
    protected java.util.List<PaginationOrder> orderClauses
    The list of order clauses.
    protected int pageNumber
    0-based page number
    protected int pageSize
    The size of each page.
  • Constructor Summary

    Constructors 
    Modifier Constructor Description
    protected PaginationParameter​(int pageNumber, int pageSize)  
    protected PaginationParameter​(int pageNumber, int pageSize, java.util.List<PaginationOrder> orderClauses)  
  • Method Summary

    Modifier and Type Method Description
    static PaginationParameter.PaginationParameterBuilder builder​(int pageNumber, int pageSize)
    Method to create a PaginationParameter using the PaginationParameter.PaginationParameterBuilder.
    boolean equals​(java.lang.Object o)  
    int getEndIndex()
    Method that computes the end index of a page according to pageNumber and pageSize.
    java.util.List<PaginationOrder> getOrderClauses()  
    int getPageNumber()  
    int getPageSize()  
    int getStartIndex()
    Method that computes the start index of a page according to pageNumber and pageSize.
    int hashCode()  
    boolean isAll()
    Test if pagination parameter is about all results range.
    static PaginationParameter of​(int pageNumber, int pageSize)
    Method to create a PaginationParameter only based on pageNumber and pageSize (no order clauses).
    static PaginationParameter of​(int pageNumber, int pageSize, java.lang.String orderClause1, boolean orderDesc1)
    Method to create a PaginationParameter based on pageNumber, pageSize and a single order clause.
    static PaginationParameter of​(int pageNumber, int pageSize, java.lang.String orderClause1, boolean orderDesc1, java.lang.String orderClause2, boolean orderDesc2)
    Method to create a PaginationParameter based on pageNumber, pageSize and two order clauses.
    static PaginationParameter of​(int pageNumber, int pageSize, java.lang.String orderClause1, boolean orderDesc1, java.lang.String orderClause2, boolean orderDesc2, java.lang.String orderClause3, boolean orderDesc3)
    Method to create a PaginationParameter based on pageNumber, pageSize and three order clauses.

    Methods inherited from class java.lang.Object

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

    • ALL_PAGE_SIZE

      protected static final int ALL_PAGE_SIZE
      All results.
      See Also:
      Constant Field Values
    • ALL

      public static final PaginationParameter ALL
      An instance that represents a page of ALL elements
    • pageNumber

      protected int pageNumber
      0-based page number
    • pageSize

      protected int pageSize
      The size of each page. Value can be -1 (for infinite pageSize) or greater than 0
    • orderClauses

      protected java.util.List<PaginationOrder> orderClauses
      The list of order clauses. This instance is unmodifiable and never null.
  • Constructor Details

  • Method Details

    • of

      public static PaginationParameter of​(int pageNumber, int pageSize)
      Method to create a PaginationParameter only based on pageNumber and pageSize (no order clauses).
      Parameters:
      pageNumber - the index (0-based) of the page
      pageSize - the size of each page. Value can be -1 (for infinite pageSize) or greater than 0
      Returns:
      an immutable PaginationParameter instance
    • of

      public static PaginationParameter of​(int pageNumber, int pageSize, java.lang.String orderClause1, boolean orderDesc1)
      Method to create a PaginationParameter based on pageNumber, pageSize and a single order clause. If you have an unknown number of order clauses, you should use the builder(int, int) method together with PaginationParameter.PaginationParameterBuilder.addOrder(String, boolean) and PaginationParameter.PaginationParameterBuilder.build() methods.
      Parameters:
      pageNumber - the index (0-based) of the page
      pageSize - the size of each page. Value can be -1 (for infinite pageSize) or greater than 0
      orderClause1 - an order clause attribute name. It comes together with {code}orderDesc1{/code}
      orderDesc1 - the asc/desc property associated with {code}orderClause1{/code}
      Returns:
      an immutable PaginationParameter instance
      See Also:
      PaginationOrder, PaginationParameter.PaginationParameterBuilder
    • of

      public static PaginationParameter of​(int pageNumber, int pageSize, java.lang.String orderClause1, boolean orderDesc1, java.lang.String orderClause2, boolean orderDesc2)
      Method to create a PaginationParameter based on pageNumber, pageSize and two order clauses. If you have an unknown number of order clauses, you should use the builder(int, int) method together with PaginationParameter.PaginationParameterBuilder.addOrder(String, boolean) and PaginationParameter.PaginationParameterBuilder.build() methods.
      Parameters:
      pageNumber - the index (0-based) of the page
      pageSize - the size of each page. Value can be -1 (for infinite pageSize) or greater than 0
      orderClause1 - an order clause attribute name. It comes together with {code}orderDesc1{/code}
      orderDesc1 - the asc/desc property associated with {code}orderClause1{/code}
      orderClause2 - an order clause attribute name. It comes together with {code}orderDesc2{/code}
      orderDesc2 - the asc/desc property associated with {code}orderClause2{/code}
      Returns:
      an immutable PaginationParameter instance
      See Also:
      PaginationOrder, PaginationParameter.PaginationParameterBuilder
    • of

      public static PaginationParameter of​(int pageNumber, int pageSize, java.lang.String orderClause1, boolean orderDesc1, java.lang.String orderClause2, boolean orderDesc2, java.lang.String orderClause3, boolean orderDesc3)
      Method to create a PaginationParameter based on pageNumber, pageSize and three order clauses. If you have more order clauses, or an unknown number of clauses, you should use the builder(int, int) method together with PaginationParameter.PaginationParameterBuilder.addOrder(String, boolean) and PaginationParameter.PaginationParameterBuilder.build() methods.
      Parameters:
      pageNumber - the index (0-based) of the page
      pageSize - the size of each page. Value can be -1 (for infinite pageSize) or greater than 0
      orderClause1 - an order clause attribute name. It comes together with {code}orderDesc1{/code}
      orderDesc1 - the asc/desc property associated with {code}orderClause1{/code}
      orderClause2 - an order clause attribute name. It comes together with {code}orderDesc2{/code}
      orderDesc2 - the asc/desc property associated with {code}orderClause2{/code}
      orderClause3 - an order clause attribute name. It comes together with {code}orderDesc3{/code}
      orderDesc3 - the asc/desc property associated with {code}orderClause3{/code}
      Returns:
      an immutable PaginationParameter instance
      See Also:
      PaginationOrder, PaginationParameter.PaginationParameterBuilder
    • builder

      public static PaginationParameter.PaginationParameterBuilder builder​(int pageNumber, int pageSize)
      Method to create a PaginationParameter using the PaginationParameter.PaginationParameterBuilder.
      Parameters:
      pageNumber - the index (0-based) of the page
      pageSize - the size of each page. Value can be -1 (for infinite pageSize) or greater than 0
      Returns:
      an immutable PaginationParameter.Builder instance
    • getPageNumber

      public int getPageNumber()
    • getPageSize

      public int getPageSize()
    • getOrderClauses

      public java.util.List<PaginationOrder> getOrderClauses()
    • getStartIndex

      public int getStartIndex()
      Method that computes the start index of a page according to pageNumber and pageSize.
      Returns:
      the computed start index
    • getEndIndex

      public int getEndIndex()
      Method that computes the end index of a page according to pageNumber and pageSize. If the pageSize is -1, the end index will be Integer.MAX_VALUE.
      Returns:
      the computed end index
    • equals

      public boolean equals​(java.lang.Object o)
      Overrides:
      equals in class java.lang.Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • isAll

      public boolean isAll()
      Test if pagination parameter is about all results range.
      Returns:
      true if pagination parameter is about all results range