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. |
| 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 interface java.util.List |
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray |
root
protected final List root
- Backing list.
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.
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