E - type of enumerated elements.class PipeEnumerator<E> extends AbstractEnumerator<E>
Important: this class is not final for testing
purposes.
Enumerator,
AbstractEnumerator| Constructor and Description |
|---|
PipeEnumerator()
Creates a new
PipeEnumerator instance with an empty internal
pipeline. |
PipeEnumerator(Enumerator<E> source)
Creates a new
PipeEnumerator instance based on the given
source Enumerator. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
cleanup()
Cleans up the internals of the current enumerator when enumeration
ends.
|
Enumerator<E> |
concat(Iterator<? extends E> elements)
Concatenates the current enumerator with the provided
Iterator. |
protected AbstractPipeProcessor |
dequeueProcessor()
Removes the element in front of
pipeline and returns the new
head of pipeline. |
protected void |
dequeueSourceProcessors(PipeSource removed)
Removes the processors of the given
PipeSource from
the pipeline. |
protected void |
dequeueSourcesUpToProcessor(AbstractPipeProcessor processor)
Removes the front elements of
sources until the given
AbstractPipeProcessor becomes first in pipeline. |
protected void |
dequeueSourceWithProcessors()
Removes the first source in
sources. |
protected Enumerator<E> |
enqueueFilterProcessor(Predicate<? super E> filter)
Enqueues the given filter by aggregating it with the last predicates,
if possible.
|
protected <X> Enumerator<X> |
enqueueMapProcessor(Function<? super E,? extends X> mapper)
Enqueues the given mapper by aggregating it with the last mappers,
if possible.
|
protected <X> Enumerator<X> |
enqueueProcessor(AbstractPipeMultiProcessor<? super E,? extends X> processor)
Adds the given
processor to the back of the multi-pipeline. |
protected <X> Enumerator<X> |
enqueueProcessor(AbstractPipeProcessor<? super E,? extends X> processor)
Adds the given
processor to the back of the pipeline. |
Enumerator<E> |
filter(Predicate<? super E> predicate)
Returns an enumerator consisting of the elements of the current
enumerator that match the provided predicate.
|
<R> Enumerator<R> |
flatMap(Function<? super E,? extends Iterator<? extends R>> mapper)
Returns an enumerator consisting of the results of replacing each
enumerated element with the content of a mapped enumerator obtained
by applying the provided mapper on each enumerated element.
|
protected boolean |
internalHasNext()
Returns whether the enumerator has more elements.
|
protected E |
internalNext()
Returns the next enumerated element.
|
Enumerator<E> |
limit(long maxSize)
Returns the current enumerator truncated to the given size.
|
<X> Enumerator<X> |
map(Function<? super E,? extends X> mapper)
Returns an enumerator consisting of the results of applying the given
function on the enumerated elements.
|
protected <X> void |
multiPipelineAddFirst(AbstractPipeMultiProcessor<? super X,?> processor)
Adds the given
processor to the beginning of
multiPipeline. |
protected <X> void |
multiPipelineAddLast(AbstractPipeMultiProcessor<? super E,? extends X> processor)
Adds the given
processor to the end of multiPipeLine. |
static <T> PipeEnumerator<T> |
of(Iterator<T> source)
Creates a
PipeEnumerator based on the given source
Iterator. |
Enumerator<E> |
prepend(Iterator<? extends E> elements)
Prepends the current enumerator with the provided
Iterator. |
protected PipeEnumerator<E> |
pushFrontFilterProcessor(Predicate<?> filter)
Prepends the given filter to the existing pipeline by aggregating it with
the first filters, if possible.
|
protected <X> PipeEnumerator<E> |
pushFrontMapProcessor(Function<? super X,?> mapper)
Prepends the given mapper to the existing pipeline by aggregating it with
the first mappers, if possible.
|
protected <X> PipeEnumerator<E> |
pushFrontProcessor(AbstractPipeMultiProcessor<? super X,?> processor)
Adds the given
processor to the front of the multi-pipeline. |
protected <X> PipeEnumerator<E> |
pushFrontProcessor(AbstractPipeProcessor<? super X,?> processor)
Adds the given
processor to the front of the pipeline. |
PipeEnumerator<E> |
reversedConcat(Iterator<?> elements)
Prepends the given
elements at the front of sources. |
PipeEnumerator<E> |
reversedFilter(Predicate<?> predicate)
Adds a filter processor at the front of the
pipeline. |
PipeEnumerator<E> |
reversedFlatMap(Function<?,? extends Iterator<?>> mapper)
Adds a flat-map processor at the front of
pipeline. |
Enumerator<E> |
reversedLimit(long maxSize)
Adds a limit processor at the front of
pipeline. |
<X> PipeEnumerator<E> |
reversedMap(Function<? super X,?> mapper)
Adds a map processor at the front of
pipeline. |
Enumerator<E> |
reversedSkip(long n)
Adds a skip processor at the front of
pipeline. |
PipeEnumerator<E> |
reversedSkipWhile(Predicate<?> predicate)
Adds a skip-while processor at the front of
pipeline. |
PipeEnumerator<E> |
reversedTakeWhile(Predicate<?> predicate)
Adds a take-while processor at the front of
pipeline. |
PipeEnumerator<E> |
reversedZipAll(Iterator<?> first,
List<Iterator<?>> rest)
Adds a zip-all processor at the front of
pipeline. |
protected <X> void |
safePipelineAddFirst(AbstractPipeProcessor<? super X,?> processor)
Adds the given
processor at the front of pipeline. |
protected <X> void |
safePipelineAddLast(AbstractPipeProcessor<? super E,? extends X> processor)
Adds the given
processor to the end of pipeline. |
PipeEnumerator<E> |
setSource(Iterator<?> elements)
Sets the source of enumeration.
|
Enumerator<E> |
skip(long n)
Returns the current enumerator with the given number of front elements
dropped.
|
Enumerator<E> |
skipWhile(Predicate<? super E> predicate)
Returns the current enumerator with front elements dropped as long as
they match a given predicate.
|
protected boolean |
straightHasNext()
Gets whether there are elements in one of the
sources. |
Enumerator<E> |
takeWhile(Predicate<? super E> predicate)
Returns an enumerator enumerating over the elements of the current
enumerator while stopping at the first element that does not match
the provided predicate.
|
protected boolean |
tryGetNext()
Tries to get the next value.
|
protected boolean |
tryPipelineIn(Out<Object> in,
Out<AbstractPipeProcessor> processor)
Tries to obtain obtain an input value for the pipeline.
|
protected boolean |
tryPipelineOut(Object in,
AbstractPipeProcessor processor,
Out<Boolean> nextOnSameSourceOnNoValue)
Tries to process the given
in value through the pipeline
and produce an output in value. |
Enumerator<Optional<E>[]> |
zipAll(Iterator<? extends E> first,
Iterator<? extends E>... rest)
Returns an enumerator consisting of an array of
Optional
objects containing elements from the current enumerator and
the given Iterator instances, while any has elements. |
Enumerator<Optional<E>[]> |
zipAll(Iterator<E> first,
List<Iterator<E>> rest)
Zips the elements of the
first Iterator with the
elements of the rest of iterators. |
enumerating, hasNext, nextclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitallMatch, anyMatch, append, as, asEnumerable, asEnumeration, asFiltered, asOptional, asShareable, asSpliterator, asStream, asSupplier, asTolerant, asTolerant, choiceOf, choiceOf, collect, concat, concat, concat, concat, concat, concatOn, contains, count, distinct, elementAt, elementsEqual, empty, first, forEach, iterate, last, limitWhile, map, max, min, noneMatch, of, of, of, of, of, of, of, ofLateBinding, ofLazyEnumeration, ofLazyIterable, ofLazyIterator, ofLazySpliterator, ofLazyStream, on, peek, prepend, prepend, prepend, prepend, prepend, prependOn, range, rangeClosed, rangeInt, rangeIntClosed, rangeLong, rangeLongClosed, reduce, reduce, repeat, repeatAll, repeatAll, repeatEach, reverse, single, sorted, sorted, take, toArray, toList, toMap, toSet, union, union, union, union, union, union, unionOn, zipAny, zipBoth, zipLeft, zipRightforEachRemaining, removepublic PipeEnumerator(Enumerator<E> source)
PipeEnumerator instance based on the given
source Enumerator.source - Enumerator providing the elements that the
pipeline works upon.public PipeEnumerator()
PipeEnumerator instance with an empty internal
pipeline.public static <T> PipeEnumerator<T> of(Iterator<T> source)
PipeEnumerator based on the given source
Iterator.
If source is already a PipeEnumerator then this function
returns it unchanged.
T - type of enumerated elements.source - Iterator to get elements from.PipeEnumerator.protected <X> Enumerator<X> enqueueProcessor(AbstractPipeProcessor<? super E,? extends X> processor)
processor to the back of the pipeline.
This method also maintains the consistency of
needValueForHasNext, AbstractPipeProcessor.next of
the last element in pipeline as well as
PipeSource.firstProcessor of the last element in
sources.
X - type of processed enumerated elements.processor - AbstractPipeProcessor to add.PipeEnumerator.protected <X> PipeEnumerator<E> pushFrontProcessor(AbstractPipeProcessor<? super X,?> processor)
processor to the front of the pipeline.
This method also maintains the consistency of
needValueForHasNext as well as
AbstractPipeProcessor.next of processor.
X - type of elements produced by processor.processor - AbstractPipeProcessor to add.PipeEnumerator.protected <X> Enumerator<X> enqueueProcessor(AbstractPipeMultiProcessor<? super E,? extends X> processor)
processor to the back of the multi-pipeline.
This method also maintains the consistency of
needValueForHasNext, AbstractPipeProcessor.next of
the last element in pipeline as well as
PipeSource.firstProcessor of the last element in
sources.
X - type of processed enumerated elements.processor - AbstractPipeMultiProcessor to add.PipeEnumerator.protected <X> PipeEnumerator<E> pushFrontProcessor(AbstractPipeMultiProcessor<? super X,?> processor)
processor to the front of the multi-pipeline.
This method also maintains the consistency of
needValueForHasNext as well as
AbstractPipeProcessor.next of processor.
X - type of elements produced by processor.processor - AbstractPipeMultiProcessor to add.PipeEnumerator.protected <X> Enumerator<X> enqueueMapProcessor(Function<? super E,? extends X> mapper)
X - type of mapped enumerated elements.mapper - mapping Function.Enumerator.protected <X> PipeEnumerator<E> pushFrontMapProcessor(Function<? super X,?> mapper)
X - type of enumerated elements to map.mapper - mapping Function.Enumerator.protected Enumerator<E> enqueueFilterProcessor(Predicate<? super E> filter)
filter - filtering Predicate.Enumerator.protected PipeEnumerator<E> pushFrontFilterProcessor(Predicate<?> filter)
filter - filtering Predicate.Enumerator.protected <X> void safePipelineAddLast(AbstractPipeProcessor<? super E,? extends X> processor)
processor to the end of pipeline.
This method allows fault-injection for testing purposes.
X - type of processed elements.processor - AbstractPipeProcessor to add.protected <X> void multiPipelineAddLast(AbstractPipeMultiProcessor<? super E,? extends X> processor)
processor to the end of multiPipeLine.
This method exists for testing purposes, to support fault injection.
X - type of processed elements.processor - AbstractPipeProcessor to add.protected <X> void safePipelineAddFirst(AbstractPipeProcessor<? super X,?> processor)
processor at the front of pipeline.X - type of processed elements.processor - AbstractPipeProcessor to add.protected <X> void multiPipelineAddFirst(AbstractPipeMultiProcessor<? super X,?> processor)
processor to the beginning of
multiPipeline.
This method exists for testing purposes, to support fault injection.
X - type of processed elements.processor - AbstractPipeMultiProcessor to add.protected void dequeueSourceWithProcessors()
sources.
This happens because the first source in sources has no more
elements. Removing the first source also involves removing the
AbstractPipeProcessor instances that were processing specifically
the elements of that source.
This method clears value.
protected void dequeueSourcesUpToProcessor(AbstractPipeProcessor processor)
sources until the given
AbstractPipeProcessor becomes first in pipeline.
This method keeps calling dequeueSourceWithProcessors()
until the condition is met.
processor - AbstractPipeProcessor to bring to the front
of sources.protected void dequeueSourceProcessors(PipeSource removed)
PipeSource from
the pipeline.removed - PipeSource that has just been removed and need
its processors to be removed as well.protected AbstractPipeProcessor dequeueProcessor()
pipeline and returns the new
head of pipeline.
This method removes the same element from the front of
multiPipeline if the removed element matches the head of
multiPipeline.
The method also maintains the consistency of
needValueForHasNext.
pipeline, if any.protected boolean tryPipelineIn(Out<Object> in, Out<AbstractPipeProcessor> processor)
protected boolean tryPipelineOut(Object in, AbstractPipeProcessor processor, Out<Boolean> nextOnSameSourceOnNoValue)
in value through the pipeline
and produce an output in value.in - input for the pipeline.processor - AbstractPipeProcessor instance in
pipeline to start processing from.nextOnSameSourceOnNoValue - Out boolean telling whether
to keep the same source on a failure to process the input or not.in value has been processed to the
end, false otherwise.protected boolean internalHasNext()
AbstractEnumerator
This method is the internal counterpart of AbstractEnumerator.hasNext().
internalHasNext in class AbstractEnumerator<E>AbstractEnumerator.next()protected E internalNext()
AbstractEnumerator
This method is the internal counterpart of AbstractEnumerator.hasNext()
internalNext in class AbstractEnumerator<E>protected void cleanup()
AbstractEnumeratorBy default this method does nothing.
cleanup in class AbstractEnumerator<E>AbstractEnumerator.hasNext(),
AbstractEnumerator.next(),
AbstractEnumerator.internalHasNext(),
AbstractEnumerator.internalNext()protected final boolean straightHasNext()
sources.
This method also discards the items in sources with no elements.
protected final boolean tryGetNext()
public Enumerator<E> concat(Iterator<? extends E> elements)
EnumeratorIterator.
This operation is highly composable.
elements - Iterator instance to concatenate withpublic Enumerator<E> filter(Predicate<? super E> predicate)
EnumeratorThis operation is highly composable.
predicate - state-less predicate to apply on each element.public <R> Enumerator<R> flatMap(Function<? super E,? extends Iterator<? extends R>> mapper)
EnumeratorThis operation is highly composable.
Example:
Enumerator.on(1, 2, 3)
.flatMap(i -> Enumerator.on(i*i, i*(i+1)))
will produce the sequence 1, 2, 4, 6, 9 and 12.
R - the element type of the new enumerator.mapper - Function instance to apply on each enumerated
element of the current enumerator.public <X> Enumerator<X> map(Function<? super E,? extends X> mapper)
EnumeratorThis operation is highly composable.
X - the element type of the new enumerator.mapper - state-less Function to apply on each enumerated
element.Enumerator.map(java.util.function.BiFunction)public Enumerator<E> limit(long maxSize)
Enumerator
This method works exactly like take(long).
This operation is highly composable.
maxSize - the maximum number of elements in the resulted
enumerator.public Enumerator<E> prepend(Iterator<? extends E> elements)
EnumeratorIterator.
This operation is highly composable.
elements - Iterator instance to prepend in front of the
current enumerator.public Enumerator<E> skip(long n)
EnumeratorThis operation is highly composable.
n - the number of front elements to drop.public Enumerator<E> takeWhile(Predicate<? super E> predicate)
Enumerator
this method works exactly like limitWhile(Predicate).
This operation is highly composable.
predicate - state-less Predicate instance to apply on
enumerated elements.public Enumerator<E> skipWhile(Predicate<? super E> predicate)
EnumeratorThis operation is highly composable.
predicate - Predicate instance to match the enumerated
elements against.public Enumerator<Optional<E>[]> zipAll(Iterator<? extends E> first, Iterator<? extends E>... rest)
EnumeratorOptional
objects containing elements from the current enumerator and
the given Iterator instances, while any has elements.
This operation is highly composable.
public Enumerator<Optional<E>[]> zipAll(Iterator<E> first, List<Iterator<E>> rest)
first Iterator with the
elements of the rest of iterators.first - first Iterator to zip.rest - rest of the Iterator instances to zip.Enumerator of zipped elements.public PipeEnumerator<E> setSource(Iterator<?> elements)
This method gets called when the PipeEnumerator gets constructed
in reverse order, during enumerator extraction from a
PipeEnumerable.
elements - Iterator to set as source.PipeEnumerator.public PipeEnumerator<E> reversedConcat(Iterator<?> elements)
elements at the front of sources.elements - Iterator to prepend.PipeEnumerator.public PipeEnumerator<E> reversedFilter(Predicate<?> predicate)
pipeline.predicate - condition to filter elements upon.PipeEnumerator.public PipeEnumerator<E> reversedFlatMap(Function<?,? extends Iterator<?>> mapper)
pipeline.mapper - Function mapping enumerated elements.PipeEnumerator.public <X> PipeEnumerator<E> reversedMap(Function<? super X,?> mapper)
pipeline.X - type of mapped elements.mapper - Function mapping enumerated elements.PipeEnumerator.public Enumerator<E> reversedLimit(long maxSize)
pipeline.maxSize - enumeration limit.PipeEnumerator.public Enumerator<E> reversedSkip(long n)
pipeline.n - number of elements to skip.PipeEnumerator.public PipeEnumerator<E> reversedTakeWhile(Predicate<?> predicate)
pipeline.predicate - condition to continue taking elements.PipeEnumerator.public PipeEnumerator<E> reversedSkipWhile(Predicate<?> predicate)
pipeline.predicate - condition to continue skipping elements.PipeEnumerator.public PipeEnumerator<E> reversedZipAll(Iterator<?> first, List<Iterator<?>> rest)
pipeline.first - Iterator to zip.rest - rest of Iterator instances to zip with.PipeEnumerator.Copyright © 2016. All rights reserved.