ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/ArrayDeque.java
(Generate patch)

Comparing jsr166/src/main/java/util/ArrayDeque.java (file contents):
Revision 1.65 by jsr166, Sat Feb 28 20:35:47 2015 UTC vs.
Revision 1.70 by jsr166, Sat Sep 19 19:53:11 2015 UTC

# Line 109 | Line 109 | public class ArrayDeque<E> extends Abstr
109              initialCapacity |= (initialCapacity >>> 16);
110              initialCapacity++;
111  
112 <            if (initialCapacity < 0)   // Too many elements, must back off
113 <                initialCapacity >>>= 1;// Good luck allocating 2 ^ 30 elements
112 >            if (initialCapacity < 0)    // Too many elements, must back off
113 >                initialCapacity >>>= 1; // Good luck allocating 2^30 elements
114          }
115          elements = new Object[initialCapacity];
116      }
# Line 247 | Line 247 | public class ArrayDeque<E> extends Abstr
247      }
248  
249      public E pollFirst() {
250 <        int h = head;
250 >        final Object[] elements = this.elements;
251 >        final int h = head;
252          @SuppressWarnings("unchecked")
253          E result = (E) elements[h];
254          // Element is null if deque empty
# Line 259 | Line 260 | public class ArrayDeque<E> extends Abstr
260      }
261  
262      public E pollLast() {
263 <        int t = (tail - 1) & (elements.length - 1);
263 >        final Object[] elements = this.elements;
264 >        final int t = (tail - 1) & (elements.length - 1);
265          @SuppressWarnings("unchecked")
266          E result = (E) elements[t];
267          if (result != null) {
# Line 606 | Line 608 | public class ArrayDeque<E> extends Abstr
608              }
609              lastRet = -1;
610          }
611 +
612 +        public void forEachRemaining(Consumer<? super E> action) {
613 +            Objects.requireNonNull(action);
614 +            Object[] a = elements;
615 +            int m = a.length - 1, f = fence, i = cursor;
616 +            cursor = f;
617 +            while (i != f) {
618 +                @SuppressWarnings("unchecked") E e = (E)a[i];
619 +                i = (i + 1) & m;
620 +                if (e == null)
621 +                    throw new ConcurrentModificationException();
622 +                action.accept(e);
623 +            }
624 +        }
625      }
626  
627      /**
# Line 845 | Line 861 | public class ArrayDeque<E> extends Abstr
861              elements[i] = s.readObject();
862      }
863  
864 +    /**
865 +     * Creates a <em><a href="Spliterator.html#binding">late-binding</a></em>
866 +     * and <em>fail-fast</em> {@link Spliterator} over the elements in this
867 +     * deque.
868 +     *
869 +     * <p>The {@code Spliterator} reports {@link Spliterator#SIZED},
870 +     * {@link Spliterator#SUBSIZED}, {@link Spliterator#ORDERED}, and
871 +     * {@link Spliterator#NONNULL}.  Overriding implementations should document
872 +     * the reporting of additional characteristic values.
873 +     *
874 +     * @return a {@code Spliterator} over the elements in this deque
875 +     * @since 1.8
876 +     */
877      public Spliterator<E> spliterator() {
878 <        return new DeqSpliterator<E>(this, -1, -1);
878 >        return new DeqSpliterator<>(this, -1, -1);
879      }
880  
881      static final class DeqSpliterator<E> implements Spliterator<E> {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines