org.pm4j.core.pm.pageable
Class PageableCollectionUtil

java.lang.Object
  extended by org.pm4j.core.pm.pageable.PageableCollectionUtil

public final class PageableCollectionUtil
extends java.lang.Object

Some common algorithms that should not be implemented redundantly for each kind of Pageable.

Author:
olaf boede

Constructor Summary
PageableCollectionUtil()
           
 
Method Summary
static int getIdxOfFirstItemOnPage(PageableCollection<?> pageable)
           
static int getIdxOfLastItemOnPage(PageableCollection<?> pageable)
           
static int getNumOfPages(PageableCollection<?> pageable)
           
static int getPageForItemPos(PageableCollection<?> pageable, int itemPos)
           
static boolean hasNextPage(PageableCollection<?> pageable)
           
static boolean hasPrevPage(PageableCollection<?> pageable)
           
static
<T> boolean
isAllOnPageSelected(PageableCollection<T> pageable)
           
static void navigateToFirstPage(PageableCollection<?> pageable)
          Navigates to the last page.
static void navigateToLastPage(PageableCollection<?> pageable)
          Navigates to the last page.
static void navigateToNextPage(PageableCollection<?> pageable)
          Navigates one page forward.
static void navigateToPrevPage(PageableCollection<?> pageable)
          Navigates one page back.
static
<T> void
setAllOnPageSelected(PageableCollection<T> pageable, boolean doSelect)
          Select or deselect all items displayed on the current page.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PageableCollectionUtil

public PageableCollectionUtil()
Method Detail

getIdxOfFirstItemOnPage

public static int getIdxOfFirstItemOnPage(PageableCollection<?> pageable)
Parameters:
pageable - The set to get the result for.
Returns:
The index of the first item on the current page.

Starts with one.
Is zero if there are no items in this set.


getIdxOfLastItemOnPage

public static int getIdxOfLastItemOnPage(PageableCollection<?> pageable)
Parameters:
pageable - The set to get the result for.
Returns:
The index of the last item on the current page.

Starts with one.
Is zero if there are no items in this set.


getPageForItemPos

public static int getPageForItemPos(PageableCollection<?> pageable,
                                    int itemPos)
Parameters:
pageable - The PageableCollection to evaluate.
itemPos - The position to get the page number for. Starts with One.
Returns:
The page number for the given item position. One for the first page.

getNumOfPages

public static int getNumOfPages(PageableCollection<?> pageable)
Parameters:
pageable - The set to get the result for.
Returns:
The number of available pages.

navigateToPrevPage

public static void navigateToPrevPage(PageableCollection<?> pageable)
Navigates one page back.

Does nothing if the set is already on the first page or has no items.

Parameters:
pageable - The set to handle.

navigateToNextPage

public static void navigateToNextPage(PageableCollection<?> pageable)
Navigates one page forward.

Does nothing if the set is already on the last page or has no items.

Parameters:
pageable - The set to handle.

navigateToFirstPage

public static void navigateToFirstPage(PageableCollection<?> pageable)
Navigates to the last page.

Does nothing if the set is already on the last page or has no items.

Parameters:
pageable - The set to handle.

navigateToLastPage

public static void navigateToLastPage(PageableCollection<?> pageable)
Navigates to the last page.

Does nothing if the set is already on the last page or has no items.

Parameters:
pageable - The set to handle.

hasNextPage

public static boolean hasNextPage(PageableCollection<?> pageable)
Parameters:
pageable - The set to handle.
Returns:
true if there is a following page to navigate to.

hasPrevPage

public static boolean hasPrevPage(PageableCollection<?> pageable)
Parameters:
pageable - The set to handle.
Returns:
true if there is a previous page to navigate to.

setAllOnPageSelected

public static <T> void setAllOnPageSelected(PageableCollection<T> pageable,
                                            boolean doSelect)
Select or deselect all items displayed on the current page.

Parameters:
pageable - The set to handle.
doSelect - true selects all items of the current page.
false does deselect all items of the current page.

isAllOnPageSelected

public static <T> boolean isAllOnPageSelected(PageableCollection<T> pageable)
Parameters:
pageable - The set to handle.
Returns:
true if all items on the current page are selected.

For an empty page always false.