mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-22 16:23:50 +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]
|
* @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
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user