Top Description Methods
org.springframework.core

public Interface AttributeAccessor

Known Direct Implementers
org.springframework.core.AttributeAccessorSupport
Imports
java.util.function.Function, org.springframework.lang.Nullable, org.springframework.util.Assert

Interface defining a generic contract for attaching and accessing metadata to/from arbitrary objects.
Authors
Rob Harrop, Sam Brannen
Since
2.0

Method Summary

Modifier and TypeMethod and Description
public String[]
attributeNames()

Return the names of all attributes.

public default <
the type of the attribute value
T
>
T

Returns:

the existing value or newly computed value for the named attribute
computeAttribute
(String
the unique attribute key
name
,
Function<String, T>
a function that computes a new value for the attribute name; the function must not return a null value
computeFunction
)

Compute a new value for the attribute identified by name if necessary and set the new value in this AttributeAccessor.

public Object

Returns:

the current value of the attribute, if any
getAttribute
(String
the unique attribute key
name
)

Get the value of the attribute identified by name.

public boolean
hasAttribute(String
the unique attribute key
name
)

Return true if the attribute identified by name exists.

public Object

Returns:

the last value of the attribute, if any
removeAttribute
(String
the unique attribute key
name
)

Remove the attribute identified by name and return its value.

public void
setAttribute(String
the unique attribute key
name
,
Object
the attribute value to be attached
value
)

Set the attribute defined by name to the supplied value.

Method Detail

attributeNamesback to summary
public String[] attributeNames()

Return the names of all attributes.

computeAttributeback to summary
public default <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.

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.

Parameters
<T>
the type of the attribute value
name:String

the unique attribute key

computeFunction:Function<String, T>

a function that computes a new value for the attribute name; the function must not return a null value

Returns:T

the existing value or newly computed value for the named attribute

Annotations
@SuppressWarnings:unchecked
Since
5.3.3
See Also
getAttribute(String), setAttribute(String, Object)
getAttributeback to summary
public Object getAttribute(String name)

Get the value of the attribute identified by name.

Return null if the attribute doesn't exist.

Parameters
name:String

the unique attribute key

Returns:Object

the current value of the attribute, if any

Annotations
@Nullable
hasAttributeback to summary
public boolean hasAttribute(String name)

Return true if the attribute identified by name exists.

Otherwise return false.

Parameters
name:String

the unique attribute key

removeAttributeback to summary
public Object removeAttribute(String name)

Remove the attribute identified by name and return its value.

Return null if no attribute under name is found.

Parameters
name:String

the unique attribute key

Returns:Object

the last value of the attribute, if any

Annotations
@Nullable
setAttributeback to summary
public void setAttribute(String name, Object value)

Set the attribute defined by 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.

Parameters
name:String

the unique attribute key

value:Object

the attribute value to be attached