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.77 by jsr166, Tue Oct 18 00:33:05 2016 UTC vs.
Revision 1.80 by jsr166, Thu Oct 20 01:43:31 2016 UTC

# Line 134 | Line 134 | public class ArrayDeque<E> extends Abstr
134       * to ensure that it can hold at least the given number of elements.
135       *
136       * @param minCapacity the desired minimum capacity
137 <     * @since 9
137 >     * @since TBD
138       */
139 <    public void ensureCapacity(int minCapacity) {
139 >    /* public */ void ensureCapacity(int minCapacity) {
140          if (minCapacity > elements.length)
141              grow(minCapacity - elements.length);
142          // checkInvariants();
# Line 145 | Line 145 | public class ArrayDeque<E> extends Abstr
145      /**
146       * Minimizes the internal storage of this collection.
147       *
148 <     * @since 9
148 >     * @since TBD
149       */
150 <    public void trimToSize() {
150 >    /* public */ void trimToSize() {
151          if (size < elements.length) {
152              elements = toArray();
153              head = 0;
# Line 196 | Line 196 | public class ArrayDeque<E> extends Abstr
196      }
197  
198      /**
199     * Returns the array index of the last element.
200     * May return invalid index -1 if there are no elements.
201     */
202    final int tail() {
203        return add(head, size - 1, elements.length);
204    }
205
206    /**
207     * Adds i and j, mod modulus.
208     * Precondition and postcondition: 0 <= i < modulus, 0 <= j <= modulus.
209     */
210    static final int add(int i, int j, int modulus) {
211        if ((i += j) - modulus >= 0) i -= modulus;
212        return i;
213    }
214
215    /**
199       * Increments i, mod modulus.
200       * Precondition and postcondition: 0 <= i < modulus.
201       */
# Line 231 | Line 214 | public class ArrayDeque<E> extends Abstr
214      }
215  
216      /**
217 +     * Adds i and j, mod modulus.
218 +     * Precondition and postcondition: 0 <= i < modulus, 0 <= j <= modulus.
219 +     */
220 +    static final int add(int i, int j, int modulus) {
221 +        if ((i += j) - modulus >= 0) i -= modulus;
222 +        return i;
223 +    }
224 +
225 +    /**
226 +     * Returns the array index of the last element.
227 +     * May return invalid index -1 if there are no elements.
228 +     */
229 +    final int tail() {
230 +        return add(head, size - 1, elements.length);
231 +    }
232 +
233 +    /**
234       * Returns element at array index i.
235       */
236      @SuppressWarnings("unchecked")
# Line 305 | Line 305 | public class ArrayDeque<E> extends Abstr
305      public boolean addAll(Collection<? extends E> c) {
306          // checkInvariants();
307          Object[] a, elements;
308 <        int len, capacity, s = size;
309 <        if ((len = (a = c.toArray()).length) == 0)
308 >        int newcomers, capacity, s = size;
309 >        if ((newcomers = (a = c.toArray()).length) == 0)
310              return false;
311 <        while ((capacity = (elements = this.elements).length) - s < len)
312 <            grow(len - (capacity - s));
311 >        while ((capacity = (elements = this.elements).length) - s < newcomers)
312 >            grow(newcomers - (capacity - s));
313          int i = add(head, s, capacity);
314          for (Object x : a) {
315              Objects.requireNonNull(x);
# Line 845 | Line 845 | public class ArrayDeque<E> extends Abstr
845       * operator to that element, as specified by {@link List#replaceAll}.
846       *
847       * @param operator the operator to apply to each element
848 <     * @since 9
848 >     * @since TBD
849       */
850 <    public void replaceAll(UnaryOperator<E> operator) {
850 >    /* public */ void replaceAll(UnaryOperator<E> operator) {
851          Objects.requireNonNull(operator);
852          final Object[] elements = this.elements;
853          final int capacity = elements.length;
# Line 902 | Line 902 | public class ArrayDeque<E> extends Abstr
902              }
903              return deleted > 0;
904          } catch (Throwable ex) {
905 <            for (; remaining > 0;
906 <                 remaining--, i = inc(i, capacity), j = inc(j, capacity))
907 <                elements[j] = elements[i];
905 >            if (deleted > 0)
906 >                for (; remaining > 0;
907 >                     remaining--, i = inc(i, capacity), j = inc(j, capacity))
908 >                    elements[j] = elements[i];
909              throw ex;
910          } finally {
911              size -= deleted;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines