Package dev.getelements.elements.sdk
Interface Attributes
- All Known Subinterfaces:
MutableAttributes
- All Known Implementing Classes:
GuiceAttributes,ImmutableAttributes,InheritedAttributes,InheritedMutableAttributes,PropertiesAttributes,ServletRequestAttributes,SimpleAttributes
public interface Attributes
Contains attributes which represent contextual information for various types.
The test for
Object.equals(Object) and Object.hashCode() should be implemented using the provided
static methods in this interface, or an equivalent algorithm. Many Attributes implementations exist and the
most reliable means must be determined by the contents as they are accessible through this interface and not in an
implementation specific way. Failure to do so may result in poor cache performance as Attributes may be a
component of a cache key in some parts of the application.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordRepresents a singleAttributes.Attribute. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionasMap()Returns a view of thisAttributesobject as aMap<String,.Object> default PropertiesReturns thisAttributesas aPropertiesinstance, copying all attributes over.default PropertiesasProperties(Properties defaults) Returns thisAttributesas aPropertiesinstance.static AttributesReturnsEMPTY.static booleanequals(Attributes a, Attributes b) Tests if twoAttributesare equal to each other.static booleanequals(Attributes a, Object b) Test if the suppliedAttributesis equal to the otherObjectby first testing if it an instance ofAttributesas well as ifequals(Attributes, Attributes)returns true.default ObjectgetAttribute(String name) Gets the attribute associated with thisAttributesfor the given name.getAttributeOptional(String name) Gets the attribute associated with thisAttributesobject.static inthashCode(Attributes attributes) Given a set ofAttributes, this will determined is hash code.Returns a copy of thisAttributesas an immutable copy.default Stream<Attributes.Attribute<Object>> stream()Gets allAttributes.Attributes as aStream.
-
Field Details
-
EMPTY
The emptyAttributesimplementation. This returns an empty list of attribute names, and will return null for any requested attribute.
-
-
Method Details
-
getAttributeNames
-
stream
Gets allAttributes.Attributes as aStream.- Returns:
- a
StreamofAttributes.Attributes
-
getAttribute
Gets the attribute associated with thisAttributesfor the given name. Returning null if no such attribute is found. Note that an attribute may exist with the supplied name and the value null. In order to distinguish from this, the methodgetAttributeOptional(String)may be used.- Parameters:
name- the name of hte attribute- Returns:
- the value or null
-
getAttributeOptional
Gets the attribute associated with thisAttributesobject. -
immutableCopy
Attributes immutableCopy()Returns a copy of thisAttributesas an immutable copy. Alternatively, if this instance is already immutable, then this will return this instance.- Returns:
- an immutable copy of this
Attributes
-
asMap
Returns a view of thisAttributesobject as aMap<String,.Object> - Returns:
- this
Attributesas aMap<String,Object>
-
asProperties
Returns thisAttributesas aPropertiesinstance, copying all attributes over.- Returns:
- the
Properties
-
asProperties
Returns thisAttributesas aPropertiesinstance.- Parameters:
defaults- the default properties to use- Returns:
- the
Properties
-
emptyAttributes
ReturnsEMPTY.- Returns:
EMPTY
-
hashCode
Given a set ofAttributes, this will determined is hash code. This must be consistent with the rules ofObject.hashCode()andequals(Attributes, Attributes)- Parameters:
attributes- theAttributes- Returns:
- the hash code
-
equals
Test if the suppliedAttributesis equal to the otherObjectby first testing if it an instance ofAttributesas well as ifequals(Attributes, Attributes)returns true.- Parameters:
a- the attributes objectb- another obect- Returns:
- true if equal, false otherwise.
-
equals
Tests if twoAttributesare equal to each other. This is used by subclasses toprovide a universal test for equality against another instance ofAttributes. Generally equality is defined as follows:- The names of all attributes are the same (order notwithstanding)
- The name set of all attributes are equal in size.
- Each individual attribute is equal (as determined by
Object.equals(Object)
- Parameters:
a- the firstAttributesb- the secondAttributes- Returns:
- true if equals, false otherwise.
-