Class PaginatedSpliterator<T>

  • Type Parameters:
    T - supplier type
    All Implemented Interfaces:
    Spliterator<T>

    public class PaginatedSpliterator<T>
    extends Object
    implements Spliterator<T>
    Spliterator implementation that populates new data to the stream by calling recurrently a provided page supplier. Usage: ;grt& Spliterator ‹ MyType › spliterator=new PaginatedSupplierSpliterator ‹ › (myLastType -> myTypePageSupplier(),estimatedAmount); Stream ‹ MyType › autoPopulatedStream=StreamSupport.stream(spliterator,true); This spliterator return the fields ORDERED, return NONNULL values, is IMMUTABLE and CONCURRENT compatible but NOT SIZED Very important: the supplier must return an ordered results otherwise can not ensure to not return the same value more than once
    Author:
    afarre
    • Field Detail

      • DEFAULT_ESTIMATED_TOTAL

        public static final long DEFAULT_ESTIMATED_TOTAL
        See Also:
        Constant Field Values
      • buffer

        protected Deque<T> buffer
      • from

        protected T from
    • Constructor Detail

      • PaginatedSpliterator

        public PaginatedSpliterator​(Function<T,​List<T>> _pageSupplier)
        Constructor receiving the _pageSupplier using DEFAULT_ESTIMATED_TOTAL as estimated total.
        Parameters:
        _pageSupplier - page supplier (must return an ordered results otherwise can not ensure to not return the same value more than once)
      • PaginatedSpliterator

        public PaginatedSpliterator​(Function<T,​List<T>> _pageSupplier,
                                    long _total)
        Constructor receiving the _pageSupplier using _total as estimated total.
        Parameters:
        _pageSupplier - page supplier (must return an ordered results otherwise can not ensure to not return the same value more than once)
        _total - estimated total