@ThreadSafe public final class Atomics extends Object
AtomicReference classes and
the like.
All methods are thread safe.
| Modifier and Type | Method and Description |
|---|---|
static boolean |
getAndSetIf(AtomicBoolean reference,
boolean oldValue,
boolean newValue)
|
static long |
getAndSetIf(AtomicInteger reference,
int oldValue,
int newValue)
|
static long |
getAndSetIf(AtomicLong reference,
long oldValue,
long newValue)
Get the current value of the
reference but if it matches
the oldValue argument, compare-and-set it the new value. |
static <T> T |
getAndSetIf(AtomicReference<T> reference,
T oldValue,
Supplier<T> newValue)
Get the current value of the
reference but if it
matches the oldValue argument, compare-and-set it to one created by the
new value supplier. |
static <T> T |
getAndSetIf(AtomicReference<T> reference,
T oldValue,
T newValue)
Check the current value of the
reference and if it
matches the old value argument, compare-and-set it to the new value and
return that instead. |
static <T> T |
getAndSetIf(AtomicReferenceArray<T> reference,
int index,
T oldValue,
Supplier<T> newValue)
Get the current value of the
array reference
but if it matches the oldValue argument, compare-and-set it to one created
by the new value supplier. |
static <T> T |
getAndSetIf(AtomicReferenceArray<T> reference,
int index,
T oldValue,
T newValue)
Get the current value of the
array reference
but if it matches the oldValue argument, compare-and-set it the new value. |
static <T> T |
getAndSetIfNull(AtomicReference<T> reference,
Supplier<T> newValue)
|
static <T> T |
getAndSetIfNull(AtomicReference<T> reference,
T newValue)
Get the current value of the
reference but if it is
null, compare-and-set it the new value. |
static <T> T |
getAndSetIfNull(AtomicReferenceArray<T> reference,
int index,
Supplier<T> newValue)
Get the current value of the
array reference
but if it is null, compare-and-set it to one created by the new value
Supplier. |
static <T> T |
getAndSetIfNull(AtomicReferenceArray<T> reference,
int index,
T newValue)
Get the current value of the
array reference
but if it is null, compare-and-set it the new value |
public static <T> T getAndSetIf(AtomicReference<T> reference, T oldValue, Supplier<T> newValue)
reference but if it
matches the oldValue argument, compare-and-set it to one created by the
new value supplier.T - the object type.reference - the reference to get the value from.oldValue - to check the current value against (reference equality
check only).newValue - a Supplier for a new value. May
be called more than once.public static <T> T getAndSetIf(AtomicReference<T> reference, T oldValue, T newValue)
reference and if it
matches the old value argument, compare-and-set it to the new value and
return that instead. If the old value argument does not match, ignore both
and return the current value.T - the object type.reference - the reference to get the value fromoldValue - to check the current value against (reference equality
check only)newValue - the new value to set it topublic static <T> T getAndSetIfNull(AtomicReference<T> reference, Supplier<T> newValue)
reference but if it is
null, compare-and-set it to one created by the new value
Supplier.T - the object type.reference - the reference to get the value fromnewValue - a Supplier for a new value. May
be called more than once.public static <T> T getAndSetIfNull(AtomicReference<T> reference, T newValue)
reference but if it is
null, compare-and-set it the new value.T - the object type.reference - the reference to get the value fromnewValue - the new value.public static <T> T getAndSetIf(AtomicReferenceArray<T> reference, int index, T oldValue, Supplier<T> newValue)
array reference
but if it matches the oldValue argument, compare-and-set it to one created
by the new value supplier.T - the object type.index - the index to the itemreference - the reference to get the value fromoldValue - to check the current value against (reference equality
check only)newValue - a Supplier for a new value. May
be called more than once.IndexOutOfBoundsException - if the index is less than 0 or
equal or greater than the array sizepublic static <T> T getAndSetIf(AtomicReferenceArray<T> reference, int index, T oldValue, T newValue)
array reference
but if it matches the oldValue argument, compare-and-set it the new value.T - the object type.index - the index to the itemreference - the reference to get the value fromoldValue - to check the current value against (reference equality
check only)newValue - the new value.IndexOutOfBoundsException - if the index is less than 0 or
equal or greater than the array sizepublic static <T> T getAndSetIfNull(AtomicReferenceArray<T> reference, int index, Supplier<T> newValue)
array reference
but if it is null, compare-and-set it to one created by the new value
Supplier.T - the object type.index - the index to the item.reference - the reference to get the value from.newValue - a Supplier for a new value. May
be called more than once.IndexOutOfBoundsException - if the index is less than 0 or
equal or greater than the array size.public static <T> T getAndSetIfNull(AtomicReferenceArray<T> reference, int index, T newValue)
array reference
but if it is null, compare-and-set it the new valueT - the object type.index - the index to the item.reference - the reference to get the value from.newValue - the new value.IndexOutOfBoundsException - if the index is less than 0 or
equal or greater than the array size.public static long getAndSetIf(AtomicLong reference, long oldValue, long newValue)
reference but if it matches
the oldValue argument, compare-and-set it the new value.reference - the reference to get the value fromoldValue - to check the current value against.newValue - the new value.public static long getAndSetIf(AtomicInteger reference, int oldValue, int newValue)
reference but if it
matches the oldValue argument, compare-and-set it to one created by the
newValue Supplier.reference - the reference to get the value fromoldValue - to check the current value against.newValue - the new value.public static boolean getAndSetIf(AtomicBoolean reference, boolean oldValue, boolean newValue)
reference but if it
matches the oldValue argument, compare-and-set it to one created by the
newValue Supplier.reference - the reference to get the value fromoldValue - to check the current value against.newValue - the new value.Copyright © 2024 Atlassian. All rights reserved.