Package com.linecorp.armeria.common
Interface AttributesGetters
- All Known Subinterfaces:
Attributes
,ConcurrentAttributes
Provides the getter methods to
Attributes
and ConcurrentAttributes
.-
Method Summary
Modifier and TypeMethodDescription<T> T
attr
(AttributeKey<T> key) Returns the value associated with the givenAttributeKey
ornull
if there's no value set byAttributesSetters.set(AttributeKey, Object)
.attrs()
default boolean
hasAttr
(AttributeKey<?> key) default boolean
hasOwnAttr
(AttributeKey<?> key) boolean
isEmpty()
Returnstrue
if thisAttributesGetters
does not contain any entries.<T> T
ownAttr
(AttributeKey<T> key) Returns the value associated with the givenAttributeKey
ornull
if there's no value set byAttributesBuilder.set(AttributeKey, Object)
.ownAttrs()
parent()
Returns theparent()
which was specified when creating thisAttributesGetters
.int
size()
Returns the number ofAttributeKey
-value mappings in thisAttributesGetters
.
-
Method Details
-
attr
Returns the value associated with the givenAttributeKey
ornull
if there's no value set byAttributesSetters.set(AttributeKey, Object)
. If there is no value in thisAttributesGetters
but it exists inparent()
, the value in theparent()
} will be returned.- See Also:
-
ownAttr
Returns the value associated with the givenAttributeKey
ornull
if there's no value set byAttributesBuilder.set(AttributeKey, Object)
.Unlike
attr(AttributeKey)
, this does not search inparent()
.- See Also:
-
hasAttr
- See Also:
-
hasOwnAttr
Returnstrue
if and only if the value associated with the specifiedAttributeKey
is notnull
.Unlike
hasAttr(AttributeKey)
, this does not search inparent()
.- See Also:
-
ownAttrs
Iterator<Map.Entry<AttributeKey<?>,Object>> ownAttrs()Returns theIterator
of allMap.Entry
s thisAttributesGetters
contains.Unlike
For example:attrs()
, this does not iterateparent()
}.static final AttributeKey<String> USER_ID = AttributeKey.valueOf("USER_ID"); static final AttributeKey<String> SECRET_TOKEN = AttributeKey.valueOf("SECRET_TOKEN"); static final AttributeKey<String> TRACE_ID = AttributeKey.valueOf("TRACE_ID"); Attributes parent = Attributes.of(USER_ID, "Meri Kim", SECRET_TOKEN, "secret-1"); Attributes child = Attributes.builder(parent) .set(SECRET_TOKEN, "secret-2") .set(TRACE_ID, "trace-1") .build(); Iterator<Entry<AttributeKey<?>, Object>> attrs = child.ownAttrs(); assert Iterables.size(attrs) == 2; assert Streams.stream(child.attrs()) .map(Entry::getValue) .sorted() .collect(Collectors.toList()) .equals(List.of("secret-2", "trace-1"));
- See Also:
-
attrs
Iterator<Map.Entry<AttributeKey<?>,Object>> attrs()Returns theIterator
of allMap.Entry
s thisAttributesGetters
contains.The
Iterator
returned by this method will also yield theMap.Entry
s from theparent()
} except those whoseAttributeKey
exist already in this context. For example:static final AttributeKey<String> USER_ID = AttributeKey.valueOf("USER_ID"); static final AttributeKey<String> SECRET_TOKEN = AttributeKey.valueOf("SECRET_TOKEN"); static final AttributeKey<String> TRACE_ID = AttributeKey.valueOf("TRACE_ID"); Attributes parent = Attributes.of(USER_ID, "Meri Kim", SECRET_TOKEN, "secret-1"); Attributes child = Attributes.builder(parent) .set(SECRET_TOKEN, "secret-2") .set(TRACE_ID, "trace-1") .build(); Iterator<Entry<AttributeKey<?>, Object>> attrs = child.attrs(); assert Iterables.size(attrs) == 3; assert Streams.stream(child.attrs()) .map(Entry::getValue) .sorted() .collect(Collectors.toList()) // "secret-1" is overridden by "secret-2" .equals(List.of("Meri Kim", "secret-2", "trace-1"));
-
parent
Returns theparent()
which was specified when creating thisAttributesGetters
.- See Also:
-
isEmpty
boolean isEmpty()Returnstrue
if thisAttributesGetters
does not contain any entries. -
size
int size()Returns the number ofAttributeKey
-value mappings in thisAttributesGetters
.If the same
AttributeKey
is both in theparent()
and the childAttributes
, only theAttributeKey
-value mapping in the child will be counted.static final AttributeKey<String> USER_ID = AttributeKey.valueOf("USER_ID"); static final AttributeKey<String> SECRET_TOKEN = AttributeKey.valueOf("SECRET_TOKEN"); static final AttributeKey<String> TRACE_ID = AttributeKey.valueOf("TRACE_ID"); Attributes parent = Attributes.of(USER_ID, "Meri Kim", SECRET_TOKEN, "secret-1"); assert parent.size() == 2; Attributes child = Attributes.builder(parent) .set(SECRET_TOKEN, "secret-2") .set(TRACE_ID, "trace-1") .build(); assert child.size() == 3;
-