mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-26 03:58:45 +00:00
Pagination#reverse
This commit is contained in:
parent
97cbe44fb5
commit
64b0184a17
@ -2,6 +2,10 @@
|
||||
|
||||
## 0.2.1
|
||||
|
||||
* `Pagination`
|
||||
* `Common`:
|
||||
* Extension `Pagination#reverse` has been added
|
||||
|
||||
## 0.2.0
|
||||
|
||||
* `Repos`
|
||||
|
@ -0,0 +1,22 @@
|
||||
package dev.inmo.micro_utils.pagination.utils
|
||||
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
|
||||
/**
|
||||
* Example:
|
||||
*
|
||||
* * `|__f__l_______________________|` will be transformed to `|_______________________f__l__|`
|
||||
* * `|__f__l_|` will be transformed to `|__f__l_|`
|
||||
*
|
||||
* @return Reversed version of this [Pagination]
|
||||
*/
|
||||
fun Pagination.reverse(objectsCount: Long): SimplePagination {
|
||||
if (firstIndex > objectsCount) {
|
||||
return Pagination(objectsCount.toInt(), size)
|
||||
}
|
||||
val firstIndex = (objectsCount - firstIndex - size).toInt()
|
||||
return Pagination(
|
||||
firstIndex,
|
||||
size
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue
Block a user