org.apache.commons.collections.list
Class SynchronizedList<E>

java.lang.Object
  extended by org.apache.commons.collections.collection.SynchronizedCollection<E>
      extended by org.apache.commons.collections.list.SynchronizedList<E>
All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, List<E>

public class SynchronizedList<E>
extends SynchronizedCollection<E>
implements List<E>

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.

Since:
Commons Collections 3.0
Version:
$Revision: 1.1.1.1 $ $Date: 2005/05/23 04:35:26 $
Author:
Matt Hall, John Watkinson, Stephen Colebourne
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.commons.collections.collection.SynchronizedCollection
collection, lock
 
Constructor Summary
protected SynchronizedList(List<E> list)
          Constructor that wraps (not copies).
protected SynchronizedList(List<E> list, Object lock)
          Constructor that wraps (not copies).
 
Method Summary
 void add(int index, E object)
           
 boolean addAll(int index, Collection<? extends E> coll)
           
static
<E> List<E>
decorate(List<E> list)
          Factory method to create a synchronized list.
 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)
           
 
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
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 

Constructor Detail

SynchronizedList

protected SynchronizedList(List<E> list)
Constructor that wraps (not copies).

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

SynchronizedList

protected SynchronizedList(List<E> 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:
IllegalArgumentException - if list is null
Method Detail

decorate

public static <E> List<E> decorate(List<E> list)
Factory method to create a synchronized list.

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

getList

protected List<E> getList()
Gets the decorated list.

Returns:
the decorated list

add

public void add(int index,
                E object)
Specified by:
add in interface List<E>

addAll

public boolean addAll(int index,
                      Collection<? extends E> coll)
Specified by:
addAll in interface List<E>

get

public E get(int index)
Specified by:
get in interface List<E>

indexOf

public int indexOf(Object object)
Specified by:
indexOf in interface List<E>

lastIndexOf

public int lastIndexOf(Object object)
Specified by:
lastIndexOf in interface List<E>

listIterator

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

Specified by:
listIterator in interface List<E>
Returns:
an iterator that must be manually synchronized on the collection

listIterator

public ListIterator<E> listIterator(int index)
Iterators must be manually synchronized.
 synchronized (coll) {
   ListIterator it = coll.listIterator(3);
   // do stuff with iterator
 }

Specified by:
listIterator in interface List<E>
Returns:
an iterator that must be manually synchronized on the collection

remove

public E remove(int index)
Specified by:
remove in interface List<E>

set

public E set(int index,
             E object)
Specified by:
set in interface List<E>

subList

public List<E> subList(int fromIndex,
                       int toIndex)
Specified by:
subList in interface List<E>


Copyright © 2005-2005 Apache Software Foundation, Matt Hall, John Watkinson. All Rights Reserved.