package org.ta.pddserver.model.common;


public class PageTool {

    private Integer page;
    private Integer offset;
    private Integer size;

    public Integer getSize() {
        return size;
    }

    public void setSize(Integer size) {
        this.size = size;
    }

    public Integer getPage() {
        if (page == null || page < 1) {
            page = 1;
        }
        return page;
    }
    public void setPage(Integer page) {
        if (page == null || page < 1) {
            page = 1;
        }
        this.page = page;
    }

    public Integer getOffset() {
        if (offset == null || offset < 0) {
            offset = 0;
        }
        return offset;
    }

    public void setOffset(Integer offset) {
        if (offset == null || offset < 0) {
            offset = 0;
        }
        this.offset = offset;
    }

    public void checkPage(Integer count, Integer perPage) {
        if (this.size == null || this.size <= 0) {
            this.size = perPage;
        }
        Integer allPage = (count - 1) / this.size + 1;
        if (this.getPage() > allPage) {
            this.page = allPage;
        }
        this.offset = (this.page - 1) * this.size;
    }
}
