fix in calculating page fun

This commit is contained in:
InsanusMokrassar 2020-10-14 18:16:58 +06:00
parent e78961b597
commit 8461ff4d38

View File

@ -1,6 +1,7 @@
package dev.inmo.micro_utils.pagination package dev.inmo.micro_utils.pagination
import kotlin.math.ceil import kotlin.math.ceil
import kotlin.math.floor
/** /**
* Base interface of pagination * Base interface of pagination
@ -54,4 +55,8 @@ fun calculatePagesNumber(datasetSize: Int, pageSize: Int): Int =
/** /**
* @return calculated page number which can be correctly used in [PaginationResult] as [PaginationResult.page] value * @return calculated page number which can be correctly used in [PaginationResult] as [PaginationResult.page] value
*/ */
fun calculatePage(firstIndex: Int, resultsSize: Int): Int = firstIndex / resultsSize fun calculatePage(firstIndex: Int, resultsSize: Int): Int = if (resultsSize > 0) {
floor(firstIndex.toFloat() / resultsSize).toInt()
} else {
0
}