org.springframework.batch.core.step.item

## Class Chunk<W>

- java.lang.Object
- - org.springframework.batch.core.step.item.Chunk<W>

- All Implemented Interfaces:
    java.lang.Iterable<W>

      public class Chunk<W>
      extends java.lang.Object
      implements java.lang.Iterable<W>

  Encapsulation of a list of items to be processed and possibly a list of failed items to be skipped. To mark an item as skipped clients should iterate over the chunk using the `iterator()` method, and if there is a failure call `Chunk.ChunkIterator.remove()` on the iterator. The skipped items are then available through the chunk.
  Since:
    2.0
  Author:
    Dave Syer

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `Chunk.ChunkIterator` Special iterator for a chunk providing the `Chunk.ChunkIterator.remove(Throwable)` method for dynamically removing an item and adding it to the skips.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Chunk()`
    `Chunk(java.util.Collection<? extends W> items)`
    `Chunk(java.util.Collection<? extends W> items, java.util.List<SkipWrapper<W>> skips)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(W item)` Add the item to the chunk.
    `void` | `clear()` Clear the items down to signal that we are done.
    `void` | `clearSkips()` Clear only the skips list.
    `java.util.List<java.lang.Exception>` | `getErrors()`
    `java.util.List<W>` | `getItems()`
    `java.util.List<SkipWrapper<W>>` | `getSkips()`
    `java.lang.Object` | `getUserData()`
    `boolean` | `isBusy()` Query the chunk to see if anyone has registered an interest in keeping a reference to it.
    `boolean` | `isEmpty()`
    `boolean` | `isEnd()` Flag to indicate if the source data is exhausted.
    `Chunk.ChunkIterator` | `iterator()` Get an unmodifiable iterator for the underlying items.
    `void` | `setBusy(boolean busy)` Register an interest in the chunk to prevent it from being cleaned up before the flag is reset to false.
    `void` | `setEnd()` Set the flag to say that this chunk represents an end of stream (there is no more data to process).
    `void` | `setUserData(java.lang.Object userData)`
    `int` | `size()`
    `void` | `skip(java.lang.Exception e)` Register an anonymous skip.
    `java.lang.String` | `toString()`

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

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

    - ### Methods inherited from interface java.lang.Iterable

      `forEach, spliterator`

- - ### Constructor Detail

    - #### Chunk

          public Chunk()

    - #### Chunk

          public Chunk(java.util.Collection<? extends W> items)

    - #### Chunk

          public Chunk(java.util.Collection<? extends W> items,
                       java.util.List<SkipWrapper<W>> skips)

  - ### Method Detail

    - #### add

          public void add(W item)

      Add the item to the chunk.
      Parameters:
        `item` - the item to add

    - #### clear

          public void clear()

      Clear the items down to signal that we are done.

    - #### getItems

          public java.util.List<W> getItems()

      Returns:
        a copy of the items to be processed as an unmodifiable list

    - #### getSkips

          public java.util.List<SkipWrapper<W>> getSkips()

      Returns:
        a copy of the skips as an unmodifiable list

    - #### getErrors

          public java.util.List<java.lang.Exception> getErrors()

      Returns:
        a copy of the anonymous errors as an unmodifiable list

    - #### skip

          public void skip(java.lang.Exception e)

      Register an anonymous skip. To skip an individual item, use `Chunk.ChunkIterator.remove()`.
      Parameters:
        `e` - the exception that caused the skip

    - #### isEmpty

          public boolean isEmpty()

      Returns:
        true if there are no items in the chunk

    - #### iterator

          public Chunk.ChunkIterator iterator()

      Get an unmodifiable iterator for the underlying items.
      Specified by:
        `iterator` in interface `java.lang.Iterable<W>`
      See Also:
        `Iterable.iterator()`

    - #### size

          public int size()

      Returns:
        the number of items (excluding skips)

    - #### isEnd

          public boolean isEnd()

      Flag to indicate if the source data is exhausted.
      Returns:
        true if there is no more data to process

    - #### setEnd

          public void setEnd()

      Set the flag to say that this chunk represents an end of stream (there is no more data to process).

    - #### isBusy

          public boolean isBusy()

      Query the chunk to see if anyone has registered an interest in keeping a reference to it.
      Returns:
        the busy flag

    - #### setBusy

          public void setBusy(boolean busy)

      Register an interest in the chunk to prevent it from being cleaned up before the flag is reset to false.
      Parameters:
        `busy` - the flag to set

    - #### clearSkips

          public void clearSkips()

      Clear only the skips list.

    - #### getUserData

          public java.lang.Object getUserData()

    - #### setUserData

          public void setUserData(java.lang.Object userData)

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`