Class CounterIterator<T>

java.lang.Object
fr.lirmm.graphik.util.stream.AbstractCloseableIterator<T>
fr.lirmm.graphik.util.stream.CounterIterator<T>
Type Parameters:
T - type of elements of the iterator
All Implemented Interfaces:
CloseableIterator<T>, Closeable, AutoCloseable

public class CounterIterator<T> extends AbstractCloseableIterator<T>
Counts the number of elements read from a closeable iterator.
Author:
Clément Sipieter (INRIA) <clement@6pi.fr>
  • Constructor Details

    • CounterIterator

      public CounterIterator(CloseableIterator<T> it)
      Creates a counter around the provided iterator.
      Parameters:
      it - the iterator to wrap
  • Method Details

    • getCptValue

      public int getCptValue()
      Returns the number of elements returned so far.
      Returns:
      the current element count
    • 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 T 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()