Top Description Fields Constructors Methods
org.springframework.core

public abstract Class AttributeAccessorSupport

extends Object
implements AttributeAccessor, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.springframework.core.AttributeAccessor
Annotations
@SuppressWarnings:serial
Imports
java.io.Serializable, java.util.LinkedHashMap, .Map, java.util.function.Function, org.springframework.lang.Nullable, org.springframework.util.Assert, .StringUtils

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.

Authors
Rob Harrop, Juergen Hoeller, Sam Brannen
Since
2.0

Field Summary

Modifier and TypeField and Description
private final Map<String, Object>
attributes

Map with String keys and Object values.

Constructor Summary

AccessConstructor and Description
public

Method Summary

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

Implements org.springframework.core.AttributeAccessor.attributeNames.

Return the names of all attributes.

public <T> T
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
)

Overrides default org.springframework.core.AttributeAccessor.computeAttribute.

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

protected void
copyAttributesFrom(AttributeAccessor
the AttributeAccessor to copy from
source
)

Copy the attributes from the supplied AttributeAccessor to this accessor.

public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public Object
getAttribute(String
the unique attribute key
name
)

Implements org.springframework.core.AttributeAccessor.getAttribute.

Get the value of the attribute identified by name.

public boolean
hasAttribute(String
the unique attribute key
name
)

Implements org.springframework.core.AttributeAccessor.hasAttribute.

Return true if the attribute identified by name exists.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public Object
removeAttribute(String
the unique attribute key
name
)

Implements org.springframework.core.AttributeAccessor.removeAttribute.

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
)

Implements org.springframework.core.AttributeAccessor.setAttribute.

Set the attribute defined by name to the supplied value.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

attributesback to summary
private final Map<String, Object> attributes

Map with String keys and Object values.

Constructor Detail

AttributeAccessorSupportback to summary
public AttributeAccessorSupport()

Method Detail

attributeNamesback to summary
public String[] attributeNames()

Implements org.springframework.core.AttributeAccessor.attributeNames.

Doc from org.springframework.core.AttributeAccessor.attributeNames.

Return the names of all attributes.

Annotations
@Override
computeAttributeback to summary
public <T> T computeAttribute(String name, Function<String, T> computeFunction)

Overrides default org.springframework.core.AttributeAccessor.computeAttribute.

Doc from org.springframework.core.AttributeAccessor.computeAttribute.

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
@Override
@SuppressWarnings:unchecked
copyAttributesFromback to summary
protected void copyAttributesFrom(AttributeAccessor source)

Copy the attributes from the supplied AttributeAccessor to this accessor.

Parameters
source:AttributeAccessor

the AttributeAccessor to copy from

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getAttributeback to summary
public Object getAttribute(String name)

Implements org.springframework.core.AttributeAccessor.getAttribute.

Doc from org.springframework.core.AttributeAccessor.getAttribute.

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
@Override
@Nullable
hasAttributeback to summary
public boolean hasAttribute(String name)

Implements org.springframework.core.AttributeAccessor.hasAttribute.

Doc from org.springframework.core.AttributeAccessor.hasAttribute.

Return true if the attribute identified by name exists.

Otherwise return false.

Parameters
name:String

the unique attribute key

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
removeAttributeback to summary
public Object removeAttribute(String name)

Implements org.springframework.core.AttributeAccessor.removeAttribute.

Doc from org.springframework.core.AttributeAccessor.removeAttribute.

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
@Override
@Nullable
setAttributeback to summary
public void setAttribute(String name, Object value)

Implements org.springframework.core.AttributeAccessor.setAttribute.

Doc from org.springframework.core.AttributeAccessor.setAttribute.

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

Annotations
@Override