1 12 package org.displaytag.pagination; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.displaytag.properties.SortOrderEnum; 18 import org.displaytag.test.NumberedItem; 19 20 21 25 public class SimplePaginatedList implements PaginatedList 26 { 27 28 31 private List fullList = new ArrayList (); 32 33 36 private int objectsPerPage; 37 38 41 private int currentPage; 42 43 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 59 public List getList() 60 { 61 int startOffset = objectsPerPage * (currentPage - 1); 62 List sublist = fullList.subList(startOffset, Math.min(fullList.size(), startOffset + objectsPerPage)); 63 return sublist; 64 } 65 66 69 public int getPageNumber() 70 { 71 return currentPage; 72 } 73 74 77 public int getObjectsPerPage() 78 { 79 return objectsPerPage; 80 } 81 82 85 public int getFullListSize() 86 { 87 return fullList.size(); 88 } 89 90 93 public String getSortCriterion() 94 { 95 return "number"; 96 } 97 98 101 public SortOrderEnum getSortDirection() 102 { 103 return SortOrderEnum.DESCENDING; 104 } 105 106 109 public String getSearchId() 110 { 111 return Integer.toHexString(objectsPerPage * 10000 + currentPage); 112 } 113 114 } 115 | Popular Tags |