public class SynchronizedList<E> extends SynchronizedCollection<E> implements List<E>
List to synchronize its behaviour
for a multi-threaded environment.
Methods are synchronized, then forwarded to the decorated list.
This class is Serializable from Commons Collections 3.1.
collection, lock| Modifier | Constructor and Description |
|---|---|
protected |
SynchronizedList(List<E> list)
Constructor that wraps (not copies).
|
protected |
SynchronizedList(List<E> list,
Object lock)
Constructor that wraps (not copies).
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(int index,
E object) |
boolean |
addAll(int index,
Collection<? extends E> coll) |
E |
get(int index) |
protected List<E> |
getList()
Gets the decorated list.
|
int |
indexOf(Object object) |
int |
lastIndexOf(Object object) |
ListIterator<E> |
listIterator()
Iterators must be manually synchronized.
|
ListIterator<E> |
listIterator(int index)
Iterators must be manually synchronized.
|
E |
remove(int index) |
E |
set(int index,
E object) |
List<E> |
subList(int fromIndex,
int toIndex) |
static <T> SynchronizedList<T> |
synchronizedList(List<T> list)
Factory method to create a synchronized list.
|
add, addAll, clear, contains, containsAll, decorated, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, synchronizedCollection, toArray, toArray, toStringprotected SynchronizedList(List<E> list)
list - the list to decorate, must not be nullIllegalArgumentException - if list is nullprotected SynchronizedList(List<E> list, Object lock)
list - the list to decorate, must not be nulllock - the lock to use, must not be nullIllegalArgumentException - if list is nullpublic static <T> SynchronizedList<T> synchronizedList(List<T> list)
T - the type of the elements in the listlist - the list to decorate, must not be nullIllegalArgumentException - if list is nullpublic boolean addAll(int index, Collection<? extends E> coll)
public int lastIndexOf(Object object)
lastIndexOf in interface List<E>public ListIterator<E> listIterator()
synchronized (coll) {
ListIterator it = coll.listIterator();
// do stuff with iterator
}listIterator in interface List<E>public ListIterator<E> listIterator(int index)
synchronized (coll) {
ListIterator it = coll.listIterator(3);
// do stuff with iterator
}listIterator in interface List<E>index - index of first element to be returned by this list iteratorCopyright © 2001-2013 The Apache Software Foundation. All Rights Reserved.