JAVA—咖啡館

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

          BlogJava 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
            447 Posts :: 145 Stories :: 368 Comments :: 0 Trackbacks
            1/**  
            2 * 分頁(yè)操作助手類   
            3 *  
            4 */
            
            5public class PagedList   
            6{   
            7    protected long count; //數(shù)據(jù)的總數(shù)   
            8    protected int last; //最后一頁(yè)   
            9    protected int previous;//上一頁(yè)   
           10    protected int index; //當(dāng)前頁(yè)   
           11    protected int next; //下一頁(yè)   
           12    protected boolean hasFirst; //是否首頁(yè)   
           13    protected boolean hasLast; //是否最后一頁(yè)   
           14    protected boolean hasNext; //是否有下一頁(yè)   
           15    protected boolean hasPrevious;//是否有上一頁(yè)   
           16    protected List pageList;  //頁(yè)面顯示的頁(yè)碼集   
           17    protected List list;  //數(shù)據(jù)集   
           18       
           19    /**  
           20       * 構(gòu)造方法,構(gòu)建一個(gè)分頁(yè)類  
           21       *   
           22       * @param count 數(shù)據(jù)總數(shù)  
           23       * @param size  每頁(yè)顯示多少  
           24       * @param index 當(dāng)前頁(yè)  
           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        //如果當(dāng)前頁(yè)不是最后一頁(yè),   
           40        hasNext = hasLast = index < last;   
           41        //如果有下一頁(yè)   
           42        if(hasNext)   
           43            next = index + 1;   
           44        //如果當(dāng)前頁(yè)不是第一頁(yè),   
           45        hasPrevious = hasFirst = index > 1;   
           46        //如果有上一頁(yè)   
           47        if(hasPrevious)   
           48            previous = index - 1;   
           49        //頁(yè)碼集   
           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) 評(píng)論(0)  編輯  收藏 所屬分類: 【Java知識(shí)】
          主站蜘蛛池模板: 沙坪坝区| 大石桥市| 高台县| 屏东县| 竹溪县| 马公市| 洛隆县| 交城县| 越西县| 静乐县| 休宁县| 新干县| 禄劝| 平舆县| 佛教| 克什克腾旗| 九龙城区| 安平县| 云林县| 南部县| 建宁县| 广饶县| 本溪市| 卢龙县| 高邑县| 隆昌县| 威海市| 岳池县| 肥乡县| 正安县| 金溪县| 江川县| 襄城县| 巩留县| 封开县| 合水县| 故城县| 马鞍山市| 柞水县| 同江市| 东阿县|