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 { 210 bufferSink.end(); // might trigger more elements 211 finished = true; | 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 if (buffer != null && buffer.count() > 0) // partial traversal started 193 return null; 194 Spliterator<P_IN> split = spliterator.trySplit(); 195 return (split == null) ? null : wrap(split); 196 } 197 else 198 return null; 199 } 200 201 /** 202 * If the buffer is empty, push elements into the sink chain until 203 * the source is empty or cancellation is requested. 204 * @return whether there are elements to consume from the buffer 205 */ 206 private boolean fillBuffer() { 207 while (buffer.count() == 0) { 208 if (bufferSink.cancellationRequested() || !pusher.getAsBoolean()) { 209 if (finished) 210 return false; 211 else { 212 bufferSink.end(); // might trigger more elements 213 finished = true; |