⇒ Index (Frames) |  ⇒ Index (No Frames) |  ⇒ Package |  ⇒ Package Tree |  ⇒ Full Tree 
org.apache.commons.collections.list

Class SynchronizedList

java.lang.Object
|
+--org.apache.commons.collections.collection.SynchronizedCollection
   |
   +--org.apache.commons.collections.list.SynchronizedList

All Implemented Interfaces:
Collection, List


public class SynchronizedList
extends SynchronizedCollection
implements List

Decorates another List to synchronize its behaviour for a multi-threaded environment.

Methods are synchronized, then forwarded to the decorated list.

Since:
Commons Collections 3.0
Author:
Stephen Colebourne

Constructor Summary

SynchronizedList(List list)

Constructor that wraps (not copies).

SynchronizedList(List list, Object lock)

Constructor that wraps (not copies).

Method Summary

void

add(int index, Object object)

boolean

addAll(int index, Collection coll)

static List

decorate(List list)

Factory method to create a synchronized list.

Object

get(int index)

List

getList()

Gets the decorated list.

int

indexOf(Object object)

int

lastIndexOf(Object object)

ListIterator

listIterator()

Iterators must be manually synchronized.

ListIterator

listIterator(int index)

Iterators must be manually synchronized.

Object

remove(int index)

Object

set(int index, Object object)

List

subList(int fromIndex, int toIndex)

Constructor Details

SynchronizedList

protected SynchronizedList(List list, Object lock)

Constructor that wraps (not copies).

Parameters:
list - the list to decorate, must not be null
lock - the lock to use, must not be null
Throws:
- if list is null

SynchronizedList

protected SynchronizedList(List list)

Constructor that wraps (not copies).

Parameters:
list - the list to decorate, must not be null
Throws:
- if list is null

Method Details

add

public void add(int index, Object object)

Parameters:
index
object

addAll

public boolean addAll(int index, Collection coll)

Parameters:
index
coll

decorate

public static List decorate(List list)

Factory method to create a synchronized list.

Parameters:
list - the list to decorate, must not be null
Throws:
- if list is null

get

public Object get(int index)

Parameters:
index

getList

protected List getList()

Gets the decorated list.

Returns:
the decorated list

indexOf

public int indexOf(Object object)

Parameters:
object

lastIndexOf

public int lastIndexOf(Object object)

Parameters:
object

listIterator

public ListIterator listIterator()

Iterators must be manually synchronized.
 synchronized (coll) {
   ListIterator it = coll.listIterator();
   // do stuff with iterator

Returns:
an iterator that must be manually synchronized on the collection

listIterator

public ListIterator listIterator(int index)

Iterators must be manually synchronized.
 synchronized (coll) {
   ListIterator it = coll.listIterator(3);
   // do stuff with iterator

Parameters:
index
Returns:
an iterator that must be manually synchronized on the collection

remove

public Object remove(int index)

Parameters:
index

set

public Object set(int index, Object object)

Parameters:
index
object

subList

public List subList(int fromIndex, int toIndex)

Parameters:
fromIndex
toIndex