169 hasNext = fillBuffer();
170 }
171 return hasNext;
172 }
173 }
174
175 /**
176 * Invokes the shape-specific constructor with the provided arguments
177 * and returns the result.
178 */
179 abstract AbstractWrappingSpliterator<P_IN, P_OUT, ?> wrap(Spliterator<P_IN> s);
180
181 /**
182 * Initializes buffer, sink chain, and pusher for a shape-specific
183 * implementation.
184 */
185 abstract void initPartialTraversalState();
186
187 @Override
188 public Spliterator<P_OUT> trySplit() {
189 if (isParallel && !finished) {
190 init();
191
192 Spliterator<P_IN> split = spliterator.trySplit();
193 return (split == null) ? null : wrap(split);
194 }
195 else
196 return null;
197 }
198
199 /**
200 * If the buffer is empty, push elements into the sink chain until
201 * the source is empty or cancellation is requested.
202 * @return whether there are elements to consume from the buffer
203 */
204 private boolean fillBuffer() {
205 while (buffer.count() == 0) {
206 if (bufferSink.cancellationRequested() || !pusher.getAsBoolean()) {
207 if (finished)
208 return false;
209 else {
|
169 hasNext = fillBuffer();
170 }
171 return hasNext;
172 }
173 }
174
175 /**
176 * Invokes the shape-specific constructor with the provided arguments
177 * and returns the result.
178 */
179 abstract AbstractWrappingSpliterator<P_IN, P_OUT, ?> wrap(Spliterator<P_IN> s);
180
181 /**
182 * Initializes buffer, sink chain, and pusher for a shape-specific
183 * implementation.
184 */
185 abstract void initPartialTraversalState();
186
187 @Override
188 public Spliterator<P_OUT> trySplit() {
189 if (isParallel && buffer == null && !finished) {
190 init();
191
192 Spliterator<P_IN> split = spliterator.trySplit();
193 return (split == null) ? null : wrap(split);
194 }
195 else
196 return null;
197 }
198
199 /**
200 * If the buffer is empty, push elements into the sink chain until
201 * the source is empty or cancellation is requested.
202 * @return whether there are elements to consume from the buffer
203 */
204 private boolean fillBuffer() {
205 while (buffer.count() == 0) {
206 if (bufferSink.cancellationRequested() || !pusher.getAsBoolean()) {
207 if (finished)
208 return false;
209 else {
|