Package org.springframework.core
Class AttributeAccessorSupport
java.lang.Object
org.springframework.core.AttributeAccessorSupport
- All Implemented Interfaces:
Serializable
,AttributeAccessor
- Direct Known Subclasses:
BeanMetadataAttributeAccessor
public abstract class AttributeAccessorSupport
extends Object
implements AttributeAccessor, Serializable
Support class for
AttributeAccessors
, providing
a base implementation of all methods. To be extended by subclasses.
Serializable
if subclasses and all attribute values are Serializable
.
- Since:
- 2.0
- Author:
- Rob Harrop, Juergen Hoeller, Sam Brannen
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionString[]
Return the names of all attributes.<T> T
computeAttribute
(String name, Function<String, T> computeFunction) Compute a new value for the attribute identified byname
if necessary and set the new value in thisAttributeAccessor
.protected void
copyAttributesFrom
(AttributeAccessor source) Copy the attributes from the supplied AttributeAccessor to this accessor.boolean
getAttribute
(String name) Get the value of the attribute identified byname
.boolean
hasAttribute
(String name) Returntrue
if the attribute identified byname
exists.int
hashCode()
removeAttribute
(String name) Remove the attribute identified byname
and return its value.void
setAttribute
(String name, Object value) Set the attribute defined byname
to the suppliedvalue
.
-
Constructor Details
-
AttributeAccessorSupport
public AttributeAccessorSupport()
-
-
Method Details
-
setAttribute
Description copied from interface:AttributeAccessor
Set the attribute defined byname
to the suppliedvalue
.If
value
isnull
, the attribute isremoved
.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.
- Specified by:
setAttribute
in interfaceAttributeAccessor
- Parameters:
name
- the unique attribute keyvalue
- the attribute value to be attached
-
getAttribute
Description copied from interface:AttributeAccessor
Get the value of the attribute identified byname
.Return
null
if the attribute doesn't exist.- Specified by:
getAttribute
in interfaceAttributeAccessor
- Parameters:
name
- the unique attribute key- Returns:
- the current value of the attribute, if any
-
computeAttribute
Description copied from interface:AttributeAccessor
Compute a new value for the attribute identified byname
if necessary and set the new value in thisAttributeAccessor
.If a value for the attribute identified by
name
already exists in thisAttributeAccessor
, 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.
- Specified by:
computeAttribute
in interfaceAttributeAccessor
- Type Parameters:
T
- the type of the attribute value- Parameters:
name
- the unique attribute keycomputeFunction
- a function that computes a new value for the attribute name; the function must not return anull
value- Returns:
- the existing value or newly computed value for the named attribute
- See Also:
-
removeAttribute
Description copied from interface:AttributeAccessor
Remove the attribute identified byname
and return its value.Return
null
if no attribute undername
is found.- Specified by:
removeAttribute
in interfaceAttributeAccessor
- Parameters:
name
- the unique attribute key- Returns:
- the last value of the attribute, if any
-
hasAttribute
Description copied from interface:AttributeAccessor
Returntrue
if the attribute identified byname
exists.Otherwise return
false
.- Specified by:
hasAttribute
in interfaceAttributeAccessor
- Parameters:
name
- the unique attribute key
-
attributeNames
Description copied from interface:AttributeAccessor
Return the names of all attributes.- Specified by:
attributeNames
in interfaceAttributeAccessor
-
copyAttributesFrom
Copy the attributes from the supplied AttributeAccessor to this accessor.- Parameters:
source
- the AttributeAccessor to copy from
-
equals
-
hashCode
public int hashCode()
-