< 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,216 ****
* @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);
}
/**
* Circularly increments i, mod modulus.
* Precondition and postcondition: 0 <= i < modulus.
--- 206,216 ----
* @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());
! copyElements(c);
}
/**
* Circularly increments i, mod modulus.
* Precondition and postcondition: 0 <= i < modulus.
*** 320,333 ****
*/
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);
return size() > s;
}
/**
* 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})
--- 320,337 ----
*/
public boolean addAll(Collection<? extends E> c) {
final int s, needed;
if ((needed = (s = size()) + c.size() + 1 - elements.length) > 0)
grow(needed);
! 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 >