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.129 by jsr166, Wed May 31 19:01:08 2017 UTC vs.
Revision 1.138 by jsr166, Fri Aug 30 18:05:38 2019 UTC

# Line 8 | Line 8 | package java.util;
8   import java.io.Serializable;
9   import java.util.function.Consumer;
10   import java.util.function.Predicate;
11 < import java.util.function.UnaryOperator;
11 > // OPENJDK import jdk.internal.access.SharedSecrets;
12  
13   /**
14   * Resizable-array implementation of the {@link Deque} interface.  Array
# Line 50 | Line 50 | import java.util.function.UnaryOperator;
50   * Iterator} interfaces.
51   *
52   * <p>This class is a member of the
53 < * <a href="{@docRoot}/java/util/package-summary.html#CollectionsFramework">
53 > * <a href="{@docRoot}/java.base/java/util/package-summary.html#CollectionsFramework">
54   * Java Collections Framework</a>.
55   *
56   * @author  Josh Bloch and Doug Lea
# Line 180 | Line 180 | public class ArrayDeque<E> extends Abstr
180       * sufficient to hold 16 elements.
181       */
182      public ArrayDeque() {
183 <        elements = new Object[16];
183 >        elements = new Object[16 + 1];
184      }
185  
186      /**
# Line 208 | Line 208 | public class ArrayDeque<E> extends Abstr
208       */
209      public ArrayDeque(Collection<? extends E> c) {
210          this(c.size());
211 <        addAll(c);
211 >        copyElements(c);
212      }
213  
214      /**
215 <     * Increments i, mod modulus.
215 >     * Circularly increments i, mod modulus.
216       * Precondition and postcondition: 0 <= i < modulus.
217       */
218      static final int inc(int i, int modulus) {
# Line 221 | Line 221 | public class ArrayDeque<E> extends Abstr
221      }
222  
223      /**
224 <     * Decrements i, mod modulus.
224 >     * Circularly decrements i, mod modulus.
225       * Precondition and postcondition: 0 <= i < modulus.
226       */
227      static final int dec(int i, int modulus) {
# Line 234 | Line 234 | public class ArrayDeque<E> extends Abstr
234       * Precondition: 0 <= i < modulus, 0 <= distance <= modulus.
235       * @return index 0 <= i < modulus
236       */
237 <    static final int add(int i, int distance, int modulus) {
237 >    static final int inc(int i, int distance, int modulus) {
238          if ((i += distance) - modulus >= 0) i -= modulus;
239          return i;
240      }
# Line 244 | Line 244 | public class ArrayDeque<E> extends Abstr
244       * Index i must be logically ahead of index j.
245       * Precondition: 0 <= i < modulus, 0 <= j < modulus.
246       * @return the "circular distance" from j to i; corner case i == j
247 <     * is diambiguated to "empty", returning 0.
247 >     * is disambiguated to "empty", returning 0.
248       */
249      static final int sub(int i, int j, int modulus) {
250          if ((i -= j) < 0) i += modulus;
# Line 324 | Line 324 | public class ArrayDeque<E> extends Abstr
324          final int s, needed;
325          if ((needed = (s = size()) + c.size() + 1 - elements.length) > 0)
326              grow(needed);
327 <        c.forEach(this::addLast);
327 >        copyElements(c);
328          // checkInvariants();
329          return size() > s;
330      }
331  
332 +    private void copyElements(Collection<? extends E> c) {
333 +        c.forEach(this::addLast);
334 +    }
335 +
336      /**
337       * Inserts the specified element at the front of this deque.
338       *
# Line 840 | Line 844 | public class ArrayDeque<E> extends Abstr
844              final int i, n;
845              return ((n = sub(getFence(), i = cursor, es.length) >> 1) <= 0)
846                  ? null
847 <                : new DeqSpliterator(i, cursor = add(i, n, es.length));
847 >                : new DeqSpliterator(i, cursor = inc(i, n, es.length));
848          }
849  
850          public void forEachRemaining(Consumer<? super E> action) {
# Line 912 | Line 916 | public class ArrayDeque<E> extends Abstr
916       * @param operator the operator to apply to each element
917       * @since TBD
918       */
919 <    /* public */ void replaceAll(UnaryOperator<E> operator) {
919 >    /* public */ void replaceAll(java.util.function.UnaryOperator<E> operator) {
920          Objects.requireNonNull(operator);
921          final Object[] es = elements;
922          for (int i = head, end = tail, to = (i <= end) ? end : es.length;
# Line 1194 | Line 1198 | public class ArrayDeque<E> extends Abstr
1198          }
1199      }
1200  
1201 +    // OPENJDK @java.io.Serial
1202      private static final long serialVersionUID = 2340985798034038923L;
1203  
1204      /**
# Line 1205 | Line 1210 | public class ArrayDeque<E> extends Abstr
1210       * followed by all of its elements (each an object reference) in
1211       * first-to-last order.
1212       */
1213 +    // OPENJDK @java.io.Serial
1214      private void writeObject(java.io.ObjectOutputStream s)
1215              throws java.io.IOException {
1216          s.defaultWriteObject();
# Line 1229 | Line 1235 | public class ArrayDeque<E> extends Abstr
1235       *         could not be found
1236       * @throws java.io.IOException if an I/O error occurs
1237       */
1238 +    // OPENJDK @java.io.Serial
1239      private void readObject(java.io.ObjectInputStream s)
1240              throws java.io.IOException, ClassNotFoundException {
1241          s.defaultReadObject();
1242  
1243          // Read in size and allocate array
1244          int size = s.readInt();
1245 +        jsr166.Platform.checkArray(s, Object[].class, size + 1);
1246          elements = new Object[size + 1];
1247          this.tail = size;
1248  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines