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 Details

    • AttributeAccessorSupport

      public AttributeAccessorSupport()
  • Method Details

    • setAttribute

      public void setAttribute(String name, @Nullable Object value)
      Description copied from interface: AttributeAccessor
      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.

      Specified by:
      setAttribute in interface AttributeAccessor
      Parameters:
      name - the unique attribute key
      value - the attribute value to be attached
    • getAttribute

      @Nullable public Object getAttribute(String name)
      Description copied from interface: AttributeAccessor
      Get the value of the attribute identified by name.

      Return null if the attribute doesn't exist.

      Specified by:
      getAttribute in interface AttributeAccessor
      Parameters:
      name - the unique attribute key
      Returns:
      the current value of the attribute, if any
    • computeAttribute

      public <T> T computeAttribute(String name, Function<String,T> computeFunction)
      Description copied from interface: AttributeAccessor
      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.

      Specified by:
      computeAttribute in interface AttributeAccessor
      Type Parameters:
      T - the type of the attribute value
      Parameters:
      name - the unique attribute key
      computeFunction - a function that computes a new value for the attribute name; the function must not return a null value
      Returns:
      the existing value or newly computed value for the named attribute
      See Also:
    • removeAttribute

      @Nullable public Object removeAttribute(String name)
      Description copied from interface: AttributeAccessor
      Remove the attribute identified by name and return its value.

      Return null if no attribute under name is found.

      Specified by:
      removeAttribute in interface AttributeAccessor
      Parameters:
      name - the unique attribute key
      Returns:
      the last value of the attribute, if any
    • hasAttribute

      public boolean hasAttribute(String name)
      Description copied from interface: AttributeAccessor
      Return true if the attribute identified by name exists.

      Otherwise return false.

      Specified by:
      hasAttribute in interface AttributeAccessor
      Parameters:
      name - the unique attribute key
    • attributeNames

      public String[] attributeNames()
      Description copied from interface: AttributeAccessor
      Return the names of all attributes.
      Specified by:
      attributeNames in interface AttributeAccessor
    • copyAttributesFrom

      protected void copyAttributesFrom(AttributeAccessor source)
      Copy the attributes from the supplied AttributeAccessor to this accessor.
      Parameters:
      source - the AttributeAccessor to copy from
    • equals

      public boolean equals(@Nullable Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object