I - the inner type, i.e. the type of the elements returned by the wrapped/inner spliteratorO - the outer type, i.e. the type of elements returned by this spliteratorpublic final class TransformingSpliterator<I,O> extends Object
Spliterator which wraps another spliterator and transforms the returned elements from an inner type
I to an outer type O and vice versa.
The transformation of null elements of either inner or outer type is fixed to null -> null. The
transformation functions specified during construction do not have to handle null input elements and are not allowed
to produce a null result.
Note that this spliterator reports the exact same SORTED characteristic as the inner one. It's getComparator() transforms the elements it should compare from the
outer to the inner type and calls the inner spliterator's comparator with it.
This means that sorting streams is always done by the inner spliterator's logic.
Spliterator.OfDouble, Spliterator.OfInt, Spliterator.OfLong, Spliterator.OfPrimitive<T,T_CONS,T_SPLITR extends Spliterator.OfPrimitive<T,T_CONS,T_SPLITR>>CONCURRENT, DISTINCT, IMMUTABLE, NONNULL, ORDERED, SIZED, SORTED, SUBSIZED| Constructor and Description |
|---|
TransformingSpliterator(Spliterator<I> innerSpliterator,
Function<? super I,? extends O> transformToOuter,
Function<? super O,? extends I> transformToInner)
Creates a new transforming spliterator.
|
| Modifier and Type | Method and Description |
|---|---|
int |
characteristics() |
long |
estimateSize() |
void |
forEachRemaining(Consumer<? super O> action) |
Comparator<? super O> |
getComparator() |
long |
getExactSizeIfKnown() |
protected Spliterator<I> |
getInnerSpliterator() |
boolean |
hasCharacteristics(int characteristics) |
protected I |
transformToInner(O outerElement)
Transforms an element from the outer type
O to the inner type I. |
protected O |
transformToOuter(I innerElement)
Transforms an element from the inner type
I to the outer type O. |
boolean |
tryAdvance(Consumer<? super O> action) |
Spliterator<O> |
trySplit() |
protected Spliterator<O> |
wrapNewSpliterator(Spliterator<I> newSpliterator)
Wraps the specified spliterator over
I into a spliterator over O. |
public TransformingSpliterator(Spliterator<I> innerSpliterator, Function<? super I,? extends O> transformToOuter, Function<? super O,? extends I> transformToInner)
If the specified spliterator is used by any other instance, the behavior is undefined. The specified transform functions will not be called with null elements and are not allowed to return null.
innerSpliterator - the wrapped/inner spliteratortransformToOuter - transforms elements from the inner type I to the outer type OtransformToInner - transforms elements from the outer type O to the inner type Iprotected Spliterator<I> getInnerSpliterator()
protected O transformToOuter(I innerElement)
I to the outer type O.innerElement - an element returned by the innerSpliteratorOprotected I transformToInner(O outerElement)
O to the inner type I.outerElement - an element of type OIprotected Spliterator<O> wrapNewSpliterator(Spliterator<I> newSpliterator)
I into a spliterator over O.
This method is called inside trySplit(). It is not called with null.
newSpliterator - the newly created inner Spliterator<I>Spliterator<O>public boolean tryAdvance(Consumer<? super O> action)
tryAdvance in interface Spliterator<O>public void forEachRemaining(Consumer<? super O> action)
forEachRemaining in interface Spliterator<O>public Spliterator<O> trySplit()
trySplit in interface Spliterator<O>public long estimateSize()
estimateSize in interface Spliterator<O>public long getExactSizeIfKnown()
getExactSizeIfKnown in interface Spliterator<O>public int characteristics()
characteristics in interface Spliterator<O>public boolean hasCharacteristics(int characteristics)
hasCharacteristics in interface Spliterator<O>public Comparator<? super O> getComparator()
getComparator in interface Spliterator<O>This documentation is licensed under CC-BY 4.0, attributed to Nicolai Parlog from CodeFX.