package com.huawei.iread.ieach.util;
import java.util.List;
/**
* pagination class
*
* @author Administrator
*
*/
@SuppressWarnings("unchecked")
public class Pager
{
public final static int PAGESIZE = 10;
private int pageSize = PAGESIZE;
private int totalCount;
private int currentPage;
private int totalPage;
private List items = null;
private String staticUrl;
private int prePage = 0;
private int nextPage = 0;
private int wap_version = 1;
/**
* constructor
*
* @param list
* @param totalCount
* @param pageSize
* @param currentPage
*/
public Pager(List list, int totalCount, int currentPage, int pageSize)
{
if (!(list == null || list.isEmpty()))
{
this.items = list;
this.totalCount = totalCount;
this.pageSize = pageSize;
this.currentPage = currentPage;
this.setTotalPage(totalCount);
}
}
public Pager(List list, int totalCount, int currentPage, int pageSize,
String staticUrl)
{
if (!(list == null || list.isEmpty()))
{
this.items = list;
this.totalCount = totalCount;
this.pageSize = pageSize;
this.currentPage = currentPage;
this.staticUrl = staticUrl;
this.setTotalPage(totalCount);
}
}
public Pager(int totalCount, int currentPage, int pageSize, String staticUrl)
{
this.totalCount = totalCount;
this.pageSize = pageSize;
this.currentPage = currentPage;
this.staticUrl = staticUrl;
this.setTotalPage(totalCount);
}
public Pager(List list, int totalCount, int currentPage, int pageSize,
String staticUrl, int wap_version)
{
if (!(list == null || list.isEmpty()))
{
this.items = list;
this.totalCount = totalCount;
this.pageSize = pageSize;
this.currentPage = currentPage;
this.staticUrl = staticUrl;
this.setTotalPage(totalCount);
this.wap_version = wap_version;
}
}
/**
* get items
*
* @return
*/
public List getItems()
{
return items;
}
/**
* calculate total Page
*
* @param totalCount
*/
public void setTotalPage(int totalCount)
{
int count = 0;
count = totalCount / pageSize;
if (totalCount % pageSize > 0)
{
count++;
}
this.totalPage = count;
if (this.totalPage <= this.currentPage)
{
this.currentPage = this.totalPage;
this.nextPage = this.totalPage;
}
else
{
this.nextPage = this.currentPage + 1;
}
if (this.currentPage <= 1)
{
this.currentPage = 1;
this.prePage = 1;
}
else
{
this.prePage = this.currentPage - 1;
}
}
public int getTotalCount()
{
return totalCount;
}
public int getCurrentPage()
{
return currentPage;
}
public int getTotalPage()
{
return totalPage;
}
public int getPageSize()
{
return pageSize;
}
public String getStaticUrl()
{
return staticUrl;
}
public int getPrePage()
{
return prePage;
}
public int getNextPage()
{
return nextPage;
}
public int getWap_version()
{
return wap_version;
}
}