Class BatchingIterator<ObjectType>
- java.lang.Object
-
- com.identityworksllc.iiq.common.iterators.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 Summary
Constructors Constructor Description BatchingIterator(Iterator<? extends ObjectType> input, int batchSize)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the iterator by flushing the input iteratorboolean
hasNext()
Retrieves the next batch of items and returns true if the batch is not empty.List<ObjectType>
next()
Returns the next item, which is derived during hasNext().-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
-
-
-
Constructor Detail
-
BatchingIterator
public BatchingIterator(Iterator<? extends ObjectType> input, int batchSize)
Constructor- Parameters:
input
- The iterator being wrapped by this transformerbatchSize
- The batch size
-
-
Method Detail
-
close
public void close()
Closes the iterator by flushing the input iterator- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfacesailpoint.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 interfacesailpoint.tools.CloseableIterator<ObjectType>
- Specified by:
hasNext
in interfaceIterator<ObjectType>
- Returns:
- True if the batch is not empty and next() will return a value
-
next
public List<ObjectType> next()
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 interfacesailpoint.tools.CloseableIterator<ObjectType>
- Specified by:
next
in interfaceIterator<ObjectType>
- Returns:
- The next item
- Throws:
NoSuchElementException
- if hasNext() has not been invoked or if it returned false
-
-