public abstract class AttributeAccessorSupport extends Object implements AttributeAccessor, Serializable
AttributeAccessors
, providing
a base implementation of all methods. To be extended by subclasses.
Serializable
if subclasses and all attribute values are Serializable
.
Constructor and Description |
---|
AttributeAccessorSupport() |
Modifier and Type | Method and Description |
---|---|
String[] |
attributeNames()
Return the names of all attributes.
|
<T> T |
computeAttribute(String name,
Function<String,T> computeFunction)
Compute a new value for the attribute identified by
name if
necessary and set the new value in this
AttributeAccessor . |
protected void |
copyAttributesFrom(AttributeAccessor source)
Copy the attributes from the supplied AttributeAccessor to this accessor.
|
boolean |
equals(Object other) |
Object |
getAttribute(String name)
Get the value of the attribute identified by
name . |
boolean |
hasAttribute(String name)
Return
true if the attribute identified by name exists. |
int |
hashCode() |
Object |
removeAttribute(String name)
Remove the attribute identified by
name and return its value. |
void |
setAttribute(String name,
Object value)
Set the attribute defined by
name to the supplied value . |
public void setAttribute(String name, @Nullable Object value)
AttributeAccessor
name
to the supplied value
.
If value
is null
, the attribute is removed
.
In general, users should take care to prevent overlaps with other metadata attributes by using fully-qualified names, perhaps using class or package names as prefix.
setAttribute
in interface AttributeAccessor
name
- the unique attribute keyvalue
- the attribute value to be attached@Nullable public Object getAttribute(String name)
AttributeAccessor
name
.
Return null
if the attribute doesn't exist.
getAttribute
in interface AttributeAccessor
name
- the unique attribute keypublic <T> T computeAttribute(String name, Function<String,T> computeFunction)
AttributeAccessor
name
if
necessary and set the new value in this
AttributeAccessor
.
If a value for the attribute identified by name
already exists
in this AttributeAccessor
, the existing value will be returned
without applying the supplied compute function.
The default implementation of this method is not thread safe but can be overridden by concrete implementations of this interface.
computeAttribute
in interface AttributeAccessor
T
- the type of the attribute valuename
- the unique attribute keycomputeFunction
- a function that computes a new value for the attribute
name; the function must not return a null
valueAttributeAccessor.getAttribute(String)
,
AttributeAccessor.setAttribute(String, Object)
@Nullable public Object removeAttribute(String name)
AttributeAccessor
name
and return its value.
Return null
if no attribute under name
is found.
removeAttribute
in interface AttributeAccessor
name
- the unique attribute keypublic boolean hasAttribute(String name)
AttributeAccessor
true
if the attribute identified by name
exists.
Otherwise return false
.
hasAttribute
in interface AttributeAccessor
name
- the unique attribute keypublic String[] attributeNames()
AttributeAccessor
attributeNames
in interface AttributeAccessor
protected void copyAttributesFrom(AttributeAccessor source)
source
- the AttributeAccessor to copy from