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

Comparing jsr166/src/main/java/util/concurrent/CopyOnWriteArrayList.java (file contents):
Revision 1.5 by brian, Mon Jun 23 02:26:16 2003 UTC vs.
Revision 1.6 by dl, Tue Jun 24 14:34:47 2003 UTC

# Line 28 | Line 28 | import java.util.*;
28   * to preclude interference among concurrent threads.  The iterator
29   * method uses a reference to the state of the array at the point that
30   * the iterator was created. This array never changes during the
31 < * lifetime of the iterator, so interference is impossible and the iterator
32 < * is guaranteed not to throw <tt>ConcurrentModificationException</tt>.  The
33 < * iterator will not reflect additions, removals, or changes to the List since the
34 < * iterator was created.
35 < * <p>
31 > * lifetime of the iterator, so interference is impossible and the
32 > * iterator is guaranteed not to throw
33 > * <tt>ConcurrentModificationException</tt>.  The iterator will not
34 > * reflect additions, removals, or changes to the List since the
35 > * iterator was created.  <p>
36   *
37   * Because of the copy-on-write policy, some one-by-one mutative
38   * operations in the java.util.Arrays and java.util.Collections
# Line 41 | Line 41 | import java.util.*;
41   * operations on iterators (remove, set, and add) are not
42   * supported. These are the only methods throwing
43   * UnsupportedOperationException.  <p>
44 < **/
44 > * @since 1.5
45 > * @author Doug Lea
46 > */
47   public class CopyOnWriteArrayList<E>
48          implements List<E>, RandomAccess, Cloneable, java.io.Serializable {
49  
50      /**
51 <     * The held array. Directly access only within synchronized
51 >     * The held array. Directly accessed only within synchronized
52       *  methods
53       */
54      private volatile transient E[] array_;
# Line 69 | Line 71 | public class CopyOnWriteArrayList<E>
71       * Constructs an list containing the elements of the specified
72       * Collection, in the order they are returned by the Collection's
73       * iterator.
74 +     * @param c the collection of initially held elements
75       */
76      public CopyOnWriteArrayList(Collection<E> c) {
77          array_ = new E[c.size()];
# Line 126 | Line 129 | public class CopyOnWriteArrayList<E>
129      /**
130       * Returns true if this list contains the specified element.
131       *
132 <     * @param o element whose presence in this List is to be tested.
132 >     * @param elem element whose presence in this List is to be tested.
133       */
134      public boolean contains(Object elem) {
135          E[] elementData = array();
# Line 295 | Line 298 | public class CopyOnWriteArrayList<E>
298       *            be stored, if it is big enough; otherwise, a new array of the
299       *            same runtime type is allocated for this purpose.
300       * @return an array containing the elements of the list.
301 <     * @exception ArrayStoreException the runtime type of a is not a supertype
301 >     * @throws ArrayStoreException the runtime type of a is not a supertype
302       * of the runtime type of every element in this list.
303       */
304      public <T> T[] toArray(T a[]) {
# Line 320 | Line 323 | public class CopyOnWriteArrayList<E>
323       * Returns the element at the specified position in this list.
324       *
325       * @param index index of element to return.
326 <     * @exception IndexOutOfBoundsException index is out of range (index
326 >     * @return the element
327 >     * @throws IndexOutOfBoundsException index is out of range (index
328       *              &lt; 0 || index &gt;= size()).
329       */
330      public E get(int index) {
# Line 336 | Line 340 | public class CopyOnWriteArrayList<E>
340       * @param index index of element to replace.
341       * @param element element to be stored at the specified position.
342       * @return the element previously at the specified position.
343 <     * @exception IndexOutOfBoundsException index out of range
343 >     * @throws IndexOutOfBoundsException index out of range
344       *              (index &lt; 0 || index &gt;= size()).
345       */
346      public synchronized E set(int index, E element) {
# Line 377 | Line 381 | public class CopyOnWriteArrayList<E>
381       *
382       * @param index index at which the specified element is to be inserted.
383       * @param element element to be inserted.
384 <     * @exception IndexOutOfBoundsException index is out of range
384 >     * @throws IndexOutOfBoundsException index is out of range
385       *              (index &lt; 0 || index &gt; size()).
386       */
387      public synchronized void add(int index, E element) {
# Line 397 | Line 401 | public class CopyOnWriteArrayList<E>
401       * Shifts any subsequent elements to the left (subtracts one from their
402       * indices).  Returns the element that was removed from the list.
403       *
404 <     * @exception IndexOutOfBoundsException index out of range (index
404 >     * @throws IndexOutOfBoundsException index out of range (index
405       *              &lt; 0 || index &gt;= size()).
406       * @param index the index of the element to removed.
407       */
# Line 468 | Line 472 | public class CopyOnWriteArrayList<E>
472       * toIndex==fromIndex, this operation has no effect.)
473       *
474       * @param fromIndex index of first element to be removed.
475 <     * @param fromIndex index after last element to be removed.
476 <     * @exception IndexOutOfBoundsException fromIndex or toIndex out of
475 >     * @param toIndex index after last element to be removed.
476 >     * @throws IndexOutOfBoundsException fromIndex or toIndex out of
477       *              range (fromIndex &lt; 0 || fromIndex &gt;= size() || toIndex
478       *              &gt; size() || toIndex &lt; fromIndex).
479       */
# Line 521 | Line 525 | public class CopyOnWriteArrayList<E>
525       * each element returned by the Iterator in turn to see if it's
526       * contained in this Collection.  If all elements are so contained
527       * true is returned, otherwise false.
528 <     *
528 >     * @param c the collection
529 >     * @return true if all elements are contained
530       */
531      public <T> boolean containsAll(Collection<T> c) {
532          E[] elementData = array();
533          int len = elementData.length;
534          Iterator<T> e = c.iterator();
535          while (e.hasNext())
536 <            if(indexOf(e.next(), elementData, len) < 0)
536 >            if (indexOf(e.next(), elementData, len) < 0)
537                  return false;
538  
539          return true;
# Line 541 | Line 546 | public class CopyOnWriteArrayList<E>
546       * in this class because of the need for an internal temporary array.
547       * <p>
548       *
549 +     * @param c the collection
550       * @return true if this Collection changed as a result of the call.
551       */
552      public synchronized <T> boolean removeAll(Collection<T> c) {
# Line 572 | Line 578 | public class CopyOnWriteArrayList<E>
578       * specified Collection (optional operation).  In other words, removes from
579       * this Collection all of its elements that are not contained in the
580       * specified Collection.
581 +     * @param c the collection
582       * @return true if this Collection changed as a result of the call.
583       */
584      public synchronized <T> boolean retainAll(Collection<T> c) {
# Line 647 | Line 654 | public class CopyOnWriteArrayList<E>
654       * specified Collection's Iterator.
655       *
656       * @param c elements to be inserted into this list.
657 +     * @return true if any elements are added
658       */
659      public synchronized <T extends E> boolean addAll(Collection<T> c) {
660          int numNew = c.size();
# Line 674 | Line 682 | public class CopyOnWriteArrayList<E>
682       * @param index index at which to insert first element
683       *                from the specified collection.
684       * @param c elements to be inserted into this list.
685 <     * @exception IndexOutOfBoundsException index out of range (index
685 >     * @throws IndexOutOfBoundsException index out of range (index
686       *              &lt; 0 || index &gt; size()).
687 +     * @return true if any elements are added
688       */
689      public synchronized <T extends E> boolean addAll(int index, Collection<T> c) {
690          int len = array_.length;
# Line 713 | Line 722 | public class CopyOnWriteArrayList<E>
722       * @serialData The length of the array backing the list is emitted
723       *               (int), followed by all of its elements (each an Object)
724       *               in the proper order.
725 +     * @param s the stream
726       */
727      private void writeObject(java.io.ObjectOutputStream s)
728          throws java.io.IOException{
# Line 731 | Line 741 | public class CopyOnWriteArrayList<E>
741  
742      /**
743       * Reconstitute the list from a stream (i.e., deserialize it).
744 +     * @param s the stream
745       */
746      private synchronized void readObject(java.io.ObjectInputStream s)
747          throws java.io.IOException, ClassNotFoundException {
# Line 861 | Line 872 | public class CopyOnWriteArrayList<E>
872       *
873       * @param index index of first element to be returned from the
874       *                ListIterator (by a call to getNext).
875 <     * @exception IndexOutOfBoundsException index is out of range
875 >     * @throws IndexOutOfBoundsException index is out of range
876       *              (index &lt; 0 || index &gt; size()).
877       */
878      public ListIterator<E> listIterator(final int index) {
# Line 923 | Line 934 | public class CopyOnWriteArrayList<E>
934  
935          /**
936           * Not supported. Always throws UnsupportedOperationException.
937 <         * @exception UnsupportedOperationException remove is not supported
937 >         * @throws UnsupportedOperationException remove is not supported
938           *            by this Iterator.
939           */
940  
# Line 933 | Line 944 | public class CopyOnWriteArrayList<E>
944  
945          /**
946           * Not supported. Always throws UnsupportedOperationException.
947 <         * @exception UnsupportedOperationException set is not supported
947 >         * @throws UnsupportedOperationException set is not supported
948           *            by this Iterator.
949           */
950          public void set(E o) {
# Line 942 | Line 953 | public class CopyOnWriteArrayList<E>
953  
954          /**
955           * Not supported. Always throws UnsupportedOperationException.
956 <         * @exception UnsupportedOperationException add is not supported
956 >         * @throws UnsupportedOperationException add is not supported
957           *            by this Iterator.
958           */
959          public void add(E o) {
# Line 965 | Line 976 | public class CopyOnWriteArrayList<E>
976       * a fashion that iterations in progress may yield incorrect results.)
977       *
978       * @param fromIndex low endpoint (inclusive) of the subList.
979 <     * @param toKey high endpoint (exclusive) of the subList.
979 >     * @param toIndex high endpoint (exclusive) of the subList.
980       * @return a view of the specified range within this List.
981 <     * @exception IndexOutOfBoundsException Illegal endpoint index value
981 >     * @throws IndexOutOfBoundsException Illegal endpoint index value
982       *     (fromIndex &lt; 0 || toIndex &gt; size || fromIndex &gt; toIndex).
983       */
984      public synchronized List<E> subList(int fromIndex, int toIndex) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines