i2p.susi.util
Class Folder

java.lang.Object
  extended by i2p.susi.util.Folder

public class Folder
extends java.lang.Object

Folder object manages a array Object[] to support paging and sorting. You create a folder object, set the contents with setElements(), add Comparators with addSorter(), choose one with sortBy() and and then fetch the content of the current page with currentPageIterator().

Author:
susi

Field Summary
(package private)  java.util.Comparator currentSorter
           
static int DEFAULT_PAGESIZE
           
static boolean DOWN
           
static java.lang.String PAGESIZE
           
static boolean UP
           
 
Constructor Summary
Folder()
           
 
Method Summary
 void addSorter(java.lang.String id, java.util.Comparator sorter)
          Adds a new sorter to the folder.
 java.util.Iterator currentPageIterator()
          Returns an iterator containing the elements on the current page.
 void firstPage()
          Sets folder to display first page.
 int getCurrentPage()
          Returns the current page.
 java.lang.Object getElementAtPosXonCurrentPage(int x)
          Returns the element on the current page on the given position.
 java.lang.Object getFirstElement()
          Returns the first element of the sorted folder.
 java.lang.Object getLastElement()
          Returns the last element of the sorted folder.
 java.lang.Object getNextElement(java.lang.Object element)
          Retrieves the next element in the sorted array.
 int getPages()
          Returns the number of pages in the folder.
 int getPageSize()
          Returns page size.
 java.lang.Object getPreviousElement(java.lang.Object element)
          Retrieves the previous element in the sorted array.
 int getSize()
          Returns the size of the folder.
 boolean isFirstElement(java.lang.Object element)
          Returns true, if elements.equals( firstElementOfTheSortedArray ).
 boolean isFirstPage()
          Returns true, if folder shows points to the first page.
 boolean isLastElement(java.lang.Object element)
          Returns true, if elements.equals( lastElementOfTheSortedArray ).
 boolean isLastPage()
          Returns true, if folder shows points to the last page.
 void lastPage()
          Sets folder to display last page.
 void nextPage()
          Turns folder to next page.
 void previousPage()
          Turns folder to previous page.
 void setCurrentPage(int currentPage)
          Sets the current page to the given parameter.
 void setElements(java.lang.Object[] elements)
          Set the array of objects the folder should manage.
 void setPageSize(int pageSize)
          Set page size.
 void setSortingDirection(boolean direction)
          Sets the sorting direction of the folder.
 void sortBy(java.lang.String id)
          Activates sorting by the choosen Comparator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PAGESIZE

public static final java.lang.String PAGESIZE
See Also:
Constant Field Values

DEFAULT_PAGESIZE

public static final int DEFAULT_PAGESIZE
See Also:
Constant Field Values

DOWN

public static final boolean DOWN
See Also:
Constant Field Values

UP

public static final boolean UP
See Also:
Constant Field Values

currentSorter

java.util.Comparator currentSorter
Constructor Detail

Folder

public Folder()
Method Detail

getCurrentPage

public int getCurrentPage()
Returns the current page.

Returns:
Returns the current page.

setCurrentPage

public void setCurrentPage(int currentPage)
Sets the current page to the given parameter.

Parameters:
currentPage - The current page to set.

getSize

public int getSize()
Returns the size of the folder.

Returns:
Returns the size of the folder.

getPages

public int getPages()
Returns the number of pages in the folder.

Returns:
Returns the number of pages.

getPageSize

public int getPageSize()
Returns page size. If no page size has been set, it returns property @link PAGESIZE. If no property is set @link DEFAULT_PAGESIZE is returned.

Returns:
Returns the pageSize.

setPageSize

public void setPageSize(int pageSize)
Set page size.

Parameters:
pageSize - The page size to set.

setElements

public void setElements(java.lang.Object[] elements)
Set the array of objects the folder should manage.

Parameters:
elements - Array of Objects.

currentPageIterator

public java.util.Iterator currentPageIterator()
Returns an iterator containing the elements on the current page.

Returns:
Iterator containing the elements on the current page.

nextPage

public void nextPage()
Turns folder to next page.


previousPage

public void previousPage()
Turns folder to previous page.


firstPage

public void firstPage()
Sets folder to display first page.


lastPage

public void lastPage()
Sets folder to display last page.


addSorter

public void addSorter(java.lang.String id,
                      java.util.Comparator sorter)
Adds a new sorter to the folder. You can sort the folder by calling sortBy() and choose the given id there.

Parameters:
id - ID to identify the Comparator with @link sortBy()
sorter - a Comparator to sort the Array given by @link setElements()

sortBy

public void sortBy(java.lang.String id)
Activates sorting by the choosen Comparator. The id must match the one, which the Comparator has been stored in the folder with @link addSorter().

Parameters:
id - ID to identify the Comparator stored with @link addSorter()

getElementAtPosXonCurrentPage

public java.lang.Object getElementAtPosXonCurrentPage(int x)
Returns the element on the current page on the given position.

Parameters:
Position - of the element on the current page.
Returns:
Element on the current page on the given position.

setSortingDirection

public void setSortingDirection(boolean direction)
Sets the sorting direction of the folder.

Parameters:
direction - @link UP or @link DOWN

getFirstElement

public java.lang.Object getFirstElement()
Returns the first element of the sorted folder.

Returns:
First element.

getLastElement

public java.lang.Object getLastElement()
Returns the last element of the sorted folder.

Returns:
Last element.

getNextElement

public java.lang.Object getNextElement(java.lang.Object element)
Retrieves the next element in the sorted array. Sorting direction is taken into account.

Parameters:
element -
Returns:

getPreviousElement

public java.lang.Object getPreviousElement(java.lang.Object element)
Retrieves the previous element in the sorted array. Sorting direction is taken into account.

Parameters:
element -
Returns:

isLastPage

public boolean isLastPage()
Returns true, if folder shows points to the last page.

Returns:

isFirstPage

public boolean isFirstPage()
Returns true, if folder shows points to the first page.

Returns:

isLastElement

public boolean isLastElement(java.lang.Object element)
Returns true, if elements.equals( lastElementOfTheSortedArray ). The sorting direction influences which element is taken for comparison.

Parameters:
element -
Returns:

isFirstElement

public boolean isFirstElement(java.lang.Object element)
Returns true, if elements.equals( firstElementOfTheSortedArray ). The sorting direction influences which element is taken for comparison.

Parameters:
element -
Returns: