The javadoc Spliterator mentions that:
The delimiter can move through individual elements (tryAdvance ()) or sequentially in bulk (forEachRemaining ()).
Then go to javadoc tryAdvance() , which states that:
If the remaining element exists, it performs the specified action on it, returning true; else returns false.
Perhaps I am reading something incorrectly, but for me it seems that provided that one or more elements remaining, Consumer should use only each .accept() argument as an argument before returning true , and if if, say, I have two arguments that are available immediately, and then I cannot:
action.accept(arg1); action.accept(arg2); return true;
In this project , I rewrote the width of the first separator so that it now reads:
// deque is a Deque<Iterator<T>> @Override public boolean tryAdvance(final Consumer<? super T> action) { Iterator<T> iterator; T element; while (!deque.isEmpty()) { iterator = deque.removeFirst(); while (iterator.hasNext()) { element = iterator.next(); deque.add(fn.apply(element)); action.accept(element); } } return false; }
In short, I am doing an action to accept all arguments, and then return false ... and the test, although fairly simple, still succeeds ( link ).
Note that .trySplit() always returns null ; and the delimiter has chacacteristics DISTINCT , ORDERED and NONNULL .
So, is there a use of a thread in which the code above will not work due to the above method, which consumes all the elements at the same time?