Package org.appng.api
Class DataContainer
- java.lang.Object
-
- org.appng.api.DataContainer
-
public final class DataContainer extends Object
A container for the data returned by aDataProvider
. ADataProvider
must call one of the following methods in order to provide someData
:setItem(Object)
- in case of a single objectsetItems(Collection)
- in case of a (non-sortable and non-pageable) collection of itemssetPage(Page)
- in case of a (potentially sorted/paginated)Page
setPage(Collection, Pageable)
/setPage(Collection, Pageable, boolean)
- in case where paging and sorting should be applied to a collection of items
Resultset
(in caseisSingleResult()
returnsfalse
) or aResult
is being added to theData
returned bygetWrappedData()
using aResultService
.- Author:
- Matthias Müller
-
-
Constructor Summary
Constructors Constructor Description DataContainer(FieldProcessor fieldProcessor)
Creates a newDataContainer
using the givenFieldProcessor
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FieldProcessor
getFieldProcessor()
Returns theFieldProcessor
thisDataContainer
was created withObject
getItem()
Returns the single itemCollection<?>
getItems()
Returns the items previously set via one of thesetItems(...)
-methodsorg.springframework.data.domain.Page<?>
getPage()
Returns thePage
(may benull
) for thisDataContainer
org.springframework.data.domain.Pageable
getPageable()
Returns thePageable
(may benull
) for thisDataContainer
List<SelectionGroup>
getSelectionGroups()
Convenience method to access theSelectionGroup
s of the wrappedData
.List<Selection>
getSelections()
Data
getWrappedData()
Returns theData
wrapped within thisDataContainer
boolean
isSingleResult()
Returns whether thisDataContainer
contains only a single itemvoid
setItem(Object item)
Sets the single itemvoid
setItems(Collection<?> items)
Sets theCollection
of items for thisDataContainer
.void
setPage(Collection<?> items, org.springframework.data.domain.Pageable pageable)
Sets thePage
for thisDataContainer
, which is being extracted from the givenCollection
of items, based on the givenPageable
.void
setPage(Collection<?> items, org.springframework.data.domain.Pageable pageable, boolean skipSort)
Sets thePage
for thisDataContainer
, which is being extracted from the givenCollection
of items, based on the givenPageable
.
For example, if there are 15 items in the collection, and thePageable
requests (the 0-based) page 1 with a pagesize of 10, the resulting page will contain the (1-based) elements 11 to 15.
If thePageable
has aSort
property set, the items will be sorted before extracting the page.void
setPage(org.springframework.data.domain.Page<?> page)
Sets thePage
for thisDataContainer
-
-
-
Constructor Detail
-
DataContainer
public DataContainer(FieldProcessor fieldProcessor)
Creates a newDataContainer
using the givenFieldProcessor
.- Parameters:
fieldProcessor
- theFieldProcessor
containing all readableFieldDef
initions
-
-
Method Detail
-
getItem
public Object getItem()
Returns the single item- Returns:
- the item
-
setItem
public void setItem(Object item)
Sets the single item- Parameters:
item
- the item
-
isSingleResult
public boolean isSingleResult()
Returns whether thisDataContainer
contains only a single item- Returns:
true
if thisDataContainer
only contains a single result which has been set viasetItem(Object)
-
getItems
public Collection<?> getItems()
Returns the items previously set via one of thesetItems(...)
-methods- Returns:
- the items
-
setItems
public void setItems(Collection<?> items)
Sets theCollection
of items for thisDataContainer
. Note that paging and sorting is not supported when using this method.- Parameters:
items
- aCollection
of items
-
setPage
public void setPage(Collection<?> items, org.springframework.data.domain.Pageable pageable)
Sets thePage
for thisDataContainer
, which is being extracted from the givenCollection
of items, based on the givenPageable
. SeesetPage(Collection, Pageable, boolean)
for details.- Parameters:
items
- theCollection
of items the extract thePage
frompageable
- thePageable
for thePage
to extract- See Also:
setPage(Collection, Pageable, boolean)
-
setPage
public void setPage(Collection<?> items, org.springframework.data.domain.Pageable pageable, boolean skipSort)
Sets thePage
for thisDataContainer
, which is being extracted from the givenCollection
of items, based on the givenPageable
.
For example, if there are 15 items in the collection, and thePageable
requests (the 0-based) page 1 with a pagesize of 10, the resulting page will contain the (1-based) elements 11 to 15.
If thePageable
has aSort
property set, the items will be sorted before extracting the page.Note that sorting the items is done by using Java Reflection-API, thus for performance reasons it is not recommended to apply sorting to very large collections. Such collections should be pre-sorted before in a non-reflective way (then
skipSort
should be set totrue
).- Parameters:
items
- theCollection
of items the extract thePage
frompageable
- thePageable
for thePage
to extractskipSort
- if the items should not get sorted, even if thepageable
has aSort
property set
-
getPageable
public org.springframework.data.domain.Pageable getPageable()
Returns thePageable
(may benull
) for thisDataContainer
- Returns:
- the
Pageable
, if any - See Also:
setPage(Page)
,setPage(Collection, Pageable)
-
getPage
public org.springframework.data.domain.Page<?> getPage()
Returns thePage
(may benull
) for thisDataContainer
- Returns:
- the
Page
, if any - See Also:
setPage(Page)
,setPage(Collection, Pageable)
-
setPage
public void setPage(org.springframework.data.domain.Page<?> page)
Sets thePage
for thisDataContainer
- Parameters:
page
- thePage
to set
-
getSelections
public List<Selection> getSelections()
- Returns:
- a list of
Selection
s - See Also:
getWrappedData()
-
getSelectionGroups
public List<SelectionGroup> getSelectionGroups()
Convenience method to access theSelectionGroup
s of the wrappedData
.- Returns:
- a list of
SelectionGroup
s - See Also:
getWrappedData()
-
getWrappedData
public Data getWrappedData()
Returns theData
wrapped within thisDataContainer
- Returns:
- the
Data
-
getFieldProcessor
public FieldProcessor getFieldProcessor()
Returns theFieldProcessor
thisDataContainer
was created with- Returns:
- the
FieldProcessor
-
-