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 a `DataProvider`. A `DataProvider` must call one of the following methods in order to provide some `Data`:
  - `setItem(Object)` - in case of a single object
  - `setItems(Collection)` - in case of a (non-sortable and non-pageable) collection of items
  - `setPage(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
  A `Resultset` (in case `isSingleResult()` returns `false`) or a `Result` is being added to the `Data` returned by `getWrappedData()` using a `ResultService`.
  Author:
    Matthias Müller

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `DataContainer(FieldProcessor fieldProcessor)` Creates a new `DataContainer` using the given `FieldProcessor`.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `FieldProcessor` | `getFieldProcessor()` Returns the `FieldProcessor` this `DataContainer` was created with
    `Object` | `getItem()` Returns the single item
    `Collection<?>` | `getItems()` Returns the items previously set via one of the `setItems(...)` -methods
    `org.springframework.data.domain.Page<?>` | `getPage()` Returns the `Page` (may be `null`) for this `DataContainer`
    `org.springframework.data.domain.Pageable` | `getPageable()` Returns the `Pageable` (may be `null`) for this `DataContainer`
    `List<SelectionGroup>` | `getSelectionGroups()` Convenience method to access the `SelectionGroup`s of the wrapped `Data`.
    `List<Selection>` | `getSelections()` Convenience method to access the `Selection`s of the wrapped `Data`.
    `Data` | `getWrappedData()` Returns the `Data` wrapped within this `DataContainer`
    `boolean` | `isSingleResult()` Returns whether this `DataContainer` contains only a single item
    `void` | `setItem(Object item)` Sets the single item
    `void` | `setItems(Collection<?> items)` Sets the `Collection` of items for this `DataContainer`.
    `void` | `setPage(Collection<?> items, org.springframework.data.domain.Pageable pageable)` Sets the `Page` for this `DataContainer`, which is being extracted from the given `Collection` of items, based on the given `Pageable`.
    `void` | `setPage(Collection<?> items, org.springframework.data.domain.Pageable pageable, boolean skipSort)` Sets the `Page` for this `DataContainer`, which is being extracted from the given `Collection` of items, based on the given `Pageable`. For example, if there are 15 items in the collection, and the `Pageable` requests (the 0-based) page 1 with a pagesize of 10, the resulting page will contain the (1-based) elements 11 to 15. If the `Pageable` has a `Sort` property set, the items will be sorted before extracting the page.
    `void` | `setPage(org.springframework.data.domain.Page<?> page)` Sets the `Page` for this `DataContainer`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DataContainer

          public DataContainer(FieldProcessor fieldProcessor)

      Creates a new `DataContainer` using the given `FieldProcessor`.
      Parameters:
        `fieldProcessor` - the `FieldProcessor` containing all readable `FieldDef`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 this `DataContainer` contains only a single item
      Returns:
        `true` if this `DataContainer` only contains a single result which has been set via `setItem(Object)`

    - #### getItems

          public Collection<?> getItems()

      Returns the items previously set via one of the `setItems(...)` -methods
      Returns:
        the items

    - #### setItems

          public void setItems(Collection<?> items)

      Sets the `Collection` of items for this `DataContainer`. Note that paging and sorting is not supported when using this method.
      Parameters:
        `items` - a `Collection` of items

    - #### setPage

          public void setPage(Collection<?> items,
                              org.springframework.data.domain.Pageable pageable)

      Sets the `Page` for this `DataContainer`, which is being extracted from the given `Collection` of items, based on the given `Pageable`. See `setPage(Collection, Pageable, boolean)` for details.
      Parameters:
        `items` - the `Collection` of items the extract the `Page` from
        `pageable` - the `Pageable` for the `Page` to extract
      See Also:
        `setPage(Collection, Pageable, boolean)`

    - #### setPage

          public void setPage(Collection<?> items,
                              org.springframework.data.domain.Pageable pageable,
                              boolean skipSort)

      Sets the `Page` for this `DataContainer`, which is being extracted from the given `Collection` of items, based on the given `Pageable`.
      For example, if there are 15 items in the collection, and the `Pageable` requests (the 0-based) page 1 with a pagesize of 10, the resulting page will contain the (1-based) elements 11 to 15.
      If the `Pageable` has a `Sort` 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 to `true`).

      Parameters:
        `items` - the `Collection` of items the extract the `Page` from
        `pageable` - the `Pageable` for the `Page` to extract
        `skipSort` - if the items should not get sorted, even if the `pageable` has a `Sort` property set

    - #### getPageable

          public org.springframework.data.domain.Pageable getPageable()

      Returns the `Pageable` (may be `null`) for this `DataContainer`
      Returns:
        the `Pageable`, if any
      See Also:
        `setPage(Page)`, `setPage(Collection, Pageable)`

    - #### getPage

          public org.springframework.data.domain.Page<?> getPage()

      Returns the `Page` (may be `null`) for this `DataContainer`
      Returns:
        the `Page`, if any
      See Also:
        `setPage(Page)`, `setPage(Collection, Pageable)`

    - #### setPage

          public void setPage(org.springframework.data.domain.Page<?> page)

      Sets the `Page` for this `DataContainer`
      Parameters:
        `page` - the `Page` to set

    - #### getSelections

          public List<Selection> getSelections()

      Convenience method to access the `Selection`s of the wrapped `Data`.
      Returns:
        a list of `Selection`s
      See Also:
        `getWrappedData()`

    - #### getSelectionGroups

          public List<SelectionGroup> getSelectionGroups()

      Convenience method to access the `SelectionGroup`s of the wrapped `Data`.
      Returns:
        a list of `SelectionGroup`s
      See Also:
        `getWrappedData()`

    - #### getWrappedData

          public Data getWrappedData()

      Returns the `Data` wrapped within this `DataContainer`
      Returns:
        the `Data`

    - #### getFieldProcessor

          public FieldProcessor getFieldProcessor()

      Returns the `FieldProcessor` this `DataContainer` was created with
      Returns:
        the `FieldProcessor`

Copyright © 2011–2023 aiticon GmbH. All rights reserved.