public class ResettableLazyReference<T> extends Object
getOrCreate(Supplier)
The reference can be cleared atomically with reset()
or safeReset(Object)
.
Once reset, no other thread is able obtain the same value from this reference (though other
threads may already have obtained it before the reset occurred).Constructor and Description |
---|
ResettableLazyReference() |
Modifier and Type | Method and Description |
---|---|
io.atlassian.fugue.Option<T> |
get() |
T |
getOrCreate(Supplier<T> creator)
Gets the reference's value, obtaining the new value from the supplier if it was not previously
initialized.
|
io.atlassian.fugue.Option<T> |
reset()
Resets this reference to empty, returning the old value.
|
io.atlassian.fugue.Option<T> |
safeReset(T expected)
Compares the reference value to the
expected value and resets it if and only if it is identical. |
public io.atlassian.fugue.Option<T> reset()
public io.atlassian.fugue.Option<T> safeReset(T expected)
expected
value and resets it if and only if it is identical.
The reset request will fail (return Option.none()
and have no effect) if the expected
value supplied is null
.
expected
- the expected value of the referencenull
or because it did not match the value currently held by the reference), then
Option.none()
is returned.public io.atlassian.fugue.Option<T> get()
Option.some
on the current value for this reference; Option.none()
if it has not
been initialized yet@Nonnull public T getOrCreate(Supplier<T> creator)
Only one thread will be allowed to call the supplier at any given time, and it will not be
called again before the reference is reset()
.
creator
- supplier to be used for creating this referenceIllegalArgumentException
- if creator.get()
returns null
Copyright © 2002-2023 Atlassian. All Rights Reserved.