What is the difference between getSize()
and getNumberOfElements
in the Spring Data class org.springframework.data.domain.Slice
?
The Javadoc does not offer too much help here.
What is the difference between getSize()
and getNumberOfElements
in the Spring Data class org.springframework.data.domain.Slice
?
The Javadoc does not offer too much help here.
getSize() returns the capacity of the Slice.
getNumberOfElements() how many elements does the Slice contains.
For example: You want Page of data from PagingAndSortingRepository. You can call method like repo.findAll(new PageRequest(0,30)) what means you request for first page of data which contains 30 entities at most. Assuming that there are only 10 entities in database you receive a Page where size is 30 and numberOfElements is 10.
Here is the difference.
Consider, for example full content retrieved has 55 items and page size is 10.
getSize - return the Page size (i.e. current page size) if it is pageable
Example: A page can be defined to have 10 items. So, getSize() would return 10 based on Page definition.
getNumberOfElements - returns the actual content size of a page
Example:- The number of elements can be 10 or less than 10 based on the actual data. The last page would return 5 items.
org.springframework.data.domain.AbstractPageRequest.java - has size attribute
org.springframework.data.domain.Chunk - abstract class has the definition for getNumberOfElements() method returning the size of contents (i.e. list type)