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

io.github.shmilyjxs.utils.PageResult Maven / Gradle / Ivy

There is a newer version: 1.37
Show newest version
package io.github.shmilyjxs.utils;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

public class PageResult implements Serializable {

    private static final long serialVersionUID = 1L;

    private final long pageNum;

    private final long pageSize;

    private final long total;

    private final long pages;

    private final List records;

    public PageResult(long pageNum, long pageSize, long total, long pages, List records) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.total = total;
        this.pages = pages;
        this.records = Optional.ofNullable(records).orElse(Collections.emptyList());
    }

    public static  PageResult of(long pageNum, long pageSize, long total, long pages, List records) {
        return new PageResult<>(pageNum, pageSize, total, pages, records);
    }

    public  PageResult map(Function mapper) {
        return PageResult.of(pageNum, pageSize, total, pages, records.stream().map(mapper).collect(Collectors.toList()));
    }

    public long getPageNum() {
        return pageNum;
    }

    public long getPageSize() {
        return pageSize;
    }

    public long getTotal() {
        return total;
    }

    public long getPages() {
        return pages;
    }

    public List getRecords() {
        return records;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy