Class CloseableIteratorAccumulator<E>

java.lang.Object
fr.lirmm.graphik.util.stream.AbstractCloseableIterator<E>
fr.lirmm.graphik.util.stream.CloseableIteratorAccumulator<E>
Type Parameters:
E - the iterated element type
All Implemented Interfaces:
CloseableIterator<E>, Closeable, AutoCloseable

public class CloseableIteratorAccumulator<E> extends AbstractCloseableIterator<E>
This Iterator stores the items passed in a buffer memory.
Author:
Olivier Rodriguez
  • Constructor Details

    • CloseableIteratorAccumulator

      public CloseableIteratorAccumulator(CloseableIterator<E> it) throws IteratorException
      Creates an accumulator around the specified iterator.
      Parameters:
      it - the iterator to consume and buffer
      Throws:
      IteratorException - if testing the first element fails
  • Method Details

    • hasNext

      public boolean hasNext() throws IteratorException
      Description copied from interface: CloseableIterator
      Returns whether another element is available.
      Returns:
      true if another element can be read
      Throws:
      IteratorException - if the iteration fails
    • next

      public E next() throws IteratorException
      Description copied from interface: CloseableIterator
      Returns the next element.
      Returns:
      the next element
      Throws:
      IteratorException - if the iteration fails
    • close

      public void close()
    • consumeAll

      public CloseableIteratorAccumulator<E> consumeAll() throws IteratorException
      Consume the iterator (iterate until the last element).
      Returns:
      this accumulator after the iterator has been exhausted
      Throws:
      IteratorException - if the iteration fails
    • toArray

      public E[] toArray()
      Returns the buffered elements as an array.
      Returns:
      the buffered elements
    • getList

      public List<E> getList()
      Returns a copy of the buffered elements.
      Returns:
      the buffered elements as a list