mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-22 08:13:49 +00:00
fixes in reverse extension
This commit is contained in:
parent
64b0184a17
commit
ff905e1491
@ -11,12 +11,16 @@ import dev.inmo.micro_utils.pagination.*
|
||||
* @return Reversed version of this [Pagination]
|
||||
*/
|
||||
fun Pagination.reverse(objectsCount: Long): SimplePagination {
|
||||
if (firstIndex > objectsCount) {
|
||||
return Pagination(objectsCount.toInt(), size)
|
||||
val resultSize = minOf(size, objectsCount.toInt())
|
||||
return when {
|
||||
firstIndex > objectsCount -> Pagination(calculatePage(resultSize, resultSize), resultSize)
|
||||
size > objectsCount -> FirstPagePagination(resultSize)
|
||||
else -> {
|
||||
val firstIndex = (objectsCount - firstIndex - resultSize).toInt()
|
||||
Pagination(
|
||||
firstIndex,
|
||||
resultSize
|
||||
)
|
||||
}
|
||||
}
|
||||
val firstIndex = (objectsCount - firstIndex - size).toInt()
|
||||
return Pagination(
|
||||
firstIndex,
|
||||
size
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user