private static final class DefaultAttributeMap.DefaultAttribute<T> extends java.util.concurrent.atomic.AtomicReference<T> implements Attribute<T>
Modifier and Type | Field and Description |
---|---|
private DefaultAttributeMap.DefaultAttribute<?> |
head |
private AttributeKey<T> |
key |
private DefaultAttributeMap.DefaultAttribute<?> |
next |
private DefaultAttributeMap.DefaultAttribute<?> |
prev |
private boolean |
removed |
private static long |
serialVersionUID |
Constructor and Description |
---|
DefaultAttribute() |
DefaultAttribute(DefaultAttributeMap.DefaultAttribute<?> head,
AttributeKey<T> key) |
Modifier and Type | Method and Description |
---|---|
T |
getAndRemove()
Removes this attribute from the
AttributeMap and returns the old value. |
AttributeKey<T> |
key()
Returns the key of this attribute.
|
void |
remove()
Removes this attribute from the
AttributeMap . |
private void |
remove0() |
T |
setIfAbsent(T value)
Atomically sets to the given value if this
Attribute 's value is null . |
accumulateAndGet, compareAndSet, get, getAndAccumulate, getAndSet, getAndUpdate, lazySet, set, toString, updateAndGet, weakCompareAndSet
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
compareAndSet, get, getAndSet, set
private static final long serialVersionUID
private final DefaultAttributeMap.DefaultAttribute<?> head
private final AttributeKey<T> key
private DefaultAttributeMap.DefaultAttribute<?> prev
private DefaultAttributeMap.DefaultAttribute<?> next
private volatile boolean removed
DefaultAttribute(DefaultAttributeMap.DefaultAttribute<?> head, AttributeKey<T> key)
DefaultAttribute()
public AttributeKey<T> key()
Attribute
public T setIfAbsent(T value)
Attribute
Attribute
's value is null
.
If it was not possible to set the value as it contains a value it will just return the current value.setIfAbsent
in interface Attribute<T>
public T getAndRemove()
Attribute
AttributeMap
and returns the old value. Subsequent Attribute.get()
calls will return null
.
If you only want to return the old value and clear the Attribute
while still keep it in the
AttributeMap
use Attribute.getAndSet(Object)
with a value of null
.
Be aware that even if you call this method another thread that has obtained a reference to this Attribute
via AttributeMap.attr(AttributeKey)
will still operate on the same instance. That said if now another
thread or even the same thread later will call AttributeMap.attr(AttributeKey)
again, a new
Attribute
instance is created and so is not the same as the previous one that was removed. Because of
this special caution should be taken when you call Attribute.remove()
or Attribute.getAndRemove()
.
getAndRemove
in interface Attribute<T>
public void remove()
Attribute
AttributeMap
. Subsequent Attribute.get()
calls will return @{code null}.
If you only want to remove the value and clear the Attribute
while still keep it in
AttributeMap
use Attribute.set(Object)
with a value of null
.
Be aware that even if you call this method another thread that has obtained a reference to this Attribute
via AttributeMap.attr(AttributeKey)
will still operate on the same instance. That said if now another
thread or even the same thread later will call AttributeMap.attr(AttributeKey)
again, a new
Attribute
instance is created and so is not the same as the previous one that was removed. Because of
this special caution should be taken when you call Attribute.remove()
or Attribute.getAndRemove()
.
private void remove0()