Class BatchingIterator<ObjectType>

  • Type Parameters:
    ObjectType -
    All Implemented Interfaces:
    AutoCloseable, Iterator<List<ObjectType>>, sailpoint.tools.CloseableIterator<List<ObjectType>>

    public class BatchingIterator<ObjectType>
    extends Object
    implements AutoCloseable, sailpoint.tools.CloseableIterator<List<ObjectType>>, Iterator<List<ObjectType>>
    An iterator that batches up the inputs into batches of size ‘batchSize’, then returns them in chunks.

    The last batch may, of course, be smaller than the batch size.

    Similar to the Guava Iterators.partition(Iterator, int)

    • Constructor Detail

      • BatchingIterator

        public BatchingIterator​(Iterator<? extends ObjectType> input,
                                int batchSize)
        Constructor
        Parameters:
        input - The iterator being wrapped by this transformer
        batchSize - The batch size
    • Method Detail

      • close

        public void close()
        Closes the iterator by flushing the input iterator
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface sailpoint.tools.CloseableIterator<ObjectType>
      • hasNext

        public boolean hasNext()
        Retrieves the next batch of items and returns true if the batch is not empty.

        Note that if this iterator wraps something slow (e.g., an iterator that is streaming from disk or something), hasNext() will take a while.

        You MUST call hasNext() before any call to next() will work properly.

        Specified by:
        hasNext in interface sailpoint.tools.CloseableIterator<ObjectType>
        Specified by:
        hasNext in interface Iterator<ObjectType>
        Returns:
        True if the batch is not empty and next() will return a value
      • next

        public List<ObjectTypenext()
        Returns the next item, which is derived during hasNext().

        The result is always an immutable copy of the internal state of this class.

        Specified by:
        next in interface sailpoint.tools.CloseableIterator<ObjectType>
        Specified by:
        next in interface Iterator<ObjectType>
        Returns:
        The next item
        Throws:
        NoSuchElementException - if hasNext() has not been invoked or if it returned false