Java Reference
In-Depth Information
@Override
public long estimateSize() {
return 0;
}
@Override
public int characteristics() {
return 0;
}
}
In this listing a Spliterator is implemented, not to define the policy of how to split a stream but
only to use its late-binding capability. For this reason the trySplit method is unimplemented.
Also, it's impossible to return any meaningful value from the estimatedSize method because you
can't foresee how many elements can be still taken from the queue. Further, because you're not
attempting any split, this estimation will be useless. This implementation doesn't have any of
the Spliterator characteristics we listed in table 7.2 , so the characteristic method returns 0.
The only method implemented here is tryAdvance, which waits to take from its BlockingQueue
the elements of the original stream added to it by the ForkingStreamConsumer. It sends those
elements to a Consumer that (based on how this Spliterator was created in the
getOperationResult method) is the source of a further stream (on which the corresponding
function, passed to one of the fork method invocations, has to be applied). The tryAdvance
method returns true, to notify its invoker that there are other elements to be consumed, until it
finds on the queue the special Object added by ForkingStreamConsumer to signal that there are
no more elements to be taken from the queue. Figure C.2 shows an overview of the
StreamForker and its building blocks.
 
Search WWH ::




Custom Search