Biniman Idugboe wrote:Does it mean that StreamImpl{} will enclose the five operations and each of the non-terminal operations will in turn implement its own spliterator? As in the following?
Almost.
The
source_spliterator will be passed to the constructor of the stream on which the
filter() method is called; the
filter() method has access to the field that holds the spliterator.
The
filter_spliterator will be passed to the constructor of the stream on which the
map() method is called, the
map() method has access to the field that holds the spliterator.
The
map_spliterator will be passed to the constructor of the stream on which the
limit() method is called, the
limit() method has access to the field that holds the spliterator.
The
limit_spliterator will be used by the
max() method to create a result, because it's a terminal operation.
To set the ball rolling, I would need to do something like:
No.
StreamImpl has no
previousOperation field.
anotherStream.spliterator holds the spliterator that your call to
map() created, and
anotherStream.spliterator.previousOperation holds the spliterator that you created with your call to
new MappingSpliterator(spliterator).
anotherStream.spliterator.previousOperation.previousOperation holds the spliterator that you passed to the constructor of
MappingSpliterator. I think you confused yourself by constructing the
MappingSpliterator yourself, rather than letting a call to
map() do it. Then you created a second
MappingSpliterator by calling
map().
Also, this doesn't set the ball rolling, because you didn't call a terminal operation.
What will repeatedly invoke x_Spliterator.tryAdvance() so that all the elements in x_spliterator can be processed?
A terminal operation, like
forEach() or
reduce() or
max().