mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-18 14:47:15 +00:00
now Pagination is an ClosedRange
This commit is contained in:
parent
2af7e2f681
commit
aa45a4ab13
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
## 0.8.3
|
## 0.8.3
|
||||||
|
|
||||||
|
* `Pagination`:
|
||||||
|
* `Pagination` now extends `ClosedRange<Int>`
|
||||||
|
|
||||||
## 0.8.2
|
## 0.8.2
|
||||||
|
|
||||||
* `Versions`:
|
* `Versions`:
|
||||||
|
@ -9,7 +9,7 @@ import kotlin.math.floor
|
|||||||
* If you want to request something, you should use [SimplePagination]. If you need to return some result including
|
* If you want to request something, you should use [SimplePagination]. If you need to return some result including
|
||||||
* pagination - [PaginationResult]
|
* pagination - [PaginationResult]
|
||||||
*/
|
*/
|
||||||
interface Pagination {
|
interface Pagination : ClosedRange<Int> {
|
||||||
/**
|
/**
|
||||||
* Started with 0.
|
* Started with 0.
|
||||||
* Number of page inside of pagination. Offset can be calculated as [page] * [size]
|
* Number of page inside of pagination. Offset can be calculated as [page] * [size]
|
||||||
@ -20,6 +20,11 @@ interface Pagination {
|
|||||||
* Size of current page. Offset can be calculated as [page] * [size]
|
* Size of current page. Offset can be calculated as [page] * [size]
|
||||||
*/
|
*/
|
||||||
val size: Int
|
val size: Int
|
||||||
|
|
||||||
|
override val start: Int
|
||||||
|
get() = page * size
|
||||||
|
override val endInclusive: Int
|
||||||
|
get() = lastIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,7 +37,7 @@ inline val Pagination.isFirstPage
|
|||||||
* First number in index of objects. It can be used as offset for databases or other data sources
|
* First number in index of objects. It can be used as offset for databases or other data sources
|
||||||
*/
|
*/
|
||||||
val Pagination.firstIndex: Int
|
val Pagination.firstIndex: Int
|
||||||
get() = page * size
|
get() = start
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Last number in index of objects. In fact, one [Pagination] object represent data in next range:
|
* Last number in index of objects. In fact, one [Pagination] object represent data in next range:
|
||||||
@ -41,7 +46,7 @@ val Pagination.firstIndex: Int
|
|||||||
* you will retrieve [Pagination.firstIndex] == 10 and [Pagination.lastIndex] == 19. Here [Pagination.lastIndexExclusive] == 20
|
* you will retrieve [Pagination.firstIndex] == 10 and [Pagination.lastIndex] == 19. Here [Pagination.lastIndexExclusive] == 20
|
||||||
*/
|
*/
|
||||||
val Pagination.lastIndexExclusive: Int
|
val Pagination.lastIndexExclusive: Int
|
||||||
get() = firstIndex + size
|
get() = endInclusive + 1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Last number in index of objects. In fact, one [Pagination] object represent data in next range:
|
* Last number in index of objects. In fact, one [Pagination] object represent data in next range:
|
||||||
@ -50,7 +55,7 @@ val Pagination.lastIndexExclusive: Int
|
|||||||
* you will retrieve [Pagination.firstIndex] == 10 and [Pagination.lastIndex] == 19.
|
* you will retrieve [Pagination.firstIndex] == 10 and [Pagination.lastIndex] == 19.
|
||||||
*/
|
*/
|
||||||
val Pagination.lastIndex: Int
|
val Pagination.lastIndex: Int
|
||||||
get() = lastIndexExclusive - 1
|
get() = endInclusive
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates pages count for given [datasetSize]
|
* Calculates pages count for given [datasetSize]
|
||||||
|
Loading…
Reference in New Issue
Block a user