package com.palmnest.application.core.util;

import java.util.List;

/**
 * 分页
 *
 * @param <T>
 * @author xiemin
 */
public class Pages<T> {

	private int     pageSize   = 5; // 每页显示数
	private int     totalCount = 0; // 总数据量
	private int     curPage    = 1; // 开始页
	private int     totalPage  = 0; // 总页数
	private List<T> pageList;

	public Pages() {

	}

	public int getCurrentPageNo() {
		return curPage / pageSize + 1;
	}

	public boolean getHasNextPage() {
		return getCurrentPageNo() < totalPage;
	}

	public boolean getHasPavPage() {
		return getCurrentPageNo() > 1;
	}

	public int getTotalPage() {
		totalPage = totalCount / pageSize;

		if (totalCount % pageSize != 0) {
			totalPage++;
		}

		return totalPage;
	}


	public int getStart(int curPage) {

		if (curPage < 1) {
			curPage = 1;
		} else if (curPage > getTotalPage()) {
			curPage = getTotalPage();
		}

		curPage = (curPage - 1) * pageSize;
		return curPage < 0 ? 0 : curPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalCount() {
		return totalCount;
	}

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

	public int getCurPage() {
		return curPage;
	}

	public void setCurPage(int curPage) {
		this.curPage = curPage;
	}

	public List<T> getPageList() {
		return pageList;
	}

	public void setPageList(List<T> pageList) {
		this.pageList = pageList;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}


}
