T
- the type which contains the target fieldV
- the array value typepublic final class AtomicArray<T,V> extends Object
AtomicReferenceFieldUpdater
which corresponds to that field. Some of these methods perform multi-step operations; if the array field value is
changed in the middle of such an operation, the operation is retried. To avoid spinning, in some situations it
may be advisable to hold a write lock to prevent multiple concurrent updates.Modifier and Type | Class and Description |
---|---|
static interface |
AtomicArray.Creator<V> |
Modifier and Type | Method and Description |
---|---|
void |
add(T instance,
V value)
Atomically replace the array with a new array which is one element longer, and which includes the given value.
|
void |
add(T instance,
V value,
Comparator<? super V> comparator)
Add a value to a sorted array.
|
boolean |
addIfAbsent(T instance,
V value,
boolean identity)
Atomically replace the array with a new array which is one element longer, and which includes the given value,
if the value is not already present within the array.
|
boolean |
addIfAbsent(T instance,
V value,
Comparator<? super V> comparator)
Add a value to a sorted array if it is not already present.
|
void |
clear(T instance)
Convenience method to set the field value to the empty array.
|
static <T,V> AtomicArray<T,V> |
create(AtomicReferenceFieldUpdater<T,V[]> updater,
AtomicArray.Creator<V> creator)
Convenience method to create an instance.
|
static <T,V> AtomicArray<T,V> |
create(AtomicReferenceFieldUpdater<T,V[]> updater,
Class<V> componentType)
Convenience method to create an instance.
|
V[] |
getAndSet(T instance,
V[] value)
Atomically get and update the value of this array.
|
boolean |
remove(T instance,
V value,
boolean identity)
Atomically replace the array with a new array which does not include the first occurrance of the given value, if
the value is present in the array.
|
boolean |
remove(T instance,
V value,
Comparator<? super V> comparator)
Remove a value to a sorted array.
|
int |
removeAll(T instance,
V value,
boolean identity)
Atomically replace the array with a new array which does not include any occurrances of the given value, if
the value is present in the array.
|
void |
set(T instance,
V[] value)
Update the value of this array.
|
void |
sort(T instance,
Comparator<? super V> comparator)
Sort an array.
|
public static <T,V> AtomicArray<T,V> create(AtomicReferenceFieldUpdater<T,V[]> updater, Class<V> componentType)
T
- the type which contains the target fieldV
- the array value typeupdater
- the field updatercomponentType
- the component classpublic static <T,V> AtomicArray<T,V> create(AtomicReferenceFieldUpdater<T,V[]> updater, AtomicArray.Creator<V> creator)
T
- the type which contains the target fieldV
- the array value typeupdater
- the field updatercreator
- the array creatorpublic void clear(T instance)
instance
- the instance holding the fieldpublic void set(T instance, V[] value)
instance
- the instance holding the fieldvalue
- the new valuepublic V[] getAndSet(T instance, V[] value)
instance
- the instance holding the fieldvalue
- the new valuepublic void add(T instance, V value)
instance
- the instance holding the fieldvalue
- the updated valuepublic boolean addIfAbsent(T instance, V value, boolean identity)
instance
- the instance holding the fieldvalue
- the updated valueidentity
- true
if comparisons should be done using reference identity, or false
to use the equals()
methodtrue
if the value was added, or false
if it was already presentpublic boolean remove(T instance, V value, boolean identity)
instance
- the instance holding the fieldvalue
- the updated valueidentity
- true
if comparisons should be done using reference identity, or false
to use the equals()
methodtrue
if the value was removed, or false
if it was not presentpublic int removeAll(T instance, V value, boolean identity)
instance
- the instance holding the fieldvalue
- the updated valueidentity
- true
if comparisons should be done using reference identity, or false
to use the equals()
methodpublic void add(T instance, V value, Comparator<? super V> comparator)
instance
- the instance holding the fieldvalue
- the value to addcomparator
- a comparator, or null
to use natural orderingpublic boolean addIfAbsent(T instance, V value, Comparator<? super V> comparator)
instance
- the instance holding the fieldvalue
- the value to addcomparator
- a comparator, or null
to use natural orderingpublic boolean remove(T instance, V value, Comparator<? super V> comparator)
instance
- the instance holding the fieldvalue
- the value to removecomparator
- a comparator, or null
to use natural orderingpublic void sort(T instance, Comparator<? super V> comparator)
instance
- the instance holding the fieldcomparator
- a comparator, or null
to use natural orderingCopyright © 2012 JBoss by Red Hat. All Rights Reserved.