org.loom.paged
Class PagedListDataFactory

java.lang.Object
  extended by org.loom.paged.PagedListDataFactory

public class PagedListDataFactory
extends java.lang.Object


Constructor Summary
PagedListDataFactory()
           
 
Method Summary
static
<T1,T2> PagedListData<T2>
convert(PagedListData<T1> sourceData, com.google.common.base.Function<T1,T2> function)
          Convert the data of one PagedListData into another PagedListData instance, transforming the list contents.
static
<T> PagedListData<T>
create(java.util.List<T> list, java.util.Comparator<T> comparator, PagedListCriteria criteria)
          Creates a data object according to the provided criteria
static
<T> PagedListData<T>
create(PagedListCriteria criteria)
          Creates a data object according to the provided criteria
static
<T> PagedListData<T>
create(PagedListCriteria criteria, java.util.List<T> list)
          Creates a data object Note that this method is (relatively) inefficient and sorting and paging should be done by the backend instead.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PagedListDataFactory

public PagedListDataFactory()
Method Detail

create

public static <T> PagedListData<T> create(PagedListCriteria criteria)
Creates a data object according to the provided criteria

Parameters:
criteria - the criteria object, where page index, sorting etc will be extracted from.
Returns:
a PagedListData instance with the same properties of the provided criteria object

create

public static <T> PagedListData<T> create(PagedListCriteria criteria,
                                          java.util.List<T> list)
Creates a data object Note that this method is (relatively) inefficient and sorting and paging should be done by the backend instead.

Parameters:
criteria - the criteria object, where page index, sorting etc will be extracted from.
list - the entire list of results. It will be sorted and the current page will be extracted from it.
Returns:
a PagedListData instance with the same properties of the provided criteria object, and the contents of the current page extracted from the provided list.

create

public static <T> PagedListData<T> create(java.util.List<T> list,
                                          java.util.Comparator<T> comparator,
                                          PagedListCriteria criteria)
Creates a data object according to the provided criteria

Type Parameters:
T - the type of each record object
Parameters:
list - the entire list of results. Pagination and ordering will be applied on this.
comparator - the Comparator to do the sorting. If null, no sort will be performed
criteria - The pagination, sorting properties, etc.
Returns:
a PagedListData instance with the same properties as the provided criteria object, and the list of rows corresponding to this page.

convert

public static <T1,T2> PagedListData<T2> convert(PagedListData<T1> sourceData,
                                                com.google.common.base.Function<T1,T2> function)
Convert the data of one PagedListData into another PagedListData instance, transforming the list contents. The resulting instance will have the same pageIndex, size, total results, etc, but its data will be the result of applying the function to each item in source.getData()

Type Parameters:
T1 - The type of the source list contents
T2 - The type of the destination list contents
Parameters:
sourceData - the PagedListData that will be transformed
function - the function that will transform each item
Returns:
A PagedListData instance with the result of applying the function to the source object.