JAVA—咖啡館

          ——歡迎訪問rogerfan的博客,常來《JAVA——咖啡館》坐坐,喝杯濃香的咖啡,彼此探討一下JAVA技術(shù),交流工作經(jīng)驗,分享JAVA帶來的快樂!本網(wǎng)站部分轉(zhuǎn)載文章,如果有版權(quán)問題請與我聯(lián)系。

          BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
            447 Posts :: 145 Stories :: 368 Comments :: 0 Trackbacks
            1/**  
            2 * 分頁操作助手類   
            3 *  
            4 */
            
            5public class PagedList   
            6{   
            7    protected long count; //數(shù)據(jù)的總數(shù)   
            8    protected int last; //最后一頁   
            9    protected int previous;//上一頁   
           10    protected int index; //當前頁   
           11    protected int next; //下一頁   
           12    protected boolean hasFirst; //是否首頁   
           13    protected boolean hasLast; //是否最后一頁   
           14    protected boolean hasNext; //是否有下一頁   
           15    protected boolean hasPrevious;//是否有上一頁   
           16    protected List pageList;  //頁面顯示的頁碼集   
           17    protected List list;  //數(shù)據(jù)集   
           18       
           19    /**  
           20       * 構(gòu)造方法,構(gòu)建一個分頁類  
           21       *   
           22       * @param count 數(shù)據(jù)總數(shù)  
           23       * @param size  每頁顯示多少  
           24       * @param index 當前頁  
           25       * @param list  數(shù)據(jù)集  
           26       * @return  
           27      */
            
           28    public PagedList(long count, int size, int index, List list)   
           29    {   
           30        this.list = list;   
           31        this.count=count;   
           32        this.index=index;   
           33        if(index < 1)   
           34            index = 1;   
           35        if(count % (long)size > 0L)   
           36            last = (int)(count / (long)size + 1L);   
           37        else  
           38            last = (int)(count / (long)size);   
           39        //如果當前頁不是最后一頁,   
           40        hasNext = hasLast = index < last;   
           41        //如果有下一頁   
           42        if(hasNext)   
           43            next = index + 1;   
           44        //如果當前頁不是第一頁,   
           45        hasPrevious = hasFirst = index > 1;   
           46        //如果有上一頁   
           47        if(hasPrevious)   
           48            previous = index - 1;   
           49        //頁碼集   
           50        pageList = new ArrayList();   
           51        int start = 0;   
           52        int stop = 0;   
           53        if(index <= 5)   
           54        {   
           55            start = 1;   
           56            if(last > 10)   
           57                stop = 10;   
           58            else  
           59                stop = last;   
           60        }
           else  
           61        {   
           62            start = index - index % 5;   
           63            if(last > start + 10)   
           64                stop = start + 10;   
           65            else  
           66                stop = last;   
           67        }
             
           68        for(int i = start; i <= stop; i++)   
           69            pageList.add(Integer.valueOf(i));   
           70    }
             
           71  
           72    public List getList()   
           73    {   
           74        return list;   
           75    }
             
           76  
           77    public List getPageList()   
           78    {   
           79        return pageList;   
           80    }
             
           81  
           82    public long getCount()   
           83    {   
           84        return count;   
           85    }
             
           86  
           87    public int getPrevious()   
           88    {   
           89        return previous;   
           90    }
             
           91  
           92    public int getNext()   
           93    {   
           94        return next;   
           95    }
             
           96  
           97    public int getIndex()   
           98    {   
           99        return index;   
          100    }
             
          101  
          102    public int getLast()   
          103    {   
          104        return last;   
          105    }
             
          106  
          107    public boolean hasNext()   
          108    {   
          109        return hasNext;   
          110    }
             
          111  
          112    public boolean hasPrevious()   
          113    {   
          114        return hasPrevious;   
          115    }
             
          116  
          117    public boolean hasFirst()   
          118    {   
          119        return hasFirst;   
          120    }
             
          121  
          122    public boolean hasLast()   
          123    {   
          124        return hasLast;   
          125    }
             
          126  
          127      
          128}
            
          129
          130
          posted on 2010-06-21 10:13 rogerfan 閱讀(328) 評論(0)  編輯  收藏 所屬分類: 【Java知識】
          主站蜘蛛池模板: 罗江县| 韶关市| 武义县| 大城县| 合阳县| 滨海县| 乡宁县| 寿光市| 北票市| 巴彦县| 广州市| 安宁市| 灵寿县| 翼城县| 长子县| 荆州市| 息烽县| 保康县| 泰宁县| 平遥县| 宜兰县| 琼结县| 定陶县| 铁岭县| 时尚| 江津市| 东海县| 吴旗县| 霍山县| 武威市| 东辽县| 牟定县| 襄垣县| 望城县| 永善县| 读书| 石狮市| 荣成市| 仪陇县| 隆德县| 哈巴河县|