package cn.com.qmth.stmms.biz.utils;

/**
 * 分页模型
 * 
 * @author zhengmin
 * 
 * @param <T>
 */
public class PageModel<T> {

    private Integer page;// 当前页码

    private Integer totalCount;// 总记录条数

    private Integer pageCount;// 总页数

    private Integer pageSize;// 每页显示多少

    // private List<T> list;

    // private List<T> pageList;

    public PageModel(Integer page, Integer totalCount, Integer pageSize) {
        this.page = page;
        this.totalCount = totalCount;
        this.pageSize = pageSize;
    }

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getPageCount() {
        pageCount = (int) totalCount / pageSize;
        if (totalCount % pageSize > 0)
            pageCount++;
        return pageCount;
    }

    public void setPageCount(Integer pageCount) {
        this.pageCount = pageCount;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public int[] getRange() {
        if (page != null) {
            int start = (page - 1) * pageSize;
            int end = start + pageSize;
            if (end > totalCount - 1) {
                end = totalCount - 1;
            }
            return new int[] { start, end };
        } else {
            return null;
        }
    }

    /*
     * public List<T> getList() { return list; }
     * 
     * public void setList(List<T> list) { this.list = list; }
     * 
     * public List<T> getPageList() { return list.subList(getRange()[0],
     * getRange()[1]); }
     * 
     * public void setPageList(List<T> pageList) { this.pageList = pageList; }
     */

}
