fixes in reverse extension

This commit is contained in:
InsanusMokrassar 2020-10-22 14:54:27 +06:00
parent 64b0184a17
commit ff905e1491

View File

@ -11,12 +11,16 @@ import dev.inmo.micro_utils.pagination.*
* @return Reversed version of this [Pagination] * @return Reversed version of this [Pagination]
*/ */
fun Pagination.reverse(objectsCount: Long): SimplePagination { fun Pagination.reverse(objectsCount: Long): SimplePagination {
if (firstIndex > objectsCount) { val resultSize = minOf(size, objectsCount.toInt())
return Pagination(objectsCount.toInt(), size) 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
)
} }