--- jsr166/src/main/java/util/ArrayDeque.java 2016/10/18 00:33:05 1.77 +++ jsr166/src/main/java/util/ArrayDeque.java 2016/10/20 01:43:31 1.80 @@ -134,9 +134,9 @@ public class ArrayDeque extends Abstr * to ensure that it can hold at least the given number of elements. * * @param minCapacity the desired minimum capacity - * @since 9 + * @since TBD */ - public void ensureCapacity(int minCapacity) { + /* public */ void ensureCapacity(int minCapacity) { if (minCapacity > elements.length) grow(minCapacity - elements.length); // checkInvariants(); @@ -145,9 +145,9 @@ public class ArrayDeque extends Abstr /** * Minimizes the internal storage of this collection. * - * @since 9 + * @since TBD */ - public void trimToSize() { + /* public */ void trimToSize() { if (size < elements.length) { elements = toArray(); head = 0; @@ -196,23 +196,6 @@ public class ArrayDeque extends Abstr } /** - * Returns the array index of the last element. - * May return invalid index -1 if there are no elements. - */ - final int tail() { - return add(head, size - 1, elements.length); - } - - /** - * Adds i and j, mod modulus. - * Precondition and postcondition: 0 <= i < modulus, 0 <= j <= modulus. - */ - static final int add(int i, int j, int modulus) { - if ((i += j) - modulus >= 0) i -= modulus; - return i; - } - - /** * Increments i, mod modulus. * Precondition and postcondition: 0 <= i < modulus. */ @@ -231,6 +214,23 @@ public class ArrayDeque extends Abstr } /** + * Adds i and j, mod modulus. + * Precondition and postcondition: 0 <= i < modulus, 0 <= j <= modulus. + */ + static final int add(int i, int j, int modulus) { + if ((i += j) - modulus >= 0) i -= modulus; + return i; + } + + /** + * Returns the array index of the last element. + * May return invalid index -1 if there are no elements. + */ + final int tail() { + return add(head, size - 1, elements.length); + } + + /** * Returns element at array index i. */ @SuppressWarnings("unchecked") @@ -305,11 +305,11 @@ public class ArrayDeque extends Abstr public boolean addAll(Collection c) { // checkInvariants(); Object[] a, elements; - int len, capacity, s = size; - if ((len = (a = c.toArray()).length) == 0) + int newcomers, capacity, s = size; + if ((newcomers = (a = c.toArray()).length) == 0) return false; - while ((capacity = (elements = this.elements).length) - s < len) - grow(len - (capacity - s)); + while ((capacity = (elements = this.elements).length) - s < newcomers) + grow(newcomers - (capacity - s)); int i = add(head, s, capacity); for (Object x : a) { Objects.requireNonNull(x); @@ -845,9 +845,9 @@ public class ArrayDeque extends Abstr * operator to that element, as specified by {@link List#replaceAll}. * * @param operator the operator to apply to each element - * @since 9 + * @since TBD */ - public void replaceAll(UnaryOperator operator) { + /* public */ void replaceAll(UnaryOperator operator) { Objects.requireNonNull(operator); final Object[] elements = this.elements; final int capacity = elements.length; @@ -902,9 +902,10 @@ public class ArrayDeque extends Abstr } return deleted > 0; } catch (Throwable ex) { - for (; remaining > 0; - remaining--, i = inc(i, capacity), j = inc(j, capacity)) - elements[j] = elements[i]; + if (deleted > 0) + for (; remaining > 0; + remaining--, i = inc(i, capacity), j = inc(j, capacity)) + elements[j] = elements[i]; throw ex; } finally { size -= deleted;