package apacs.util;
/**
* Creation date: (9/13/2000 8:48:22 PM)
* @author: XiaogangCao
*/
public class PageHelper {
/**
* PageHelper constructor comment.
*/
public PageHelper() {
super();
}
/**
* Insert the method's description here.
* Creation date: (9/13/2000 9:37:02 PM)
* @return boolean
* @param RowCounts int
* @param RowPerPage int
* @param PageNO int
*/
public static boolean isFirstPage(int RowCount, int RowPerPage, int PageNO)
{
if (RowCount == 0)
return true;
return PageNO==0;
}
/**
* Insert the method's description here.
* Creation date: (9/13/2000 9:37:02 PM)
* @return boolean
* @param RowCounts int
* @param RowPerPage int
* @param PageNO int
*/
public static boolean isFirstPage(apacs.db.Query q, int RowPerPage, int PageNO)
{
if (q.recordCount() == 0)
return true;
return PageNO==0;
}
/**
* Insert the method's description here.
* Creation date: (9/13/2000 9:37:02 PM)
* @return boolean
* @param RowCounts int
* @param RowPerPage int
* @param PageNO int
*/
public static boolean isLastPage(int RowCount, int RowPerPage, int PageNO)
{
if (RowCount == 0)
return true;
return PageNO==pageCount(RowCount,RowPerPage)-1;
}
/**
* Insert the method's description here.
* Creation date: (9/13/2000 9:37:02 PM)
* @return boolean
* @param RowCounts int
* @param RowPerPage int
* @param PageNO int
*/
public static boolean isLastPage(apacs.db.Query q, int RowPerPage, int PageNO)
{
if (q.recordCount() == 0)
return true;
return PageNO==pageCount(q,RowPerPage)-1;
}
/**
* Starts the application.
* @param args an array of command-line arguments
*/
public static void main(java.lang.String[] args)
{
int RowCount = 101;
int RowPerPage = 25;
System.out.println(pageCount(RowCount,RowPerPage));
System.out.println(pageRangeTop(RowPerPage,4));
System.out.println(pageRangeBottom(RowCount,RowPerPage,4));
}
/**
* Insert the method's description here.
* Creation date: (9/13/2000 8:50:11 PM)
* @return int
* @param RowCounts int
* @param RowPerPage int
*/
public static int pageCount(int RowCount, int RowPerPage)
{
return (RowCount + RowPerPage-1)/ RowPerPage;
}
/**
* Insert the method's description here.
* Creation date: (9/13/2000 8:50:48 PM)
* @return int
* @param q apacs.db.Query
* @param RowPerPage int
*/
public static int pageCount(apacs.db.Query q, int RowPerPage)
{
return (q.recordCount() + RowPerPage-1)/ RowPerPage;
}
/**
* Insert the method's description here.
* Creation date: (9/13/2000 8:53:36 PM)
* @return int
* @param RowPerPage int
* @param PageNO int
*/
public static int pageRangeBottom(int RowCount,int RowPerPage, int PageNO)
{
if (!pageValid(RowCount,RowPerPage,PageNO))
return -1;
if (isLastPage(RowCount,RowPerPage,PageNO))
return RowCount-1;
return ((PageNO+1) * RowPerPage)-1;
}
/**
* Insert the method's description here.
* Creation date: (9/13/2000 8:53:36 PM)
* @return int
* @param RowPerPage int
* @param PageNO int
*/
public static int pageRangeBottom(apacs.db.Query q,int RowPerPage, int PageNO)
{
if (!pageValid(q,RowPerPage,PageNO))
return -1;
if (isLastPage(q,RowPerPage,PageNO))
return q.recordCount()-1;
return ((PageNO+1) * RowPerPage)-1;
}
/**
* Insert the method's description here.
* Creation date: (9/13/2000 8:53:36 PM)
* @return int
* @param RowPerPage int
* @param PageNO int
*/
public static int pageRangeTop(int RowPerPage, int PageNO)
{
return PageNO * RowPerPage;
}
/**
* Insert the method's description here.
* Creation date: (9/13/2000 8:54:33 PM)
* @return boolean
* @param RowCount int
* @param RowPerPage int
* @param PageNO int
*/
public static boolean pageValid(int RowCount, int RowPerPage, int PageNO)
{
return ((PageNO >=0) &&
(PageNO<pageCount(RowCount,RowPerPage)));
}
/**
* Insert the method's description here.
* Creation date: (9/13/2000 8:54:33 PM)
* @return boolean
* @param RowCount int
* @param RowPerPage int
* @param PageNO int
*/
public static boolean pageValid(apacs.db.Query q, int RowPerPage, int PageNO)
{
return ((PageNO >=0) &&
(PageNO<pageCount(q,RowPerPage)));
}
}