com.gisgraphy.domain.valueobject
Class Pagination

java.lang.Object
  extended by com.gisgraphy.domain.valueobject.Pagination

public class Pagination
extends java.lang.Object

Represent a pagination specification.the design (with DSL and interface) does not allow to set the 'to' properties before the from e.g : Paginate().from(1).to(9) will return [1,2,3,4,5,6,7,8,9].

Author:
David Masclet
See Also:
DSL

Nested Class Summary
static interface Pagination.FromSpecification
           
static class Pagination.PaginationBuilder
           
static interface Pagination.ToSpecification
           
 
Field Summary
static int DEFAULT_FROM
          the default 'from' parameters if the one specified is missing or incorrect
static int DEFAULT_MAX_RESULTS
          If the 'to' parameter is not specified or incorrect, it will be set to a value to have DEFAULT_MAX_RESULTS results this value is NOT the default to parameters, we prefer to use a startegy to fix number of results instead of the from
static Pagination DEFAULT_PAGINATION
          Default Pagination
 int maxResult
          max result the pagination should have
 
Method Summary
 boolean equals(java.lang.Object obj)
           
 int getFrom()
           
 int getMaxNumberOfResults()
           
 int getTo()
           
 int hashCode()
           
 Pagination limitNumberOfResults(int limit)
          Do a post-treatment on the current pagination to limit number of results.
static Pagination.FromSpecification paginate()
          Static method to be used to create a pagination object.
static Pagination.FromSpecification paginateWithMaxResults(int maxResult)
          Static method to be used to create a pagination object and define maxResults.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_MAX_RESULTS

public static final int DEFAULT_MAX_RESULTS
If the 'to' parameter is not specified or incorrect, it will be set to a value to have DEFAULT_MAX_RESULTS results this value is NOT the default to parameters, we prefer to use a startegy to fix number of results instead of the from

See Also:
Constant Field Values

maxResult

public int maxResult
max result the pagination should have


DEFAULT_FROM

public static final int DEFAULT_FROM
the default 'from' parameters if the one specified is missing or incorrect

See Also:
Constant Field Values

DEFAULT_PAGINATION

public static final Pagination DEFAULT_PAGINATION
Default Pagination

Method Detail

paginate

public static Pagination.FromSpecification paginate()
Static method to be used to create a pagination object. (tip : use Static import)

Returns:
An instance of Pagination.FromSpecification to force the from parameter to be set first

paginateWithMaxResults

public static Pagination.FromSpecification paginateWithMaxResults(int maxResult)
Static method to be used to create a pagination object and define maxResults. (tip : use Static import). because The to parameter is calculated with the masResultValue, you need to use this method befor set the to and the from.

Parameters:
maxResult - the max number of results he pagination should have, if max results is incorrect,DEFAULT_MAX_RESULTS will be used
Returns:
An instance of Pagination.FromSpecification to force the from parameter to be set first

getFrom

public int getFrom()
Returns:
the from

getTo

public int getTo()
Returns:
the to

limitNumberOfResults

public Pagination limitNumberOfResults(int limit)
Do a post-treatment on the current pagination to limit number of results. 'from will be unchanged, only 'to' will be changed if limit is <=0, there is no effect

Parameters:
limit - the max number Of results
Returns:
the current Pagination to chain methods

getMaxNumberOfResults

public int getMaxNumberOfResults()
Returns:
how many results will be return according the from and to parameters (the max expected numbers of results). it can be less than expected if there is less results to return. e.g : from(1).to(5) can nly return 2 results if there is only 2 parameters but this method return the max expected numbers of results) it will return 0 if from and to equals 0

hashCode

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

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2010. All Rights Reserved.