Package com.wen;
Import java.util. *;
/ ** * Used to handle the page of the screen *
Copyright: 2003 p> * @Author Filippo guan * @version 1.0 * /
Public Class ListPage {Private Int CurrentPagenum; Private Int TotalPagenum; Private Int Totalpagenum
public ListPage (List _totalList, int _pageLimit) {if (_totalList == null) {totalList = new ArrayList ();} else {totalList = _totalList;} limit = _pageLimit; currentPageNum = 1; totalPageNum = totalList.size ()% limit == 0? Totallist.size () / limited: totallist.size () / limited 1;} public listpage ();} public listpage (list _totallist) {this (_totallist, 10) }
Public void clear () {this.totallist = new vector (); currentpagenum = 1; TotalPagenum = 0;}
Public int size () {return totallist.size ();
Public List GetTotallist () {Return Totallist;}
Public int gettotalpagenum () {if (totallist == null) Return 0; TotalPagenum = Totallist.size ()% limit == 0? Totallist.size () / limit: totallist.size () / limit 1; returnid. Totalpagenum;
Public int getpagelimit () {returnit;} public void setpagelimit (int _limit) {limit = _limit;}
/ / -------------------------------------------------------------------------------------------- ----------- Public Object getLineObject (int _LineNum) {if (totallist == null) Return Null; Object Retobj = Totallist.Get (CurrentPagenum-1) * Limit _LineNum - 1); Return Retobj;} // --------------------------------------------- -------------- Public void setcurrentpagenum (int _CurrentPagenum) {currentpagenum = _currentpagenum;} public int getcurrentpagenum ()}
Public Boolean Haspreviouspage () {Return CurrentPagenum> 1;
Public Boolean HasnextPage () {Return CurrentPagenum Public List getCurrentPage () {return getpage (currentpagenum); Public List getFirstPage () {return this.getpage (1); Public List GetLastPage () {Return this.getPage (TotalPagenum); Public List getPreviouspage () {if (! Haspreviouspage ()) Throw New NullPointersReption ("HAS NOT PREVIOUS PAGE"); Return this.getPage (CurrentPagenum - 1); Public List getNextPage () {if (! hasnextpage ()) throw new nullpointEREXCEPTION ("HAS NOT NEXT PAGE"); Return THITPAGE (CurrentPagenum 1);} Public List TurnPreviouspage () {this.currentpagenum--; return this.getcurrentpage (); Public List TurnnexTPage () {this.currentpagenum ; return this.getcurrentpage (); Public List TurnfirstPage () {this.currentpagenum = 1; return this.getcurrentpage (); Public List TurnLastPage () {this.currentpagenum = this.totalpagenum; returnimpagenum; returnimpage ();} // ------------------------------------------------------------------------------------------------------------------ --------------------------------- Public List getPage (int _PAGENUM) {Vector VEC = New Vector (); for (INT I = (_ PAGENUM-1) * limited; i <_pagenum * limited (); i ) {vec.add (Totallist.get (i));} return vec;} public boolean isfirstpage INT _PAGENUM) {return_pagenum == 1;} Public boolean islastpage (int _PAGENUM) {return_pagenum == TotalPagenum; Public static void main (string [] args) {vector tryvec = new vector (); for (int i = 0; i <49; i ) {tryVec.add ("test" integer.tostring (i));} ListPage page = new ListPage (tryVec, 10); System.err.println ( "MaxPage =" page.getTotalPageNum ()); if (page.hasNextPage ()) page.turnNextPage (); Vector retVec = new Vector (page .getcurrentpage (); try {system.in.read ();} catch (exception e) {}} }