From 3c998edb3c8db05d2f5516c53dbb3b5c30cd86d8 Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Mon, 24 Feb 2020 20:41:29 +0100 Subject: [PATCH] add methode$ "isLastPage" to pagination --- src/main/kotlin/fr/postgresjson/connexion/Paginated.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/kotlin/fr/postgresjson/connexion/Paginated.kt b/src/main/kotlin/fr/postgresjson/connexion/Paginated.kt index 6768597..3904da6 100644 --- a/src/main/kotlin/fr/postgresjson/connexion/Paginated.kt +++ b/src/main/kotlin/fr/postgresjson/connexion/Paginated.kt @@ -1,6 +1,7 @@ package fr.postgresjson.connexion import fr.postgresjson.entity.EntityI +import kotlin.math.ceil data class Paginated( val result: List, @@ -10,10 +11,15 @@ data class Paginated( ) { val currentPage: Int = (offset / limit) + 1 val count: Int = result.size + val totalPages: Int = (total.toDouble() / limit.toDouble()).ceil() init { if (offset < 0) error("offset must be greather or equal than 0") if (limit < 1) error("limit must be greather or equal than 1") if (total < 0) error("total must be greather or equal than 0") } + + fun isLastPage(): Boolean = currentPage >= totalPages + + private fun Double.ceil(): Int = ceil(this).toInt() } \ No newline at end of file