gausssoft.collections
Class SynchronizedList

java.lang.Object
  |
  +--gausssoft.collections.SynchronizedCollection
        |
        +--gausssoft.collections.SynchronizedList
All Implemented Interfaces:
Collection, List, Serializable

public class SynchronizedList
extends SynchronizedCollection
implements List

The SynchronizedList class is used to synchronize all operations on a List object on a particular object.

Each method of this implementation synchronizes on a specified object specified at construction time, and then calls the method of the same signature of the backing list. Each instance is serializable only if the backing list and mutex is serializable.

This is similar to the synchronization methods in Collections, but this implementation allows you to choose what object to synchronize on, and allows subclassing.

The subList(int, int) method returns a SynchronizedList that synchronized on the same mutex used by the parent SynchronizedList.

Author:
Allan Crooks
See Also:
Collections, List, Serialized Form

Field Summary
protected  List root
          Backing list.
 
Fields inherited from class gausssoft.collections.SynchronizedCollection
mutex
 
Constructor Summary
SynchronizedList(List root)
          Creates a new SynchronizedList.
SynchronizedList(List root, Object mutex)
          Creates a new SynchronizedList.
 
Method Summary
 void add(int index, Object element)
           
 boolean addAll(int index, Collection c)
           
 Object get(int index)
           
 int indexOf(Object o)
           
 int lastIndexOf(Object o)
           
 ListIterator listIterator()
           
 ListIterator listIterator(int index)
           
 Object remove(int index)
           
 Object set(int index, Object element)
           
 List subList(int fromIndex, int toIndex)
           
 
Methods inherited from class gausssoft.collections.SynchronizedCollection
add, addAll, clear, contains, containsAll, 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
 

Field Detail

root

protected final List root
Backing list.
Constructor Detail

SynchronizedList

public SynchronizedList(List root,
                        Object mutex)
Creates a new SynchronizedList.
Parameters:
root - The list to use as the backing list.
mutex - The object to synchronize operations on.
Throws:
NullPointerException - If root is null.

SynchronizedList

public SynchronizedList(List root)
Creates a new SynchronizedList.

The object constructed will synchronize all operations on itself.

Parameters:
root - The list to use as the backing list.
Throws:
NullPointerException - If root is null.
Method Detail

addAll

public boolean addAll(int index,
                      Collection c)
Specified by:
addAll in interface List

get

public Object get(int index)
Specified by:
get in interface List

set

public Object set(int index,
                  Object element)
Specified by:
set in interface List

add

public void add(int index,
                Object element)
Specified by:
add in interface List

remove

public Object remove(int index)
Specified by:
remove in interface List

indexOf

public int indexOf(Object o)
Specified by:
indexOf in interface List

lastIndexOf

public int lastIndexOf(Object o)
Specified by:
lastIndexOf in interface List

listIterator

public ListIterator listIterator()
Specified by:
listIterator in interface List

listIterator

public ListIterator listIterator(int index)
Specified by:
listIterator in interface List

subList

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