Pagination#reverse

This commit is contained in:
InsanusMokrassar 2020-10-22 14:39:39 +06:00
parent 97cbe44fb5
commit 64b0184a17
2 changed files with 26 additions and 0 deletions

View File

@ -2,6 +2,10 @@
## 0.2.1
* `Pagination`
* `Common`:
* Extension `Pagination#reverse` has been added
## 0.2.0
* `Repos`

View File

@ -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
)
}