Class FilteredAttributes
- java.lang.Object
-
- io.opentelemetry.sdk.metrics.internal.view.FilteredAttributes
-
- All Implemented Interfaces:
Attributes
- Direct Known Subclasses:
FilteredAttributes.RegularFilteredAttributes
,FilteredAttributes.SmallFilteredAttributes
abstract class FilteredAttributes extends java.lang.Object implements Attributes
Filtered attributes is a filtered view of aImmutableKeyValuePairs
backedAttributes
instance. Rather than creating an entirely new attributes instance, it keeps track of which source attributes are excluded while implementing theAttributes
interface.Notably, the
equals(Object)
andhashCode()
depend on comparison against otherFilteredAttributes
instances. This means that whereFilteredAttributes
is used for things like map keys, it must be used for all keys in that map. You cannot mixAttributes
implementations. This is also true for the default attributes implementation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
FilteredAttributes.RegularFilteredAttributes
Implementation that can handle attributes of arbitrary size by storing filter status in aBitSet
.private static class
FilteredAttributes.SmallFilteredAttributes
Implementation that relies on the source having less thanFilteredAttributes.SmallFilteredAttributes.BITS_PER_INTEGER
attributes, and storing entry filter status in the bits of an integer.
-
Field Summary
Fields Modifier and Type Field Description private int
hashcode
private int
size
private java.lang.Object[]
sourceData
-
Constructor Summary
Constructors Modifier Constructor Description private
FilteredAttributes(java.lang.Object[] sourceData, int hashcode, int size)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.util.Map<AttributeKey<?>,java.lang.Object>
asMap()
Returns a read-only view of thisAttributes
as aMap
.private static Attributes
convertToStandardImplementation(Attributes source)
(package private) static Attributes
create(Attributes source, java.util.Set<AttributeKey<?>> includedKeys)
Create aFilteredAttributes
instance.boolean
equals(java.lang.Object object)
void
forEach(java.util.function.BiConsumer<? super AttributeKey<?>,? super java.lang.Object> consumer)
Iterates over all the key-value pairs of attributes contained by this instance.<T> T
get(AttributeKey<T> key)
Returns the value for the givenAttributeKey
, ornull
if not found.int
hashCode()
(package private) abstract boolean
includeIndexInOutput(int sourceIndex)
boolean
isEmpty()
Whether there are any attributes contained in this.private static <T> void
putInBuilder(AttributesBuilder builder, AttributeKey<T> key, T value)
int
size()
The number of attributes contained in this.AttributesBuilder
toBuilder()
Returns a newAttributesBuilder
instance populated with the data of thisAttributes
.java.lang.String
toString()
-
-
-
Method Detail
-
create
static Attributes create(Attributes source, java.util.Set<AttributeKey<?>> includedKeys)
Create aFilteredAttributes
instance.- Parameters:
source
- the source attributes, which SHOULD be based on the standardImmutableKeyValuePairs
. If not, the source will first be converted to the standard implementation.includedKeys
- the set of attribute keys to include in the output.
-
convertToStandardImplementation
private static Attributes convertToStandardImplementation(Attributes source)
-
get
@Nullable public <T> T get(AttributeKey<T> key)
Description copied from interface:Attributes
Returns the value for the givenAttributeKey
, ornull
if not found.- Specified by:
get
in interfaceAttributes
-
forEach
public void forEach(java.util.function.BiConsumer<? super AttributeKey<?>,? super java.lang.Object> consumer)
Description copied from interface:Attributes
Iterates over all the key-value pairs of attributes contained by this instance.- Specified by:
forEach
in interfaceAttributes
-
size
public int size()
Description copied from interface:Attributes
The number of attributes contained in this.- Specified by:
size
in interfaceAttributes
-
isEmpty
public boolean isEmpty()
Description copied from interface:Attributes
Whether there are any attributes contained in this.- Specified by:
isEmpty
in interfaceAttributes
-
asMap
public java.util.Map<AttributeKey<?>,java.lang.Object> asMap()
Description copied from interface:Attributes
Returns a read-only view of thisAttributes
as aMap
.- Specified by:
asMap
in interfaceAttributes
-
toBuilder
public AttributesBuilder toBuilder()
Description copied from interface:Attributes
Returns a newAttributesBuilder
instance populated with the data of thisAttributes
.- Specified by:
toBuilder
in interfaceAttributes
-
putInBuilder
private static <T> void putInBuilder(AttributesBuilder builder, AttributeKey<T> key, T value)
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
includeIndexInOutput
abstract boolean includeIndexInOutput(int sourceIndex)
-
-