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.6 by dl, Mon Sep 1 12:23:28 2003 UTC vs.
Revision 1.14 by jsr166, Sun Dec 28 00:55:45 2003 UTC

# Line 25 | Line 25 | package java.util;
25   *
26   * All of the operations perform as could be expected for a doubly-linked
27   * list.  Operations that index into the list will traverse the list from
28 < * the begining or the end, whichever is closer to the specified index.<p>
28 > * the beginning or the end, whichever is closer to the specified index.<p>
29   *
30   * <b>Note that this implementation is not synchronized.</b> If multiple
31   * threads access a list concurrently, and at least one of the threads
# Line 68 | Line 68 | package java.util;
68   * @see     Vector
69   * @see     Collections#synchronizedList(List)
70   * @since 1.2
71 + * @param <E> the type of elements held in this collection
72   */
73  
74   public class LinkedList<E>
# Line 130 | Line 131 | public class LinkedList<E>
131       * @throws    NoSuchElementException if this list is empty.
132       */
133      public E removeFirst() {
134 <        E first = header.next.element;
134 <        remove(header.next);
135 <        return first;
134 >        return remove(header.next);
135      }
136  
137      /**
# Line 142 | Line 141 | public class LinkedList<E>
141       * @throws    NoSuchElementException if this list is empty.
142       */
143      public E removeLast() {
144 <        E last = header.previous.element;
146 <        remove(header.previous);
147 <        return last;
144 >        return remove(header.previous);
145      }
146  
147      /**
# Line 288 | Line 285 | public class LinkedList<E>
285       * Removes all of the elements from this list.
286       */
287      public void clear() {
288 <        modCount++;
288 >        Entry<E> e = header.next;
289 >        while (e != header) {
290 >            Entry<E> next = e.next;
291 >            e.next = e.previous = null;
292 >            e.element = null;
293 >            e = next;
294 >        }
295          header.next = header.previous = header;
296 <        size = 0;
296 >        size = 0;
297 >        modCount++;
298      }
299  
300  
# Line 353 | Line 357 | public class LinkedList<E>
357       *            range (<tt>index &lt; 0 || index &gt;= size()</tt>).
358       */
359      public E remove(int index) {
360 <        Entry<E> e = entry(index);
357 <        remove(e);
358 <        return e.element;
360 >        return remove(entry(index));
361      }
362  
363      /**
# Line 442 | Line 444 | public class LinkedList<E>
444      // Queue operations.
445  
446      /**
447 <     * Retrieves, but does not remove, the head (first element) of this list..
447 >     * Retrieves, but does not remove, the head (first element) of this list.
448       * @return the head of this queue, or <tt>null</tt> if this queue is empty.
449 +     * @since 1.5
450       */
451      public E peek() {
452          if (size==0)
# Line 452 | Line 455 | public class LinkedList<E>
455      }
456  
457      /**
458 <     * Retrieves, but does not remove, the head (first element) of this list..
458 >     * Retrieves, but does not remove, the head (first element) of this list.
459       * @return the head of this queue.
460       * @throws NoSuchElementException if this queue is empty.
461 +     * @since 1.5
462       */
463      public E element() {
464          return getFirst();
465      }
466  
467      /**
468 <     * Retrieves and removes the head (first element) of this list..
468 >     * Retrieves and removes the head (first element) of this list.
469       * @return the head of this queue, or <tt>null</tt> if this queue is empty.
470 +     * @since 1.5
471       */
472      public E poll() {
473          if (size==0)
# Line 471 | Line 476 | public class LinkedList<E>
476      }
477  
478      /**
479 <     * Retrieves and removes the head (first element) of this list..
479 >     * Retrieves and removes the head (first element) of this list.
480       * @return the head of this queue.
481       * @throws NoSuchElementException if this queue is empty.
482 +     * @since 1.5
483       */
484      public E remove() {
485          return removeFirst();
# Line 482 | Line 488 | public class LinkedList<E>
488      /**
489       * Adds the specified element as the tail (last element) of this list.
490       *
491 <     * @param x the element to add.
491 >     * @param o the element to add.
492       * @return <tt>true</tt> (as per the general contract of
493       * <tt>Queue.offer</tt>)
494 +     * @since 1.5
495       */
496 <    public boolean offer(E x) {
497 <        return add(x);
496 >    public boolean offer(E o) {
497 >        return add(o);
498      }
499  
500      /**
# Line 576 | Line 583 | public class LinkedList<E>
583  
584          public void remove() {
585              checkForComodification();
586 +            Entry<E> lastNext = lastReturned.next;
587              try {
588                  LinkedList.this.remove(lastReturned);
589              } catch (NoSuchElementException e) {
590                  throw new IllegalStateException();
591              }
592              if (next==lastReturned)
593 <                next = lastReturned.next;
593 >                next = lastNext;
594              else
595                  nextIndex--;
596              lastReturned = header;
# Line 631 | Line 639 | public class LinkedList<E>
639          return newEntry;
640      }
641  
642 <    private void remove(Entry<E> e) {
642 >    private E remove(Entry<E> e) {
643          if (e == header)
644              throw new NoSuchElementException();
645  
646 +        E result = e.element;
647          e.previous.next = e.next;
648          e.next.previous = e.previous;
649 +        e.next = e.previous = null;
650 +        e.element = null;
651          size--;
652          modCount++;
653 +        return result;
654      }
655  
656      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines