18 |
|
import java.util.*; |
19 |
|
|
20 |
|
/** |
21 |
< |
* CopyOnWriteArrayList is a variant of java.util.ArrayList in which all |
22 |
< |
* mutative operations (add, set, and so on) are implemented by making |
23 |
< |
* a fresh copy of the underlying array. <p> |
21 |
> |
* A variant of {@link java.util.ArrayList} in which all mutative |
22 |
> |
* operations (add, set, and so on) are implemented by making a fresh |
23 |
> |
* copy of the underlying array. <p> |
24 |
|
* |
25 |
|
* This is ordinarily too costly, but it becomes attractive when |
26 |
< |
* traversal operations vastly overwhelm mutations, and, especially, |
26 |
> |
* traversal operations vastly overwhelm mutations, and, especially |
27 |
|
* when you cannot or don't want to synchronize traversals, yet need |
28 |
|
* to preclude interference among concurrent threads. The iterator |
29 |
|
* method uses a reference to the state of the array at the point that |
30 |
|
* the iterator was created. This array never changes during the |
31 |
< |
* lifetime of the iterator, so interference is impossible. (The |
31 |
> |
* lifetime of the iterator, so interference is impossible. The |
32 |
|
* iterator will not traverse elements added or changed since the |
33 |
< |
* iterator was created, but usually this is a desirable feature.) |
33 |
> |
* iterator was created. |
34 |
|
* <p> |
35 |
|
* |
36 |
|
* Because of the copy-on-write policy, some one-by-one mutative |
37 |
|
* operations in the java.util.Arrays and java.util.Collections |
38 |
|
* classes are so time/space intensive as to never be worth calling. |
39 |
< |
* <p> |
40 |
< |
* |
41 |
< |
* Due to their strict read-only nature, element-changing operations |
42 |
< |
* on iterators (remove, set, and add) are not supported. These are |
43 |
< |
* the only methods throwing UnsupportedOperationException. <p> |
39 |
> |
* Also, due to their strict read-only nature, element-changing |
40 |
> |
* operations on iterators (remove, set, and add) are not |
41 |
> |
* supported. These are the only methods throwing |
42 |
> |
* UnsupportedOperationException. <p> |
43 |
|
**/ |
44 |
|
public class CopyOnWriteArrayList<E> |
45 |
|
implements List<E>, RandomAccess, Cloneable, java.io.Serializable { |