ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/ArrayList.java
(Generate patch)

Comparing jsr166/src/main/java/util/ArrayList.java (file contents):
Revision 1.3 by jsr166, Sat Nov 26 03:03:49 2005 UTC vs.
Revision 1.6 by jsr166, Sat Nov 26 04:35:16 2005 UTC

# Line 101 | Line 101 | public class ArrayList<E> extends Abstra
101      /**
102       * Constructs an empty list with the specified initial capacity.
103       *
104 <     * @param   initialCapacity   the initial capacity of the list
105 <     * @exception IllegalArgumentException if the specified initial capacity
106 <     *            is negative
104 >     * @param initialCapacity the initial capacity of the list
105 >     * @throws IllegalArgumentException if the specified initial capacity
106 >     *         is negative
107       */
108      public ArrayList(int initialCapacity) {
109          super();
# Line 146 | Line 146 | public class ArrayList<E> extends Abstra
146          }
147          initFromConcurrentlyMutating(c);
148      }
149 <    
149 >
150      private void initFromConcurrentlyMutating(Collection<? extends E> c) {
151          elementData = c.toArray();
152          size = elementData.length;
# Line 154 | Line 154 | public class ArrayList<E> extends Abstra
154          if (elementData.getClass() != Object[].class)
155              elementData = Arrays.copyOf(elementData, size, Object[].class);
156      }
157 <    
157 >
158      private final static Object UNALLOCATED = new Object();
159 <    
159 >
160      /**
161       * Trims the capacity of this <tt>ArrayList</tt> instance to be the
162       * list's current size.  An application can use this operation to minimize
# Line 175 | Line 175 | public class ArrayList<E> extends Abstra
175       * necessary, to ensure that it can hold at least the number of elements
176       * specified by the minimum capacity argument.
177       *
178 <     * @param   minCapacity   the desired minimum capacity
178 >     * @param minCapacity the desired minimum capacity
179       */
180      public void ensureCapacity(int minCapacity) {
181          modCount++;
# Line 184 | Line 184 | public class ArrayList<E> extends Abstra
184      }
185  
186      /**
187 <     * Increase the capacity of the array.
188 <     * @param   minCapacity   the desired minimum capacity
187 >     * Increases the capacity of the array.
188 >     *
189 >     * @param minCapacity the desired minimum capacity
190       */
191      private void growArray(int minCapacity) {
192          int oldCapacity = elementData.length;
193          // Double size if small; else grow by 50%
194 <        int newCapacity = ((oldCapacity < 64)?
194 >        int newCapacity = ((oldCapacity < 64)?
195                             (oldCapacity * 2):
196                             ((oldCapacity * 3)/2 + 1));
197          if (newCapacity < minCapacity)
# Line 341 | Line 342 | public class ArrayList<E> extends Abstra
342  
343      // Positional Access Operations
344  
345 <    /**
346 <     * Create and return an appropriate exception for indexing errors
345 >    /**
346 >     * Creates and returns an appropriate exception for indexing errors.
347       */
348      private static IndexOutOfBoundsException rangeException(int i, int s) {
349          return new IndexOutOfBoundsException("Index: " + i + ", Size: " + s);
350      }
351  
351    // Positional Access Operations
352
352      /**
353       * Returns the element at the specified position in this list.
354       *
# Line 436 | Line 435 | public class ArrayList<E> extends Abstra
435          Object oldValue = elementData[index];
436          int numMoved = s - index;
437          if (numMoved > 0)
438 <            System.arraycopy(elementData, index+1, elementData, index,
438 >            System.arraycopy(elementData, index+1, elementData, index,
439                               numMoved);
440          elementData[s] = null; // forget removed element
441          return (E)oldValue;
# Line 652 | Line 651 | public class ArrayList<E> extends Abstra
651              throw new IndexOutOfBoundsException("Index: "+index);
652          return new ArrayListIterator(index);
653      }
654 <
654 >
655      /**
656       * Returns an iterator over the elements in this list in proper sequence.
657       *
# Line 663 | Line 662 | public class ArrayList<E> extends Abstra
662      }
663  
664      /**
665 <     * A streamlined version of AbstractList.Itr
665 >     * A streamlined version of AbstractList.Itr
666       */
667      final class ArrayListIterator implements ListIterator<E> {
668          int cursor;           // index of next element to return;
# Line 701 | Line 700 | public class ArrayList<E> extends Abstra
700                          lastRet = i;
701                          cursor = i + 1;
702                          return e;
703 <                    } catch (IndexOutOfBoundsException fallthrough) {
703 >                    } catch (IndexOutOfBoundsException fallthrough) {
704                      }
705                  }
706              }
# Line 720 | Line 719 | public class ArrayList<E> extends Abstra
719                          lastRet = i;
720                          cursor = i;
721                          return e;
722 <                    } catch (IndexOutOfBoundsException fallthrough) {
722 >                    } catch (IndexOutOfBoundsException fallthrough) {
723                      }
724                  }
725              }
# Line 732 | Line 731 | public class ArrayList<E> extends Abstra
731          public void remove() {
732              if (lastRet < 0)
733                  throw new IllegalStateException();
734 <            if (modCount != expectedModCount)
734 >            if (modCount != expectedModCount)
735                  throw new ConcurrentModificationException();
736              ArrayList.this.remove(lastRet);
737              if (lastRet < cursor)
# Line 744 | Line 743 | public class ArrayList<E> extends Abstra
743          public void set(E e) {
744              if (lastRet < 0)
745                  throw new IllegalStateException();
746 <            if (modCount != expectedModCount)
746 >            if (modCount != expectedModCount)
747                  throw new ConcurrentModificationException();
748              ArrayList.this.set(lastRet, e);
749              expectedModCount = modCount;
750          }
751  
752          public void add(E e) {
753 <            if (modCount != expectedModCount)
753 >            if (modCount != expectedModCount)
754                  throw new ConcurrentModificationException();
755              ArrayList.this.add(cursor++, e);
756              lastRet = -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines