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 |
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 |
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 |
|
* |
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. |
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. |
191 |
|
* @return <tt>true</tt> (as per the general contract of |
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 |
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 < 0 || index > size()</tt>). |
256 |
> |
* @throws IndexOutOfBoundsException if the index is out of range |
257 |
> |
* (<tt>index < 0 || index > size()</tt>). |
258 |
|
* @throws NullPointerException if the specified collection is null. |
259 |
|
*/ |
260 |
|
public boolean addAll(int index, Collection<? extends E> c) { |
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 < 0 || index >= size()</tt>). |
308 |
> |
* @throws IndexOutOfBoundsException if the index is out of range |
309 |
> |
* (<tt>index < 0 || index > size()</tt>). |
310 |
|
*/ |
311 |
|
public E get(int index) { |
312 |
|
return entry(index).element; |
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 < 0 || index >= size()</tt>). |
322 |
> |
* @throws IndexOutOfBoundsException if the index is out of range |
323 |
> |
* (<tt>index < 0 || index > size()</tt>). |
324 |
|
*/ |
325 |
|
public E set(int index, E element) { |
326 |
|
Entry<E> e = entry(index); |
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 < 0 || index > size()</tt>). |
340 |
> |
* @throws IndexOutOfBoundsException if the index is out of range |
341 |
> |
* (<tt>index < 0 || index > size()</tt>). |
342 |
|
*/ |
343 |
|
public void add(int index, E element) { |
344 |
|
addBefore(element, (index==size ? header : entry(index))); |
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 < 0 || index >= size()</tt>). |
355 |
> |
* @throws IndexOutOfBoundsException if the index is out of range |
356 |
> |
* (<tt>index < 0 || index > 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) |
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() { |
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 < 0 || index > size()</tt>). |
667 |
> |
* @throws IndexOutOfBoundsException if the index is out of range |
668 |
> |
* (<tt>index < 0 || index > size()</tt>). |
669 |
|
* @see List#listIterator(int) |
670 |
|
*/ |
671 |
|
public ListIterator<E> listIterator(int index) { |