< prev index next >

src/java.base/share/classes/java/util/ArrayDeque.java

Print this page
8197531: Miscellaneous changes imported from jsr166 CVS 2018-04
Reviewed-by: martin, psandoz

@@ -206,11 +206,11 @@
      * @param c the collection whose elements are to be placed into the deque
      * @throws NullPointerException if the specified collection is null
      */
     public ArrayDeque(Collection<? extends E> c) {
         this(c.size());
-        addAll(c);
+        copyElements(c);
     }
 
     /**
      * Circularly increments i, mod modulus.
      * Precondition and postcondition: 0 <= i < modulus.

@@ -320,14 +320,18 @@
      */
     public boolean addAll(Collection<? extends E> c) {
         final int s, needed;
         if ((needed = (s = size()) + c.size() + 1 - elements.length) > 0)
             grow(needed);
-        c.forEach(this::addLast);
+        copyElements(c);
         return size() > s;
     }
 
+    private void copyElements(Collection<? extends E> c) {
+        c.forEach(this::addLast);
+    }
+
     /**
      * Inserts the specified element at the front of this deque.
      *
      * @param e the element to add
      * @return {@code true} (as specified by {@link Deque#offerFirst})
< prev index next >