mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-04 23:59:29 +00:00
Revert "less annotations to god of lessannotations"
This reverts commit 87230d010c
.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package dev.inmo.micro_utils.pagination
|
||||
|
||||
import kotlin.js.JsExport
|
||||
import kotlin.js.JsName
|
||||
import kotlin.math.ceil
|
||||
import kotlin.math.floor
|
||||
|
||||
@@ -28,6 +27,7 @@ interface Pagination {
|
||||
/**
|
||||
* First number in index of objects. It can be used as offset for databases or other data sources
|
||||
*/
|
||||
@JsExport
|
||||
val Pagination.firstIndex: Int
|
||||
get() = page * size
|
||||
|
||||
@@ -37,6 +37,7 @@ val Pagination.firstIndex: Int
|
||||
* [[firstIndex], [lastIndex]]; That means, that for [Pagination] with [Pagination.size] == 10 and [Pagination.page] == 1
|
||||
* you will retrieve [Pagination.firstIndex] == 10 and [Pagination.lastIndex] == 19.
|
||||
*/
|
||||
@JsExport
|
||||
val Pagination.lastIndex: Int
|
||||
get() = firstIndex + size - 1
|
||||
|
||||
@@ -51,7 +52,6 @@ fun calculatePagesNumber(datasetSize: Long, pageSize: Int): Int {
|
||||
* Calculates pages count for given [datasetSize]
|
||||
*/
|
||||
@JsExport
|
||||
@JsName("calculatePagesNumberWithInt")
|
||||
fun calculatePagesNumber(datasetSize: Int, pageSize: Int): Int =
|
||||
calculatePagesNumber(
|
||||
datasetSize.toLong(),
|
||||
|
@@ -2,7 +2,6 @@ package dev.inmo.micro_utils.pagination
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlin.js.JsExport
|
||||
import kotlin.js.JsName
|
||||
|
||||
@JsExport
|
||||
@Serializable
|
||||
@@ -17,7 +16,6 @@ data class PaginationResult<T>(
|
||||
fun <T> emptyPaginationResult() = PaginationResult<T>(0, 0, emptyList(), 0)
|
||||
|
||||
@JsExport
|
||||
@JsName("createPaginationResultWithPagination")
|
||||
fun <T> List<T>.createPaginationResult(
|
||||
pagination: Pagination,
|
||||
commonObjectsNumber: Long
|
||||
@@ -32,7 +30,6 @@ fun <T> List<T>.createPaginationResult(
|
||||
)
|
||||
|
||||
@JsExport
|
||||
@JsName("createPaginationResultWithFirstIndex")
|
||||
fun <T> List<T>.createPaginationResult(
|
||||
firstIndex: Int,
|
||||
commonObjectsNumber: Long
|
||||
@@ -47,7 +44,6 @@ fun <T> List<T>.createPaginationResult(
|
||||
)
|
||||
|
||||
@JsExport
|
||||
@JsName("createPaginationResultWithPair")
|
||||
fun <T> Pair<Long, List<T>>.createPaginationResult(
|
||||
pagination: Pagination
|
||||
) = second.createPaginationResult(pagination, first)
|
||||
|
@@ -2,7 +2,6 @@ package dev.inmo.micro_utils.pagination
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlin.js.JsExport
|
||||
import kotlin.js.JsName
|
||||
|
||||
const val defaultSmallPageSize = 2
|
||||
const val defaultMediumPageSize = 5
|
||||
@@ -33,7 +32,6 @@ data class SimplePagination(
|
||||
) : Pagination
|
||||
|
||||
@JsExport
|
||||
@JsName("PaginationFactory")
|
||||
fun Pagination(
|
||||
page: Int,
|
||||
size: Int
|
||||
|
@@ -2,7 +2,6 @@ package dev.inmo.micro_utils.pagination.utils
|
||||
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
import kotlin.js.JsExport
|
||||
import kotlin.js.JsName
|
||||
|
||||
@JsExport
|
||||
fun <T> Iterable<T>.paginate(with: Pagination): PaginationResult<T> {
|
||||
@@ -24,7 +23,6 @@ fun <T> Iterable<T>.paginate(with: Pagination): PaginationResult<T> {
|
||||
}
|
||||
|
||||
@JsExport
|
||||
@JsName("paginateList")
|
||||
fun <T> List<T>.paginate(with: Pagination): PaginationResult<T> {
|
||||
return subList(with.firstIndex, with.lastIndex + 1).createPaginationResult(
|
||||
with,
|
||||
@@ -33,7 +31,6 @@ fun <T> List<T>.paginate(with: Pagination): PaginationResult<T> {
|
||||
}
|
||||
|
||||
@JsExport
|
||||
@JsName("paginateSet")
|
||||
fun <T> Set<T>.paginate(with: Pagination): PaginationResult<T> {
|
||||
return this.drop(with.firstIndex).take(with.size).createPaginationResult(
|
||||
with,
|
||||
|
@@ -7,18 +7,21 @@ const val paginationPageKey = "ppage"
|
||||
@JsExport
|
||||
const val paginationSizeKey = "psize"
|
||||
|
||||
@JsExport
|
||||
val Pagination.asUrlQueryParts
|
||||
get() = mapOf(
|
||||
paginationPageKey to page.toString(),
|
||||
paginationSizeKey to size.toString()
|
||||
)
|
||||
|
||||
@JsExport
|
||||
val Pagination.asUrlQueryArrayParts
|
||||
get() = arrayOf(
|
||||
paginationPageKey to page.toString(),
|
||||
paginationSizeKey to size.toString()
|
||||
)
|
||||
|
||||
@JsExport
|
||||
val Map<String, String?>.extractPagination: Pagination
|
||||
get() = SimplePagination(
|
||||
get(paginationPageKey) ?.toIntOrNull() ?: 0,
|
||||
|
Reference in New Issue
Block a user