|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.dasein.util.BrowseIterator<T>
T - the type of object being iterated overpublic class BrowseIterator<T>
Iterates through a multi-page list of items. The iterator
makes a small violation of the Iterator
contract by returning false for next() even when
more elements exist. The list is specifically exhausted
when both next() and hasMorePages()
return false.
This iterator divides a list into pages of a specified
page size. When no page size is specified, the value
from DEFAULT_PAGE_SIZE is used. You can specify
a Comparator to perform sorts on the
list prior to pagination.
This class also will store an ID field to help you create unique identifiers for the list for temporary storage and reference. You can ignore this value if you have no use for it.
Typical use of this iterator will be to display a list of items one page at a time via a web interface. When you first get the list and display the first page, you might have the following code (functions in italics are dependent on your implementation environment):
Collection<MyItem> items = someItemListing();
int page_size = 20;
BrowseIterator<MyItem> it;
it = new BrowseIterator<MyItem>(1, items, 20, null);
storeList(1, it);
while( it.hasNext() ) {
MyItem ob = it.next();
// display object in your list
}
When the user clicks the next button, your UI can respond:
long id = readValueFromParameters();
BrowseIterator<MyItem> it = lookupList(id);
it.nextPage();
while( it.hasNext() ) {
MyItem ob = it.next();
// display object in your list
}
Last modified: $Date: 2005/09/26 14:15:05 $
| Field Summary | |
|---|---|
static int |
DEFAULT_PAGE_SIZE
Default page size when none is specified. |
| Constructor Summary | |
|---|---|
BrowseIterator(Collection<T> items)
Constructs a new, unsorted browse iterator with the default page size having the specified items. |
|
BrowseIterator(Collection<T> items,
int ps)
Constructs a new, unsorted browse iterator with the specified page size having the specified items. |
|
BrowseIterator(Collection<T> items,
int ps,
Comparator<T> sort)
Constructs a new iterator with items sorted by the specified sorter. |
|
BrowseIterator(long lid,
Collection<T> items,
int ps)
Constructs an iterator having the specified unique ID. |
|
BrowseIterator(long lid,
Collection<T> items,
int ps,
Comparator<T> sort)
Constructs an iterator having the specified unique ID with specific sorting rules and page size. |
|
| Method Summary | |
|---|---|
void |
firstPage()
Sets the iterator to the first page in the iterator. |
int |
getItemCount()
|
long |
getListId()
Provides an application-defined unique identifier for this iterator. |
int |
getPage()
|
int |
getPageCount()
|
int |
getPageSize()
|
Comparator<T> |
getSorter()
|
boolean |
hasMorePages()
|
boolean |
hasNext()
|
void |
lastPage()
Navigates to the last page in the iterator. |
T |
next()
|
boolean |
nextPage()
Navigates to the next page in the iterator. |
boolean |
previousPage()
Navigates to the previous page in the iterator. |
void |
remove()
Throws an UnsupportedOperationException always. |
void |
reset()
Resets the list to the beginning of the iterator. |
boolean |
setPage(int p)
Navigates to the specified page number with 0 being the first page. |
void |
setPageSize(int ps)
Changes the page size of the list and reforms the list. |
void |
sort(Comparator<T> sort)
Re-sorts the list according to the specified sorter. |
String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_PAGE_SIZE
| Constructor Detail |
|---|
public BrowseIterator(Collection<T> items)
items - The items to be iterated over.
public BrowseIterator(Collection<T> items,
int ps)
items - the items to iterate overps - the page size for each page in the iterator
public BrowseIterator(Collection<T> items,
int ps,
Comparator<T> sort)
items - the items to be iterated overps - the page size for each page in the iteratorsort - the rules for sorting the items
public BrowseIterator(long lid,
Collection<T> items,
int ps)
lid - the unique ID to be used to reference this listitems - the items to iterate overps - the page size for each page in the iterator
public BrowseIterator(long lid,
Collection<T> items,
int ps,
Comparator<T> sort)
lid - the unique ID for this iteratoritems - the list of items to iterate overps - the page size for each page in the iteratorsort - the rules for sorting the items| Method Detail |
|---|
public void firstPage()
public int getItemCount()
public long getListId()
public int getPage()
public int getPageCount()
public int getPageSize()
public Comparator<T> getSorter()
public boolean hasMorePages()
public boolean hasNext()
hasNext in interface Iterator<T>public void lastPage()
public T next()
next in interface Iterator<T>public boolean nextPage()
public boolean previousPage()
public void remove()
UnsupportedOperationException always.
remove in interface Iterator<T>public void reset()
public boolean setPage(int p)
p - the page number to navigate to
public void setPageSize(int ps)
ps - the new page sizepublic void sort(Comparator<T> sort)
sort - the sorter to sort the list withpublic String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||