add MapKeyValueRepo.kt

This commit is contained in:
2020-10-14 18:13:40 +06:00
parent af207d78a4
commit e78961b597
9 changed files with 115 additions and 4 deletions

View File

@@ -50,3 +50,8 @@ fun calculatePagesNumber(datasetSize: Int, pageSize: Int): Int =
datasetSize.toLong(),
pageSize
)
/**
* @return calculated page number which can be correctly used in [PaginationResult] as [PaginationResult.page] value
*/
fun calculatePage(firstIndex: Int, resultsSize: Int): Int = firstIndex / resultsSize

View File

@@ -23,6 +23,19 @@ fun <T> List<T>.createPaginationResult(
pagination.size
)
fun <T> List<T>.createPaginationResult(
firstIndex: Int,
commonObjectsNumber: Long
) = PaginationResult(
calculatePage(firstIndex, size),
calculatePagesNumber(
commonObjectsNumber,
size
),
this,
size
)
fun <T> Pair<Long, List<T>>.createPaginationResult(
pagination: Pagination
) = second.createPaginationResult(pagination, first)