mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2026-11-10 14:04:01 +00:00
Pagination#reverse
This commit is contained in:
1 parent
97cbe44fb5
commit
64b0184a17
2 files changed
+26
No files matched your search
+22
@@ -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
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user