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 | Field and Description |
|---|---|
| private final Class | |
| private final V[] | |
| private final AtomicReferenceFieldUpdater |
| Access | Constructor and Description |
|---|---|
| public | AtomicArray(AtomicReferenceFieldUpdater<T, V[]>
the field updater updater, Class<V> the component class componentType)Construct an instance. |
| Modifier and Type | Method and Description |
|---|---|
| public void | add(T
the instance holding the field instance, V the updated value value)Atomically replace the array with a new array which is one element longer, and which includes the given value. |
| public void | add(T
the instance holding the field instance, V the value to add value, Comparator<? super V> a comparator, or comparator)null to use natural orderingAdd a value to a sorted array. |
| public boolean | Returns: true if the value was added, or false if it was already presentthe instance holding the field instance, V the updated value value, boolean true if comparisons should be done using reference identity, or false to use the
equals() methodAtomically 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. |
| public boolean | addIfAbsent(T
the instance holding the field instance, V the value to add value, Comparator<? super V> a comparator, or comparator)null to use natural orderingAdd a value to a sorted array if it is not already present. |
| public void | clear(T
the instance holding the field instance)Convenience method to set the field value to the empty array. |
| public boolean | Returns: true if the value was updated or false if the expected value did not matchthe instance holding the field instance, final V[] the expected value expect, final V[] the update value update)Compare and set the array. |
| private static <V> V[] | |
| public static < the type which contains the target field T, the array value type V> AtomicArray | Returns: the new instancethe field updater updater, Class<V> the component class componentType)Convenience method to create an instance. |
| public V[] | getAndSet(T
the instance holding the field instance, V[] the new value value)Atomically get and update the value of this array. |
| private static int | |
| private static <V> V[] | |
| public boolean | Returns: true if the value was removed, or false if it was not presentthe instance holding the field instance, V the updated value value, boolean true if comparisons should be done using reference identity, or false to use the
equals() methodAtomically replace the array with a new array which does not include the first occurrence of the given value, if the value is present in the array. |
| public boolean | remove(T
the instance holding the field instance, V the value to remove value, Comparator<? super V> a comparator, or comparator)null to use natural orderingRemove a value to a sorted array. |
| public int | Returns: the number of values removedthe instance holding the field instance, V the updated value value, boolean true if comparisons should be done using reference identity, or false to use the
equals() methodAtomically replace the array with a new array which does not include any occurrences of the given value, if the value is present in the array. |
| public void | set(T
the instance holding the field instance, V[] the new value value)Update the value of this array. |
| public void | sort(T
the instance holding the field instance, Comparator<? super V> a comparator, or comparator)null to use natural orderingSort an array. |
| componentType | back to summary |
|---|---|
| private final Class<V> componentType | |
| emptyArray | back to summary |
|---|---|
| private final V[] emptyArray | |
| updater | back to summary |
|---|---|
| private final AtomicReferenceFieldUpdater<T, V[]> updater | |
| AtomicArray | back to summary |
|---|---|
| public AtomicArray(AtomicReferenceFieldUpdater<T, V[]> updater, Class<V> componentType) Construct an instance.
| |
| add | back to summary |
|---|---|
| public 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.
| |
| add | back to summary |
|---|---|
| public void add(T instance, V value, Comparator<? super V> comparator) Add a value to a sorted array. Does not check for duplicates.
| |
| addIfAbsent | back to summary |
|---|---|
| public 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. This method does a linear search for the target value.
| |
| addIfAbsent | back to summary |
|---|---|
| public boolean addIfAbsent(T instance, V value, Comparator<? super V> comparator) Add a value to a sorted array if it is not already present. Does not check for duplicates.
| |
| clear | back to summary |
|---|---|
| public void clear(T instance) Convenience method to set the field value to the empty array. Empty array instances are shared.
| |
| compareAndSet | back to summary |
|---|---|
| public boolean compareAndSet(final T instance, final V[] expect, final V[] update) Compare and set the array.
| |
| copyOf | back to summary |
|---|---|
private static <V> V[] copyOf(final Class<V> componentType, V[] old, int newLen)
| |
| create | back to summary |
|---|---|
| public static <T, V> AtomicArray Convenience method to create an instance.
| |
| getAndSet | back to summary |
|---|---|
| public V[] getAndSet(T instance, V[] value) Atomically get and update the value of this array.
| |
| insertionPoint | back to summary |
|---|---|
| private static int insertionPoint(int searchResult) | |
| newInstance | back to summary |
|---|---|
private static <V> V[] newInstance(Class<V> componentType, int length)
| |
| remove | back to summary |
|---|---|
| public boolean remove(T instance, V value, boolean identity) Atomically replace the array with a new array which does not include the first occurrence of the given value, if the value is present in the array.
| |
| remove | back to summary |
|---|---|
| public boolean remove(T instance, V value, Comparator<? super V> comparator) Remove a value to a sorted array. Does not check for duplicates. If there are multiple occurrences of a value, there is no guarantee as to which one is removed.
| |
| removeAll | back to summary |
|---|---|
| public int removeAll(T instance, V value, boolean identity) Atomically replace the array with a new array which does not include any occurrences of the given value, if the value is present in the array.
| |
| set | back to summary |
|---|---|
| public void set(T instance, V[] value) Update the value of this array.
| |
| sort | back to summary |
|---|---|
| public void sort(T instance, Comparator<? super V> comparator) Sort an array.
| |