All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.nemerosa.ontrack.model.pagination.PaginatedList.kt Maven / Gradle / Ivy

There is a newer version: 4.4.5
Show newest version
package net.nemerosa.ontrack.model.pagination

/**
 * List of objects with some pagination information.
 *
 * @property pageInfo Information about the current page
 * @property pageItems Items in the current page
 */
class PaginatedList(
        val pageInfo: PageInfo,
        val pageItems: List
) {
    companion object {

        @JvmStatic
        fun  create(
                items: List,
                offset: Int,
                pageSize: Int
        ) = create(
                items.subList(
                        maxOf(offset, 0),
                        maxOf(minOf(offset + pageSize, items.size), 0)
                ),
                offset,
                pageSize,
                items.size
        )

        fun  create(
                items: List,
                offset: Int,
                pageSize: Int,
                total: Int): PaginatedList {
            return PaginatedList(
                    pageInfo = PageInfo(
                            totalSize = total,
                            currentOffset = offset,
                            currentSize = items.size,
                            previousPage = PageRequest(offset, items.size).previous(total, pageSize),
                            nextPage = PageRequest(offset, items.size).next(total, pageSize)
                    ),
                    pageItems = items
            )
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy