KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > displaytag > pagination > SimplePaginatedList


1 /**
2  * Licensed under the Artistic License; you may not use this file
3  * except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  * http://displaytag.sourceforge.net/license.html
7  *
8  * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
9  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11  */

12 package org.displaytag.pagination;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.displaytag.properties.SortOrderEnum;
18 import org.displaytag.test.NumberedItem;
19
20
21 /**
22  * @author Fabrizio Giustina
23  * @version $Revision$ ($Author$)
24  */

25 public class SimplePaginatedList implements PaginatedList
26 {
27
28     /**
29      * wrapped list
30      */

31     private List JavaDoc fullList = new ArrayList JavaDoc();
32
33     /**
34      * Number of objects per page.
35      */

36     private int objectsPerPage;
37
38     /**
39      * Current page (starting from 1)
40      */

41     private int currentPage;
42
43     /**
44      * Instantiates a new paginated list.
45      */

46     public SimplePaginatedList(int objectsPerPage, int currentPage)
47     {
48         for (int j = 1; j < 11; j++)
49         {
50             fullList.add(new NumberedItem(j));
51         }
52         this.objectsPerPage = objectsPerPage;
53         this.currentPage = currentPage;
54     }
55
56     /**
57      * @see org.displaytag.pagination.PaginatedList#getList()
58      */

59     public List JavaDoc getList()
60     {
61         int startOffset = objectsPerPage * (currentPage - 1);
62         List JavaDoc sublist = fullList.subList(startOffset, Math.min(fullList.size(), startOffset + objectsPerPage));
63         return sublist;
64     }
65
66     /**
67      * @see org.displaytag.pagination.PaginatedList#getPageNumber()
68      */

69     public int getPageNumber()
70     {
71         return currentPage;
72     }
73
74     /**
75      * @see org.displaytag.pagination.PaginatedList#getObjectsPerPage()
76      */

77     public int getObjectsPerPage()
78     {
79         return objectsPerPage;
80     }
81
82     /**
83      * @see org.displaytag.pagination.PaginatedList#getFullListSize()
84      */

85     public int getFullListSize()
86     {
87         return fullList.size();
88     }
89
90     /**
91      * @see org.displaytag.pagination.PaginatedList#getSortCriterion()
92      */

93     public String JavaDoc getSortCriterion()
94     {
95         return "number";
96     }
97
98     /**
99      * @see org.displaytag.pagination.PaginatedList#getSortDirection()
100      */

101     public SortOrderEnum getSortDirection()
102     {
103         return SortOrderEnum.DESCENDING;
104     }
105
106     /**
107      * @see org.displaytag.pagination.PaginatedList#getSearchId()
108      */

109     public String JavaDoc getSearchId()
110     {
111         return Integer.toHexString(objectsPerPage * 10000 + currentPage);
112     }
113
114 }
115
Popular Tags