src/java.base/share/classes/java/util/ArrayDeque.java
changeset 47307 6864969a78ad
parent 47216 71c04702a3d5
child 47423 4fc2a4a29f3d
equal deleted inserted replaced
47306:90b7465b9ac7 47307:6864969a78ad
   209         this(c.size());
   209         this(c.size());
   210         addAll(c);
   210         addAll(c);
   211     }
   211     }
   212 
   212 
   213     /**
   213     /**
   214      * Increments i, mod modulus.
   214      * Circularly increments i, mod modulus.
   215      * Precondition and postcondition: 0 <= i < modulus.
   215      * Precondition and postcondition: 0 <= i < modulus.
   216      */
   216      */
   217     static final int inc(int i, int modulus) {
   217     static final int inc(int i, int modulus) {
   218         if (++i >= modulus) i = 0;
   218         if (++i >= modulus) i = 0;
   219         return i;
   219         return i;
   220     }
   220     }
   221 
   221 
   222     /**
   222     /**
   223      * Decrements i, mod modulus.
   223      * Circularly decrements i, mod modulus.
   224      * Precondition and postcondition: 0 <= i < modulus.
   224      * Precondition and postcondition: 0 <= i < modulus.
   225      */
   225      */
   226     static final int dec(int i, int modulus) {
   226     static final int dec(int i, int modulus) {
   227         if (--i < 0) i = modulus - 1;
   227         if (--i < 0) i = modulus - 1;
   228         return i;
   228         return i;
   231     /**
   231     /**
   232      * Circularly adds the given distance to index i, mod modulus.
   232      * Circularly adds the given distance to index i, mod modulus.
   233      * Precondition: 0 <= i < modulus, 0 <= distance <= modulus.
   233      * Precondition: 0 <= i < modulus, 0 <= distance <= modulus.
   234      * @return index 0 <= i < modulus
   234      * @return index 0 <= i < modulus
   235      */
   235      */
   236     static final int add(int i, int distance, int modulus) {
   236     static final int inc(int i, int distance, int modulus) {
   237         if ((i += distance) - modulus >= 0) i -= modulus;
   237         if ((i += distance) - modulus >= 0) i -= modulus;
   238         return i;
   238         return i;
   239     }
   239     }
   240 
   240 
   241     /**
   241     /**
   823         public DeqSpliterator trySplit() {
   823         public DeqSpliterator trySplit() {
   824             final Object[] es = elements;
   824             final Object[] es = elements;
   825             final int i, n;
   825             final int i, n;
   826             return ((n = sub(getFence(), i = cursor, es.length) >> 1) <= 0)
   826             return ((n = sub(getFence(), i = cursor, es.length) >> 1) <= 0)
   827                 ? null
   827                 ? null
   828                 : new DeqSpliterator(i, cursor = add(i, n, es.length));
   828                 : new DeqSpliterator(i, cursor = inc(i, n, es.length));
   829         }
   829         }
   830 
   830 
   831         public void forEachRemaining(Consumer<? super E> action) {
   831         public void forEachRemaining(Consumer<? super E> action) {
   832             if (action == null)
   832             if (action == null)
   833                 throw new NullPointerException();
   833                 throw new NullPointerException();