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 record
Represents a singleAttributes.Attribute
. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionasMap()
Returns a view of thisAttributes
object as aMap<String,
.Object> default Properties
Returns thisAttributes
as aProperties
instance, copying all attributes over.default Properties
asProperties
(Properties defaults) Returns thisAttributes
as aProperties
instance.static Attributes
ReturnsEMPTY
.static boolean
equals
(Attributes a, Attributes b) Tests if twoAttributes
are equal to each other.static boolean
equals
(Attributes a, Object b) Test if the suppliedAttributes
is equal to the otherObject
by first testing if it an instance ofAttributes
as well as ifequals(Attributes, Attributes)
returns true.default Object
getAttribute
(String name) Gets the attribute associated with thisAttributes
for the given name.getAttributeOptional
(String name) Gets the attribute associated with thisAttributes
object.static int
hashCode
(Attributes attributes) Given a set ofAttributes
, this will determined is hash code.Returns a copy of thisAttributes
as an immutable copy.default Stream
<Attributes.Attribute<Object>> stream()
Gets allAttributes.Attribute
s as aStream
.
-
Field Details
-
EMPTY
The emptyAttributes
implementation. This returns an empty list of attribute names, and will return null for any requested attribute.
-
-
Method Details
-
getAttributeNames
-
stream
Gets allAttributes.Attribute
s as aStream
.- Returns:
- a
Stream
ofAttributes.Attribute
s
-
getAttribute
Gets the attribute associated with thisAttributes
for 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 thisAttributes
object. -
immutableCopy
Attributes immutableCopy()Returns a copy of thisAttributes
as 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 thisAttributes
object as aMap<String,
.Object> - Returns:
- this
Attributes
as aMap<String,
Object>
-
asProperties
Returns thisAttributes
as aProperties
instance, copying all attributes over.- Returns:
- the
Properties
-
asProperties
Returns thisAttributes
as aProperties
instance.- 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 suppliedAttributes
is equal to the otherObject
by first testing if it an instance ofAttributes
as well as ifequals(Attributes, Attributes)
returns true.- Parameters:
a
- the attributes objectb
- another obect- Returns:
- true if equal, false otherwise.
-
equals
Tests if twoAttributes
are 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 firstAttributes
b
- the secondAttributes
- Returns:
- true if equals, false otherwise.
-