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.10 by dl, Sun Oct 19 13:38:29 2003 UTC vs.
Revision 1.14 by jsr166, Sun Dec 28 00:55:45 2003 UTC

# Line 131 | 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;
135 <        remove(header.next);
136 <        return first;
134 >        return remove(header.next);
135      }
136  
137      /**
# Line 143 | 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;
147 <        remove(header.previous);
148 <        return last;
144 >        return remove(header.previous);
145      }
146  
147      /**
# Line 289 | 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 354 | 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);
358 <        remove(e);
359 <        return e.element;
360 >        return remove(entry(index));
361      }
362  
363      /**
# Line 487 | 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 582 | 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 637 | 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