Class PaginatedSpliterator<T>
- java.lang.Object
-
- org.bytemechanics.commons.functional.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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface java.util.Spliterator
Spliterator.OfDouble, Spliterator.OfInt, Spliterator.OfLong, Spliterator.OfPrimitive<T extends Object,T_CONS extends Object,T_SPLITR extends Spliterator.OfPrimitive<T,T_CONS,T_SPLITR>>
-
-
Field Summary
Fields Modifier and Type Field Description protected Deque<T>
buffer
static long
DEFAULT_ESTIMATED_TOTAL
protected T
from
-
Fields inherited from interface java.util.Spliterator
CONCURRENT, DISTINCT, IMMUTABLE, NONNULL, ORDERED, SIZED, SORTED, SUBSIZED
-
-
Constructor Summary
Constructors Constructor Description PaginatedSpliterator(Function<T,List<T>> _pageSupplier)
Constructor receiving the _pageSupplier using DEFAULT_ESTIMATED_TOTAL as estimated total.PaginatedSpliterator(Function<T,List<T>> _pageSupplier, long _total)
Constructor receiving the _pageSupplier using _total as estimated total.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
characteristics()
The spliterator characteristics by definition were: ORDERED, NONNULL, IMMUTABLE and CONCURRENTlong
estimateSize()
protected Queue<T>
getBuffer()
Return the current buffer from the last page suppliedboolean
tryAdvance(Consumer<? super T> _action)
Spliterator<T>
trySplit()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Spliterator
forEachRemaining, getComparator, getExactSizeIfKnown, hasCharacteristics
-
-
-
-
Field Detail
-
DEFAULT_ESTIMATED_TOTAL
public static final long DEFAULT_ESTIMATED_TOTAL
- See Also:
- Constant Field Values
-
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
-
-
Method Detail
-
getBuffer
protected Queue<T> getBuffer()
Return the current buffer from the last page supplied- Returns:
- Queue with the buffer content
-
tryAdvance
public boolean tryAdvance(Consumer<? super T> _action)
- Specified by:
tryAdvance
in interfaceSpliterator<T>
- See Also:
Spliterator.tryAdvance(java.util.function.Consumer)
-
trySplit
public Spliterator<T> trySplit()
- Specified by:
trySplit
in interfaceSpliterator<T>
- See Also:
Spliterator.trySplit()
-
estimateSize
public long estimateSize()
- Specified by:
estimateSize
in interfaceSpliterator<T>
- See Also:
Spliterator.estimateSize()
-
characteristics
public int characteristics()
The spliterator characteristics by definition were: ORDERED, NONNULL, IMMUTABLE and CONCURRENT- Specified by:
characteristics
in interfaceSpliterator<T>
- See Also:
Spliterator.characteristics()
-
-