用于处理画面翻页的类

package com.wen;

import java.util.*;

/**
 * 用于处理画面翻页的类
 * <p>Copyright: 2003</p>
 * @author Filippo Guan
 * @version 1.0
 */

public class ListPage {
    private List totalList;
    private int currentPageNum;
    private int totalPageNum;
    private int limit;

    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()/limit : totalList.size()/limit+1;
    }
        public ListPage(){
                this(new ArrayList());
        }
    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;
        return this.totalPageNum;
    }

    public int getPageLimit(){
        return limit;
    }
    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(){
        return currentPageNum;
    }

    public boolean hasPreviousPage(){
        return currentPageNum > 1;
    }

    public boolean hasNextPage(){
        return currentPageNum < totalPageNum;
    }

    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 NullPointerException("Has not Previous page");
        return this.getPage(currentPageNum - 1);
    }

    public List getNextPage(){
        if (!hasNextPage()) throw new NullPointerException("Has not Next page");
        return this.getPage(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;
        return this.getCurrentPage();
    }
// -----------------------------------------------------------
    public List getPage(int _pageNum){
        Vector vec = new Vector();
        for(int i=(_pageNum-1)*limit;i<_pageNum*limit && i<totalList.size();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){
      }
  }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值