I have the following, but it does not take Pageabl...
# spring
d
I have the following, but it does not take Pageable.sort into account
Copy code
fun <T> List<T>.toPage(pageable : Pageable) : Page<T> {
    val content = when {
        (pageable.offset < size) -> subList(pageable.offset, minOf(pageable.offset + pageable.pageSize, size))

        else -> emptyList()
    }
    return PageImpl(content, pageable, size.toLong())
}
l
just analyze pageabe.sort and make it yourself
but what is the case? where you get this list? if it is from some datasource (maybe database) - you should apply pageable to that datasource
d
It's for an in memory impl of a jpa repo which is used in unit tests. Not an in memory database. I would need to use reflection or something to extract the information from pageable.sort, and I guessed something would already exist.