T - the type of the atom's valuepublic class ThreadLocalAtom<T> extends Object
Atom.Watcher<T>| Constructor and Description |
|---|
ThreadLocalAtom()
Constructs a new thread-local atom with a
null value and no validator. |
ThreadLocalAtom(T rootValue)
Constructs a new thread-local atom with the specified value and no validator.
|
ThreadLocalAtom(T rootValue,
Predicate<? super T> validator)
Constructs a new thread-local atom with the specified value and the specified validator.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
addWatcher(Atom.Watcher<? super T> watcher)
Registers a watcher, which will receive notifications when the atom's value changes.
|
T |
get()
Retrieves the current value for this atom.
|
T |
getAndUpdate(Function<? super T,? extends T> function)
Applies a function to the atom's value.
|
T |
getRootValue()
Returns the atom's root value, used to seed the thread-local value for new threads.
|
Predicate<? super T> |
getValidator()
Return the atom's validator, or
null if there is no validator. |
protected void |
notify(T oldValue,
T newValue)
Notifies the atom's watchers that the value has changed.
|
boolean |
removeWatcher(Atom.Watcher<? super T> watcher)
Unregisters a watcher.
|
T |
set(T newValue)
Sets the atom's value to the one specified and returns the previous value.
|
T |
setRootValue(T newRootValue)
Sets the atom's root value.
|
T |
updateAndGet(Function<? super T,? extends T> function)
Applies a function to the atom's value.
|
protected void |
validate(T value)
Validates the specified value.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaccumulateAndGet, getAndAccumulateaddWatcher, removeWatcherpublic ThreadLocalAtom()
null value and no validator.public ThreadLocalAtom(T rootValue)
public T get()
Atompublic T set(T newValue)
SynchronousAtomnewValue - the atom's new valuepublic T getRootValue()
public T setRootValue(T newRootValue)
newRootValue - the new root valuepublic T updateAndGet(Function<? super T,? extends T> function)
SynchronousAtomupdateAndGet in interface SynchronousAtom<T>function - the function to applypublic T getAndUpdate(Function<? super T,? extends T> function)
SynchronousAtomgetAndUpdate in interface SynchronousAtom<T>function - the function to applyprotected void validate(T value)
value - the value to validateIllegalArgumentException - if the specified value is invalidpublic Predicate<? super T> getValidator()
null if there is no validator. The validator is a
predicate that returns true when invoked on valid values for the item and false otherwise.protected void notify(T oldValue,
T newValue)
oldValue - the atom's old valuenewValue - the atom's new valuepublic boolean addWatcher(Atom.Watcher<? super T> watcher)
AtomaddWatcher in interface Atom<T>watcher - the watcherpublic boolean removeWatcher(Atom.Watcher<? super T> watcher)
AtomremoveWatcher in interface Atom<T>watcher - the watcher