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

Comparing jsr166/src/main/java/util/LinkedList.java (file contents):
Revision 1.22 by dl, Wed Mar 23 01:06:26 2005 UTC vs.
Revision 1.26 by jsr166, Mon May 2 08:35:49 2005 UTC

# Line 1 | Line 1
1   /*
2   * %W% %E%
3   *
4 < * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
4 > * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
5   * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6   */
7  
8 < package java.util;
8 > package java.util;
9  
10   /**
11   * Linked list implementation of the <tt>List</tt> interface.  Implements all
# Line 36 | Line 36 | package java.util;
36   * Collections.synchronizedList method.  This is best done at creation time,
37   * to prevent accidental unsynchronized access to the list: <pre>
38   *     List list = Collections.synchronizedList(new LinkedList(...));
39 < * </pre><p>
39 > * </pre>
40   *
41 < * The iterators returned by the this class's <tt>iterator</tt> and
41 > * <p>The iterators returned by this class's <tt>iterator</tt> and
42   * <tt>listIterator</tt> methods are <i>fail-fast</i>: if the list is
43 < * structurally modified at any time after the iterator is created, in any way
44 < * except through the Iterator's own <tt>remove</tt> or <tt>add</tt> methods,
45 < * the iterator will throw a <tt>ConcurrentModificationException</tt>.  Thus,
46 < * in the face of concurrent modification, the iterator fails quickly and
47 < * cleanly, rather than risking arbitrary, non-deterministic behavior at an
48 < * undetermined time in the future.
43 > * structurally modified at any time after the iterator is created, in
44 > * any way except through the Iterator's own <tt>remove</tt> or
45 > * <tt>add</tt> methods, the iterator will throw a {@link
46 > * ConcurrentModificationException}.  Thus, in the face of concurrent
47 > * modification, the iterator fails quickly and cleanly, rather than
48 > * risking arbitrary, non-deterministic behavior at an undetermined
49 > * time in the future.
50   *
51   * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
52   * as it is, generally speaking, impossible to make any hard guarantees in the
# Line 53 | Line 54 | package java.util;
54   * throw <tt>ConcurrentModificationException</tt> on a best-effort basis.
55   * Therefore, it would be wrong to write a program that depended on this
56   * exception for its correctness:   <i>the fail-fast behavior of iterators
57 < * should be used only to detect bugs.</i><p>
57 > * should be used only to detect bugs.</i>
58   *
59 < * This class is a member of the
59 > * <p>This class is a member of the
60   * <a href="{@docRoot}/../guide/collections/index.html">
61   * Java Collections Framework</a>.
62   *
# Line 145 | Line 146 | public class LinkedList<E>
146      /**
147       * Inserts the given element at the beginning of this list.
148       *
149 <     * @param o the element to be inserted at the beginning of this list.
149 >     * @param e the element to be inserted at the beginning of this list.
150       */
151 <    public void addFirst(E o) {
152 <        addBefore(o, header.next);
151 >    public void addFirst(E e) {
152 >        addBefore(e, header.next);
153      }
154  
155      /**
156 <     * Appends the given element at the end of this list.  (Identical in
156 >     * Appends the given element to the end of this list.  (Identical in
157       * function to the <tt>add</tt> method; included only for consistency.)
158       *
159 <     * @param o the element to be inserted at the end of this list.
159 >     * @param e the element to be inserted at the end of this list.
160       */
161 <    public void addLast(E o) {
162 <        addBefore(o, header);
161 >    public void addLast(E e) {
162 >        addBefore(e, header);
163      }
164  
165      /**
# Line 184 | Line 185 | public class LinkedList<E>
185      }
186  
187      /**
188 <     * Appends the specified element at the end of this list.
188 >     * Appends the specified element to the end of this list.
189       *
190 <     * @param o element to be appended to this list.
190 >     * @param e element to be appended to this list.
191       * @return <tt>true</tt> (as per the general contract of
192       * <tt>Collection.add</tt>).
193       */
194 <    public boolean add(E o) {
195 <        addBefore(o, header);
194 >    public boolean add(E e) {
195 >        addBefore(e, header);
196          return true;
197      }
198  
# Line 225 | Line 226 | public class LinkedList<E>
226      }
227  
228      /**
229 <     * Appends all of the elements in the specified collection at the end of
229 >     * Appends all of the elements in the specified collection to the end of
230       * this list, in the order that they are returned by the specified
231       * collection's iterator.  The behavior of this operation is undefined if
232       * the specified collection is modified while the operation is in
# Line 252 | Line 253 | public class LinkedList<E>
253       *              from the specified collection.
254       * @param c elements to be inserted into this list.
255       * @return <tt>true</tt> if this list changed as a result of the call.
256 <     * @throws IndexOutOfBoundsException if the specified index is out of
257 <     *            range (<tt>index &lt; 0 || index &gt; size()</tt>).
256 >     * @throws IndexOutOfBoundsException if the index is out of range
257 >     *         (<tt>index &lt; 0 || index &gt; size()</tt>).
258       * @throws NullPointerException if the specified collection is null.
259       */
260      public boolean addAll(int index, Collection<? extends E> c) {
# Line 304 | Line 305 | public class LinkedList<E>
305       * @param index index of element to return.
306       * @return the element at the specified position in this list.
307       *
308 <     * @throws IndexOutOfBoundsException if the specified index is out of
309 <     * range (<tt>index &lt; 0 || index &gt;= size()</tt>).
308 >     * @throws IndexOutOfBoundsException if the index is out of range
309 >     *         (<tt>index &lt; 0 || index &gt; size()</tt>).
310       */
311      public E get(int index) {
312          return entry(index).element;
# Line 318 | Line 319 | public class LinkedList<E>
319       * @param index index of element to replace.
320       * @param element element to be stored at the specified position.
321       * @return the element previously at the specified position.
322 <     * @throws IndexOutOfBoundsException if the specified index is out of
323 <     *            range (<tt>index &lt; 0 || index &gt;= size()</tt>).
322 >     * @throws IndexOutOfBoundsException if the index is out of range
323 >     *         (<tt>index &lt; 0 || index &gt; size()</tt>).
324       */
325      public E set(int index, E element) {
326          Entry<E> e = entry(index);
# Line 336 | Line 337 | public class LinkedList<E>
337       * @param index index at which the specified element is to be inserted.
338       * @param element element to be inserted.
339       *
340 <     * @throws IndexOutOfBoundsException if the specified index is out of
341 <     *            range (<tt>index &lt; 0 || index &gt; size()</tt>).
340 >     * @throws IndexOutOfBoundsException if the index is out of range
341 >     *         (<tt>index &lt; 0 || index &gt; size()</tt>).
342       */
343      public void add(int index, E element) {
344          addBefore(element, (index==size ? header : entry(index)));
# Line 351 | Line 352 | public class LinkedList<E>
352       * @param index the index of the element to removed.
353       * @return the element previously at the specified position.
354       *
355 <     * @throws IndexOutOfBoundsException if the specified index is out of
356 <     *            range (<tt>index &lt; 0 || index &gt;= size()</tt>).
355 >     * @throws IndexOutOfBoundsException if the index is out of range
356 >     *         (<tt>index &lt; 0 || index &gt; size()</tt>).
357       */
358      public E remove(int index) {
359          return remove(entry(index));
360      }
361  
362      /**
363 <     * Return the indexed entry.
363 >     * Returns the indexed entry.
364       */
365      private Entry<E> entry(int index) {
366          if (index < 0 || index >= size)
# Line 486 | Line 487 | public class LinkedList<E>
487      /**
488       * Adds the specified element as the tail (last element) of this list.
489       *
490 <     * @param o the element to add.
490 >     * @param e the element to add.
491       * @return <tt>true</tt> (as per the general contract of
492       * <tt>Queue.offer</tt>)
493       * @since 1.5
494       */
495 <    public boolean offer(E o) {
496 <        return add(o);
495 >    public boolean offer(E e) {
496 >        return add(e);
497      }
498  
499      // Deque operations
# Line 597 | Line 598 | public class LinkedList<E>
598       *
599       * @return the element at the front of this list (which is the top
600       *     of the stack represented by this list)
601 <     * @throws NoSuchElementException if this list is empty
601 >     * @throws NoSuchElementException if this list is empty.
602       * @since 1.6
603       */
604      public E pop() {
# Line 663 | Line 664 | public class LinkedList<E>
664       *              list-iterator (by a call to <tt>next</tt>).
665       * @return a ListIterator of the elements in this list (in proper
666       *         sequence), starting at the specified position in the list.
667 <     * @throws    IndexOutOfBoundsException if index is out of range
668 <     *            (<tt>index &lt; 0 || index &gt; size()</tt>).
667 >     * @throws IndexOutOfBoundsException if the index is out of range
668 >     *         (<tt>index &lt; 0 || index &gt; size()</tt>).
669       * @see List#listIterator(int)
670       */
671      public ListIterator<E> listIterator(int index) {
# Line 745 | Line 746 | public class LinkedList<E>
746              expectedModCount++;
747          }
748  
749 <        public void set(E o) {
749 >        public void set(E e) {
750              if (lastReturned == header)
751                  throw new IllegalStateException();
752              checkForComodification();
753 <            lastReturned.element = o;
753 >            lastReturned.element = e;
754          }
755  
756 <        public void add(E o) {
756 >        public void add(E e) {
757              checkForComodification();
758              lastReturned = header;
759 <            addBefore(o, next);
759 >            addBefore(e, next);
760              nextIndex++;
761              expectedModCount++;
762          }
# Line 778 | Line 779 | public class LinkedList<E>
779          }
780      }
781  
782 <    private Entry<E> addBefore(E o, Entry<E> e) {
783 <        Entry<E> newEntry = new Entry<E>(o, e, e.previous);
782 >    private Entry<E> addBefore(E e, Entry<E> entry) {
783 >        Entry<E> newEntry = new Entry<E>(e, entry, entry.previous);
784          newEntry.previous.next = newEntry;
785          newEntry.next.previous = newEntry;
786          size++;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines