예제 #1
0
 public void forEachRemaining(Consumer<? super E> action) {
   Node<E> p;
   if (action == null) throw new NullPointerException();
   final ConcurrentLinkedQueue<E> q = this.queue;
   if (!exhausted && ((p = current) != null || (p = q.first()) != null)) {
     exhausted = true;
     do {
       E e = p.item;
       if (p == (p = p.next)) p = q.first();
       if (e != null) action.accept(e);
     } while (p != null);
   }
 }
예제 #2
0
 public boolean tryAdvance(Consumer<? super E> action) {
   Node<E> p;
   if (action == null) throw new NullPointerException();
   final ConcurrentLinkedQueue<E> q = this.queue;
   if (!exhausted && ((p = current) != null || (p = q.first()) != null)) {
     E e;
     do {
       e = p.item;
       if (p == (p = p.next)) p = q.first();
     } while (e == null && p != null);
     if ((current = p) == null) exhausted = true;
     if (e != null) {
       action.accept(e);
       return true;
     }
   }
   return false;
 }
예제 #3
0
 public Spliterator<E> trySplit() {
   Node<E> p;
   final ConcurrentLinkedQueue<E> q = this.queue;
   int b = batch;
   int n = (b <= 0) ? 1 : (b >= MAX_BATCH) ? MAX_BATCH : b + 1;
   if (!exhausted && ((p = current) != null || (p = q.first()) != null) && p.next != null) {
     Object[] a = new Object[n];
     int i = 0;
     do {
       if ((a[i] = p.item) != null) ++i;
       if (p == (p = p.next)) p = q.first();
     } while (p != null && i < n);
     if ((current = p) == null) exhausted = true;
     if (i > 0) {
       batch = i;
       return Spliterators.spliterator(
           a, 0, i, Spliterator.ORDERED | Spliterator.NONNULL | Spliterator.CONCURRENT);
     }
   }
   return null;
 }