Package io.opentelemetry.sdk.internal
Class AttributesMap
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<AttributeKey<?>,java.lang.Object>
-
- io.opentelemetry.sdk.internal.AttributesMap
-
- All Implemented Interfaces:
Attributes
,java.io.Serializable
,java.lang.Cloneable
,java.util.Map<AttributeKey<?>,java.lang.Object>
public final class AttributesMap extends java.util.HashMap<AttributeKey<?>,java.lang.Object> implements Attributes
A map with a fixed capacity that drops attributes when the map gets full, and which truncates string and array string attribute values to thelengthLimit
.This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private long
capacity
private int
lengthLimit
private static long
serialVersionUID
private int
totalAddedValues
-
Constructor Summary
Constructors Modifier Constructor Description private
AttributesMap(long capacity, int lengthLimit)
-
Method Summary
All Methods Static Methods Instance 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
.static AttributesMap
create(long capacity, int lengthLimit)
Create an instance.void
forEach(java.util.function.BiConsumer<? super AttributeKey<?>,? super java.lang.Object> action)
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
getTotalAddedValues()
Get the total number of attributes added, including those dropped for capcity limits.Attributes
immutableCopy()
Create an immutable copy of the attributes in this map.<T> void
put(AttributeKey<T> key, T value)
Add the attribute key value pair, applying capacity and length limits.AttributesBuilder
toBuilder()
Returns a newAttributesBuilder
instance populated with the data of thisAttributes
.java.lang.String
toString()
-
Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.opentelemetry.api.common.Attributes
isEmpty, size
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
capacity
private final long capacity
-
lengthLimit
private final int lengthLimit
-
totalAddedValues
private int totalAddedValues
-
-
Method Detail
-
create
public static AttributesMap create(long capacity, int lengthLimit)
Create an instance.- Parameters:
capacity
- the max number of attribute entrieslengthLimit
- the maximum length of string attributes
-
put
public <T> void put(AttributeKey<T> key, T value)
Add the attribute key value pair, applying capacity and length limits.
-
getTotalAddedValues
public int getTotalAddedValues()
Get the total number of attributes added, including those dropped for capcity limits.
-
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
-
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
-
forEach
public void forEach(java.util.function.BiConsumer<? super AttributeKey<?>,? super java.lang.Object> action)
Description copied from interface:Attributes
Iterates over all the key-value pairs of attributes contained by this instance.- Specified by:
forEach
in interfaceAttributes
- Specified by:
forEach
in interfacejava.util.Map<AttributeKey<?>,java.lang.Object>
- Overrides:
forEach
in classjava.util.HashMap<AttributeKey<?>,java.lang.Object>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.util.AbstractMap<AttributeKey<?>,java.lang.Object>
-
immutableCopy
public Attributes immutableCopy()
Create an immutable copy of the attributes in this map.
-
-