mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-05 08:09:33 +00:00
@@ -1,5 +1,11 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.2.6
|
||||||
|
|
||||||
|
* `Pagination`
|
||||||
|
* Fixes in function `List#paginate`
|
||||||
|
* Extension property `Pagination#lastIndexExclusive`
|
||||||
|
|
||||||
## 0.2.5
|
## 0.2.5
|
||||||
|
|
||||||
* `Coroutines`
|
* `Coroutines`
|
||||||
|
@@ -19,4 +19,4 @@ github_release_plugin_version=2.2.12
|
|||||||
uuidVersion=0.2.2
|
uuidVersion=0.2.2
|
||||||
|
|
||||||
group=dev.inmo
|
group=dev.inmo
|
||||||
version=0.2.5
|
version=0.2.6
|
||||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
@@ -28,6 +28,15 @@ interface Pagination {
|
|||||||
val Pagination.firstIndex: Int
|
val Pagination.firstIndex: Int
|
||||||
get() = page * size
|
get() = page * size
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Last number in index of objects. In fact, one [Pagination] object represent data in next range:
|
||||||
|
*
|
||||||
|
* [[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. Here [Pagination.lastIndexExclusive] == 20
|
||||||
|
*/
|
||||||
|
val Pagination.lastIndexExclusive: Int
|
||||||
|
get() = firstIndex + size
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Last number in index of objects. In fact, one [Pagination] object represent data in next range:
|
* Last number in index of objects. In fact, one [Pagination] object represent data in next range:
|
||||||
*
|
*
|
||||||
@@ -35,7 +44,7 @@ val Pagination.firstIndex: Int
|
|||||||
* you will retrieve [Pagination.firstIndex] == 10 and [Pagination.lastIndex] == 19.
|
* you will retrieve [Pagination.firstIndex] == 10 and [Pagination.lastIndex] == 19.
|
||||||
*/
|
*/
|
||||||
val Pagination.lastIndex: Int
|
val Pagination.lastIndex: Int
|
||||||
get() = firstIndex + size - 1
|
get() = lastIndexExclusive - 1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates pages count for given [datasetSize]
|
* Calculates pages count for given [datasetSize]
|
||||||
|
@@ -21,7 +21,12 @@ fun <T> Iterable<T>.paginate(with: Pagination): PaginationResult<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun <T> List<T>.paginate(with: Pagination): PaginationResult<T> {
|
fun <T> List<T>.paginate(with: Pagination): PaginationResult<T> {
|
||||||
return subList(with.firstIndex, with.lastIndex + 1).createPaginationResult(
|
val firstIndex = maxOf(with.firstIndex, 0)
|
||||||
|
val lastIndex = minOf(with.lastIndexExclusive, size)
|
||||||
|
if (firstIndex > lastIndex) {
|
||||||
|
return emptyPaginationResult()
|
||||||
|
}
|
||||||
|
return subList(firstIndex, lastIndex).createPaginationResult(
|
||||||
with,
|
with,
|
||||||
size.toLong()
|
size.toLong()
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user