org.apache.commons.collections.list

Class SynchronizedList

Implemented Interfaces:
Collection, List, Serializable

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.

This class is Serializable from Commons Collections 3.1.

Version:
$Revision: 1.5 $ $Date: 2004/06/03 22:02:13 $
Author:
Stephen Colebourne
Since:
Commons Collections 3.0

Field Summary

Fields inherited from class org.apache.commons.collections.collection.SynchronizedCollection

collection, lock

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)
protected 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)

Methods inherited from class org.apache.commons.collections.collection.SynchronizedCollection

add, addAll, clear, contains, containsAll, decorate, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString

Constructor Details

SynchronizedList

protected SynchronizedList(List list)
Constructor that wraps (not copies).
Parameters:
list - the list to decorate, must not be null

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

Method Details

add

public void add(int index,
                Object object)

addAll

public boolean addAll(int index,
                      Collection 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

get

public Object get(int index)

getList

protected List getList()
Gets the decorated list.
Returns:
the decorated list

indexOf

public int indexOf(Object object)

lastIndexOf

public int lastIndexOf(Object 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
 }
Returns:
an iterator that must be manually synchronized on the collection

remove

public Object remove(int index)

set

public Object set(int index,
                  Object object)

subList

public List subList(int fromIndex,
                    int toIndex)

Copyright © 2001-2006 Apache Software Foundation. All Rights Reserved.