mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-22 16:23:50 +00:00
hope last fix
This commit is contained in:
parent
c6f417f8c8
commit
864d0ffcc6
@ -10,22 +10,22 @@ 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(datasetSize: Long): SimplePagination {
|
||||||
val firstIndex = (objectsCount - (this.lastIndex + 1)).let {
|
val pagesNumber = calculatePagesNumber(size, datasetSize)
|
||||||
when {
|
val newPage = pagesNumber - page - 1
|
||||||
it < 0 -> 0
|
return when {
|
||||||
it >= objectsCount -> return emptyPagination
|
page < 0 || page >= pagesNumber -> emptyPagination
|
||||||
else -> it
|
else -> Pagination(
|
||||||
|
newPage,
|
||||||
|
size
|
||||||
|
).let {
|
||||||
|
if (it.lastIndex > datasetSize) {
|
||||||
|
it.copy(size = (datasetSize - firstIndex - 1).toInt())
|
||||||
|
} else {
|
||||||
|
it
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.toInt()
|
}
|
||||||
val lastIndex = (objectsCount - (this.firstIndex + 1)).let {
|
|
||||||
when {
|
|
||||||
it < 0 -> return emptyPagination
|
|
||||||
it >= objectsCount -> objectsCount - 1
|
|
||||||
else -> it
|
|
||||||
}
|
|
||||||
}.toInt()
|
|
||||||
return PaginationByIndexes(firstIndex, lastIndex)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,7 +9,6 @@ class PaginationReversingTests {
|
|||||||
fun testThatCommonCaseWorksOk() {
|
fun testThatCommonCaseWorksOk() {
|
||||||
val pageSize = 3
|
val pageSize = 3
|
||||||
val collectionSize = 9
|
val collectionSize = 9
|
||||||
val pages = calculatePage(collectionSize, pageSize)
|
|
||||||
|
|
||||||
assertEquals(Pagination(-1, pageSize).reverse(collectionSize), Pagination(0, 0))
|
assertEquals(Pagination(-1, pageSize).reverse(collectionSize), Pagination(0, 0))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user