mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-02-16 19:52:03 +00:00
Pagination#reverse
This commit is contained in:
parent
97cbe44fb5
commit
64b0184a17
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
## 0.2.1
|
## 0.2.1
|
||||||
|
|
||||||
|
* `Pagination`
|
||||||
|
* `Common`:
|
||||||
|
* Extension `Pagination#reverse` has been added
|
||||||
|
|
||||||
## 0.2.0
|
## 0.2.0
|
||||||
|
|
||||||
* `Repos`
|
* `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…
x
Reference in New Issue
Block a user