Record Class PageRecord<T>
- Type Parameters:
T- The type of elements on the page- Record Components:
pageRequest- Thepage requestfor which this page was obtainedcontent- The page contenttotalElements- The total number of elements across all pages that can be requested for the query. A negative value indicates that a total count of elements and pages is not available.moreResults- whether there is a (nonempty) next page of results
Page.
This may be used to simplify implementation of a repository interface.-
Constructor Summary
ConstructorsConstructorDescriptionPageRecord(PageRequest<T> pageRequest, List<T> content, long totalElements) Constructs a new instance, computing themoreResultscomponent astrueif the pagecontentis a full page of results and thetotalElementsis either unavailable (indicated by a negative value) or it exceeds the current page number multiplied by thesizeof a full page.PageRecord(PageRequest<T> pageRequest, List<T> content, long totalElements, boolean moreResults) Creates an instance of aPageRecordrecord class. -
Method Summary
Modifier and TypeMethodDescriptioncontent()Returns the value of thecontentrecord component.final booleanIndicates whether some other object is "equal to" this one.booleanReturns whether thePagehas content at all.final inthashCode()Returns a hash code value for this object.booleanhasNext()Returnstrueif it is known that there are more results or that it is necessary to request a next page to determine whether there are more results, so thatPage.nextPageRequest()will definitely not returnnull.booleanReturnstrueif it is known that there are previous results or that it is necessary to request the previous page to determine whether there are previous results, so thatPage.previousPageRequest()will not returnnull.booleanReturnstrueif thePage.pageRequest()specified that the total number of elements should be retrieved from the database, and that it is therefore safe to callPage.totalElements()orPage.totalPages().iterator()booleanReturns the value of themoreResultsrecord component.Returns a request for the next page ifPage.hasNext()indicates there might be a next page.<E> PageRequest<E>nextPageRequest(Class<E> entityClass) Returns a request for the next page ifPage.hasNext()indicates there might be a next page.intReturns the number of elements on thisPage, which must be no larger than the maximumsizeof the page request.Returns the value of thepageRequestrecord component.<E> PageRequest<E>pageRequest(Class<E> entityClass) Returns the page request for which this page was obtained.Returns a request for thepreviouspage, ifPage.hasPrevious()indicates there might be a previous page.<E> PageRequest<E>previousPageRequest(Class<E> entityClass) Returns a request for the previous page, ifPage.hasPrevious()indicates there might be a previous page.final StringtoString()Returns a string representation of this record class.longReturns the value of thetotalElementsrecord component.longReturns the total number of pages of query results, if thePage.pageRequest()specified that the total should be retrieved from the database.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
PageRecord
Constructs a new instance, computing themoreResultscomponent astrueif the pagecontentis a full page of results and thetotalElementsis either unavailable (indicated by a negative value) or it exceeds the current page number multiplied by thesizeof a full page.- Parameters:
pageRequest- Thepage requestfor which this page was obtained.content- The page content.totalElements- The total number of elements across all pages that can be requested for the query. A negative value indicates that a total count of elements and pages is not available.
-
PageRecord
public PageRecord(PageRequest<T> pageRequest, List<T> content, long totalElements, boolean moreResults) Creates an instance of aPageRecordrecord class.- Parameters:
pageRequest- the value for thepageRequestrecord componentcontent- the value for thecontentrecord componenttotalElements- the value for thetotalElementsrecord componentmoreResults- the value for themoreResultsrecord component
-
-
Method Details
-
hasContent
public boolean hasContent()Description copied from interface:PageReturns whether thePagehas content at all.- Specified by:
hasContentin interfacePage<T>- Returns:
- whether the
Pagehas content at all.
-
numberOfElements
public int numberOfElements()Description copied from interface:PageReturns the number of elements on thisPage, which must be no larger than the maximumsizeof the page request. If the number of elements in the page is smaller than the maximum page size, then there are no subsequent pages of data to read.- Specified by:
numberOfElementsin interfacePage<T>- Returns:
- the number of elements on this
Page.
-
hasNext
public boolean hasNext()Description copied from interface:PageReturnstrueif it is known that there are more results or that it is necessary to request a next page to determine whether there are more results, so thatPage.nextPageRequest()will definitely not returnnull. -
pageRequest
Description copied from interface:PageReturns the page request for which this page was obtained.
This method is useful when the query language is used to return a result of different type to the entity class that was queried, allowing the subsequent
PageRequestto be cast back to the type of entity class that was queried.- Specified by:
pageRequestin interfacePage<T>- Type Parameters:
E- entity class of the attributes that are used as sort criteria.- Parameters:
entityClass- entity class of the attributes that are used as sort criteria.- Returns:
- the request for the current page; will never be
null.
-
nextPageRequest
Description copied from interface:PageReturns a request for the next page ifPage.hasNext()indicates there might be a next page.- Specified by:
nextPageRequestin interfacePage<T>- Returns:
- a request for the next page.
-
hasPrevious
public boolean hasPrevious()Description copied from interface:PageReturnstrueif it is known that there are previous results or that it is necessary to request the previous page to determine whether there are previous results, so thatPage.previousPageRequest()will not returnnull.- Specified by:
hasPreviousin interfacePage<T>- Returns:
falseif this is the first page of results.
-
previousPageRequest
Description copied from interface:PageReturns a request for the
previouspage, ifPage.hasPrevious()indicates there might be a previous page.- Specified by:
previousPageRequestin interfacePage<T>- Returns:
- a request for the previous page.
-
previousPageRequest
Description copied from interface:PageReturns a request for the previous page, if
Page.hasPrevious()indicates there might be a previous page.This method is useful when the query language is used to return a result of different type to the entity class that was queried, allowing the subsequent
PageRequestto be cast back to the type of entity class that was queried.- Specified by:
previousPageRequestin interfacePage<T>- Type Parameters:
E- entity class of the attributes that are used as sort criteria.- Parameters:
entityClass- entity class of the attributes that are used as sort criteria.- Returns:
- a request for the previous page.
-
nextPageRequest
Description copied from interface:PageReturns a request for the next page if
Page.hasNext()indicates there might be a next page.This method is useful when the query language is used to return a result of different type to the entity class that was queried, allowing the subsequent
PageRequestto be cast back to the type of entity class that was queried.- Specified by:
nextPageRequestin interfacePage<T>- Type Parameters:
E- entity class of the attributes that are used as sort criteria.- Parameters:
entityClass- entity class of the attributes that are used as sort criteria.- Returns:
- a request for the next page.
-
iterator
-
hasTotals
public boolean hasTotals()Description copied from interface:PageReturnstrueif thePage.pageRequest()specified that the total number of elements should be retrieved from the database, and that it is therefore safe to callPage.totalElements()orPage.totalPages(). -
totalElements
public long totalElements()Returns the value of thetotalElementsrecord component.- Specified by:
totalElementsin interfacePage<T>- Returns:
- the value of the
totalElementsrecord component
-
totalPages
public long totalPages()Description copied from interface:PageReturns the total number of pages of query results, if thePage.pageRequest()specified that the total should be retrieved from the database.- Specified by:
totalPagesin interfacePage<T>- Returns:
- the total number of pages.
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
pageRequest
Returns the value of thepageRequestrecord component.- Specified by:
pageRequestin interfacePage<T>- Returns:
- the value of the
pageRequestrecord component
-
content
Returns the value of thecontentrecord component. -
moreResults
public boolean moreResults()Returns the value of themoreResultsrecord component.- Returns:
- the value of the
moreResultsrecord component
-