Package com.globalmentor.collections
Class DecoratorReadWriteLockCollection<E>
java.lang.Object
com.globalmentor.collections.ReadWriteLockDecorator
com.globalmentor.collections.DecoratorReadWriteLockCollection<E>
- Type Parameters:
E
- The type of elements in the collection.
- All Implemented Interfaces:
ReadWriteLockCollection<E>
,Iterable<E>
,Collection<E>
,ReadWriteLock
- Direct Known Subclasses:
DecoratorReadWriteLockSet
public class DecoratorReadWriteLockCollection<E>
extends ReadWriteLockDecorator
implements ReadWriteLockCollection<E>
A thread-safe collection decorator that allows many readers but only one writer to access a collection at a time. For operations that iterate over live
collection data, a read or write lock should be acquired before the call to acquire the data and held until the data is consumed.
- Author:
- Garret Wilson
-
Constructor Summary
ConstructorDescriptionDecoratorReadWriteLockCollection
(Collection<E> collection) Collection constructor with a default reentrant read/write lock.DecoratorReadWriteLockCollection
(Collection<E> collection, ReadWriteLock lock) Collection and read/write lock constructor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addAll
(Collection<? extends E> c) void
clear()
boolean
boolean
containsAll
(Collection<?> c) boolean
protected Collection<E>
int
hashCode()
boolean
isEmpty()
iterator()
boolean
boolean
removeAll
(Collection<?> c) boolean
boolean
retainAll
(Collection<?> c) int
size()
stream()
Object[]
toArray()
<T> T[]
toArray
(T[] a) Methods inherited from class com.globalmentor.collections.ReadWriteLockDecorator
readLock, writeLock
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.concurrent.locks.ReadWriteLock
readLock, writeLock
-
Constructor Details
-
DecoratorReadWriteLockCollection
Collection constructor with a default reentrant read/write lock.- Parameters:
collection
- The collection this collection should decorate.- Throws:
NullPointerException
- if the provided collection isnull
.
-
DecoratorReadWriteLockCollection
Collection and read/write lock constructor.- Parameters:
collection
- The collection this collection should decorate.lock
- The lock for controlling access to the collection.- Throws:
NullPointerException
- if the provided collection and/or lock isnull
.
-
-
Method Details
-
getCollection
- Returns:
- The collection this class decorates.
-
size
public int size()- Specified by:
size
in interfaceCollection<E>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<E>
-
contains
- Specified by:
contains
in interfaceCollection<E>
-
iterator
-
toArray
- Specified by:
toArray
in interfaceCollection<E>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArray
in interfaceCollection<E>
-
add
- Specified by:
add
in interfaceCollection<E>
-
remove
- Specified by:
remove
in interfaceCollection<E>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<E>
-
addAll
- Specified by:
addAll
in interfaceCollection<E>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<E>
-
removeIf
- Specified by:
removeIf
in interfaceCollection<E>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<E>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<E>
-
equals
- Specified by:
equals
in interfaceCollection<E>
- Overrides:
equals
in classObject
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<E>
- Overrides:
hashCode
in classObject
-
spliterator
- Specified by:
spliterator
in interfaceCollection<E>
- Specified by:
spliterator
in interfaceIterable<E>
-
stream
- Specified by:
stream
in interfaceCollection<E>
-
parallelStream
- Specified by:
parallelStream
in interfaceCollection<E>
-