Class 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 an Iterator. 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 the BufferedIterator class.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean hasNext()  
      T next()  
      • 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

      • 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 the BufferedIterator class.
        Parameters:
        getItemRange - A BiFunction that 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).
    • Method Detail

      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface java.util.Iterator<T>
      • next

        public T next()
        Specified by:
        next in interface java.util.Iterator<T>