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 |
|
/** |
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 |
|
/** |
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 |
|
|
357 |
|
* range (<tt>index < 0 || index >= 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 |
|
/** |
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 |
|
/** |
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; |
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 |
|
/** |