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.78 by jsr166, Tue Oct 18 17:31:18 2016 UTC vs.
Revision 1.79 by jsr166, Tue Oct 18 20:32:55 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       */
138 <    public void ensureCapacity(int minCapacity) {
138 >    /* TODO: public */ private void ensureCapacity(int minCapacity) {
139          if (minCapacity > elements.length)
140              grow(minCapacity - elements.length);
141          // checkInvariants();
# Line 144 | Line 143 | public class ArrayDeque<E> extends Abstr
143  
144      /**
145       * Minimizes the internal storage of this collection.
147     *
148     * @since 9
146       */
147 <    public void trimToSize() {
147 >    /* TODO: public */ private void trimToSize() {
148          if (size < elements.length) {
149              elements = toArray();
150              head = 0;
# Line 196 | Line 193 | public class ArrayDeque<E> extends Abstr
193      }
194  
195      /**
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    /**
196       * Increments i, mod modulus.
197       * Precondition and postcondition: 0 <= i < modulus.
198       */
# Line 231 | Line 211 | public class ArrayDeque<E> extends Abstr
211      }
212  
213      /**
214 +     * Adds i and j, mod modulus.
215 +     * Precondition and postcondition: 0 <= i < modulus, 0 <= j <= modulus.
216 +     */
217 +    static final int add(int i, int j, int modulus) {
218 +        if ((i += j) - modulus >= 0) i -= modulus;
219 +        return i;
220 +    }
221 +
222 +    /**
223 +     * Returns the array index of the last element.
224 +     * May return invalid index -1 if there are no elements.
225 +     */
226 +    final int tail() {
227 +        return add(head, size - 1, elements.length);
228 +    }
229 +
230 +    /**
231       * Returns element at array index i.
232       */
233      @SuppressWarnings("unchecked")
# Line 305 | Line 302 | public class ArrayDeque<E> extends Abstr
302      public boolean addAll(Collection<? extends E> c) {
303          // checkInvariants();
304          Object[] a, elements;
305 <        int len, capacity, s = size;
306 <        if ((len = (a = c.toArray()).length) == 0)
305 >        int newcomers, capacity, s = size;
306 >        if ((newcomers = (a = c.toArray()).length) == 0)
307              return false;
308 <        while ((capacity = (elements = this.elements).length) - s < len)
309 <            grow(len - (capacity - s));
308 >        while ((capacity = (elements = this.elements).length) - s < newcomers)
309 >            grow(newcomers - (capacity - s));
310          int i = add(head, s, capacity);
311          for (Object x : a) {
312              Objects.requireNonNull(x);
# Line 845 | Line 842 | public class ArrayDeque<E> extends Abstr
842       * operator to that element, as specified by {@link List#replaceAll}.
843       *
844       * @param operator the operator to apply to each element
848     * @since 9
845       */
846 <    public void replaceAll(UnaryOperator<E> operator) {
846 >    /* TODO: public */ private void replaceAll(UnaryOperator<E> operator) {
847          Objects.requireNonNull(operator);
848          final Object[] elements = this.elements;
849          final int capacity = elements.length;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines