E - type of shared elementspublic class ShareableEnumerator<E> extends AbstractEnumerator<E>
Enumerator with support for element sharing.
Shareable enumerators encapsulate an Iterator and spawn sharing
Enumerator instances that can share the elements without the
original iterator being traversed more than once.
Shareable enumerators work in one of the following three modes:
Enumerator instancesEnumerator instances enumerate and share the elements
independently of each otherThe second mode must come after the first mode and both are mutually exclusive with the third.
The shared mode it triggered by calls to share() or
share(int). The shared enumerating mode begins when
one of the spawned sharing Enumerator instances starts enumerating.
The enumerating mode commences with calling AbstractEnumerator.hasNext() or
AbstractEnumerator.next().
The spawned Enumerator instances can traverse independently
the sequence of elements because ShareableEnumerator keeps a
transient internal buffer of elements, from the first in use to the last in
use. While the buffer allows for independent traversal of the same sequence,
the sharing Enumerator instances may not diverge too much without
danger of buffer overflow.
Enumerator,
SharingEnumerator| Constructor and Description |
|---|
ShareableEnumerator(Iterator<E> source)
Creates a
ShareableEnumerator instance that will share the
elements of the given source. |
| Modifier and Type | Method and Description |
|---|---|
ShareableEnumerator<E> |
asShareable()
Returns a
ShareableEnumerator sharing the elements of the
current enumerator. |
protected void |
cleanup()
Cleans up the internals of the current enumerator when enumeration
ends.
|
protected boolean |
internalHasNext()
Returns whether the enumerator has more elements.
|
protected E |
internalNext()
Returns the next enumerated element.
|
Enumerator<E> |
share()
Creates an
Enumerator instance that will share the
elements of the current enumerator. |
Enumerator<E>[] |
share(int count)
Creates an array of
Enumerator instances that will share
the elements of the current enumerator. |
(package private) void |
startSharedEnumeration()
Marks the shared enumeration state consisting in the
enumerators sharing this shareable enumerator starting their own
enumeration.
|
enumerating, hasNext, nextclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitallMatch, anyMatch, append, as, asEnumerable, asEnumeration, asFiltered, asOptional, asSpliterator, asStream, asSupplier, asTolerant, asTolerant, choiceOf, choiceOf, collect, concat, concat, concat, concat, concat, concat, concatOn, contains, count, distinct, elementAt, elementsEqual, empty, filter, first, flatMap, forEach, iterate, last, limit, limitWhile, map, map, max, min, noneMatch, of, of, of, of, of, of, of, ofLateBinding, ofLazyEnumeration, ofLazyIterable, ofLazyIterator, ofLazySpliterator, ofLazyStream, on, peek, prepend, prepend, prepend, prepend, prepend, prepend, prependOn, range, rangeClosed, rangeInt, rangeIntClosed, rangeLong, rangeLongClosed, reduce, reduce, repeat, repeatAll, repeatAll, repeatEach, reverse, single, skip, skipWhile, sorted, sorted, take, takeWhile, toArray, toList, toMap, toSet, union, union, union, union, union, union, unionOn, zipAll, zipAny, zipBoth, zipLeft, zipRightforEachRemaining, removepublic ShareableEnumerator(Iterator<E> source)
ShareableEnumerator instance that will share the
elements of the given source.source - Iterator to share.ShareableEnumeratorpublic ShareableEnumerator<E> asShareable()
EnumeratorShareableEnumerator sharing the elements of the
current enumerator.
A ShareableEnumerator can either enumerate the elements of the
current enumerator itself or it can produce a collection of
Enumerator instances that will share the elements of the
current iterator when enumerating independently of each other. The two
modes are mutually exclusive.
ShareableEnumerator.SharingEnumeratorprotected 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()public Enumerator<E> share()
Enumerator instance that will share the
elements of the current enumerator.Enumerator instance.share(int)public Enumerator<E>[] share(int count)
Enumerator instances that will share
the elements of the current enumerator.count - the number of Enumerator instances to create.Enumerator instances.IllegalArgumentException - count is negativeIllegalStateException - enumeration has startedshare()void startSharedEnumeration()
AbstractEnumerator.hasNext()Copyright © 2016. All rights reserved.