Package io.pravega.common.util
Class BufferedIterator<T>
- java.lang.Object
-
- io.pravega.common.util.BufferedIterator<T>
-
- Type Parameters:
T- Type of the items.
- All Implemented Interfaces:
java.util.Iterator<T>
@NotThreadSafe public class BufferedIterator<T> extends java.lang.Object implements java.util.Iterator<T>Fetches items in batches and presents them in the form of anIterator. Useful for cases when items need to be processed in sequence but there are not enough resources to load all of them at once in memory.
-
-
Constructor Summary
Constructors Constructor Description BufferedIterator(@NonNull java.util.function.BiFunction<java.lang.Long,java.lang.Long,java.util.Iterator<T>> getItemRange, long firstIndex, long lastIndex, int batchSize)Creates a new instance of theBufferedIteratorclass.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanhasNext()Tnext()
-
-
-
Constructor Detail
-
BufferedIterator
public BufferedIterator(@NonNull @NonNull java.util.function.BiFunction<java.lang.Long,java.lang.Long,java.util.Iterator<T>> getItemRange, long firstIndex, long lastIndex, int batchSize)Creates a new instance of theBufferedIteratorclass.- Parameters:
getItemRange- ABiFunctionthat returns a range of items that will be buffered next. The first argument is the first index to fetch (inclusive) and the second argument is the last index to fetch (inclusive). This method will always be invoked in sequence with non-overlapping ranges. This method will never be passed invalid args (Arg1 > Arg2) and it should never return an empty iterator.firstIndex- The index of the first item to return (inclusive).lastIndex- The index of the last item to return (inclusive).batchSize- The size of the batch (number of items to fetch at once).
-
-