package cn.jack.tool;
import java.io.*;
public class PagesBean implements Serializable {

	private int currentPage;
	
	private int totalItem;
	
	private int everyPage;
	
	public void setCurrentPage(int currentPage) {
		
		int totalPage;
		totalPage = this.getTotalPage();
		if(currentPage <= 0) {
			this.currentPage = 0;
			return;
		} else if(currentPage >= totalPage) {
			this.currentPage = totalPage - 1;
			return;
		}
		this.currentPage = currentPage;
	}
	
	public int getCurrentPage() {
		if(totalItem <= 0) {
			return 0;
		}
		return this.currentPage;
	}
	
	public int getCurrentPageNum() {
		if(totalItem <= 0) {
			return 0;
		}
		return this.currentPage + 1;		
	}
	
	public void setEveryPage(int everyPage) {
		this.everyPage = everyPage;
	}
	
	public int getEveryPage() {
		return this.everyPage;
	}
	
	public int getTotalPage() {

		if(totalItem % everyPage == 0) {
			return totalItem / everyPage;
		} else {
			return totalItem / everyPage + 1;
		}
	}
	
	public void setTotalItem(int totalItem) {
		this.totalItem = totalItem;
	}
	
	public int getTotalItem() {
		return this.totalItem;
	}
	
	public int getBeginPosition() {
		return currentPage * everyPage;
	}
	
	public int getEndPosition() {
		return (currentPage + 1) * everyPage - 1;
	}
	
	public boolean isFirstPage() {
		return (currentPage <= 0);
	}
	
	public boolean isLastPage() {
		
		int totalPage;
		totalPage = getTotalPage();
		if(currentPage >= totalPage - 1) {
			return true;
		} else {
			return false;
		}
	}
	
	public boolean isEmptyItem() {
		return (totalItem <= 0);
	}
}