Package io.opentelemetry.api.internal
Class ImmutableKeyValuePairs<K,V>
java.lang.Object
io.opentelemetry.api.internal.ImmutableKeyValuePairs<K,V>
- Type Parameters:
V- The type of the values contained in this.
- Direct Known Subclasses:
ArrayBackedAttributes,ImmutableBaggage
An immutable set of key-value pairs.
Key-value pairs are dropped for null or empty keys.
Note: for subclasses of this, null keys will be removed, but if your key has another concept of being "empty", you'll need to remove them before calling the constructor, assuming you don't want the "empty" keys to be kept in your collection.
This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedImmutableKeyValuePairs(Object[] data) Stores the raw object data directly.protectedImmutableKeyValuePairs(Object[] data, Comparator<?> keyComparator) Sorts and dedupes the key/value pairs indata. -
Method Summary
Modifier and TypeMethodDescriptionasMap()private static <K> intcompareToNullSafe(K key, K pivotKey, Comparator<K> keyComparator) data()private static <K> Object[]dedupe(Object[] data, Comparator<K> keyComparator) booleanfinal voidforEach(BiConsumer<? super K, ? super V> consumer) Iterates over all the key-value pairs of labels contained by this instance.final VReturns the value for the givenkey, ornullif the key is not present.Object[]getData()Return the backing data array for these attributes.inthashCode()final booleanisEmpty()private static <K> voidmerge(Object[] sourceArray, int beginIndex, int middleIndex, int endIndex, Object[] targetArray, Comparator<K> keyComparator) Left source half is sourceArray[ beginIndex:middleIndex-1].private static voidmergeSort(Object[] data, Comparator<?> keyComparator) final intsize()private static Object[]sortAndFilter(Object[] data, Comparator<?> keyComparator) Sorts and dedupes the key/value pairs indata.private static voidsplitAndMerge(Object[] workArray, int beginIndex, int endIndex, Object[] targetArray, Comparator<?> keyComparator) Sort the given run of array targetArray[] using array workArray[] as a source.toString()
-
Field Details
-
data
-
hashcode
private int hashcode
-
-
Constructor Details
-
ImmutableKeyValuePairs
Stores the raw object data directly. Does not do any de-duping or sorting. If you use this constructor, you *must* guarantee that the data has been de-duped and sorted by key before it is passed here. -
ImmutableKeyValuePairs
Sorts and dedupes the key/value pairs indata.nullvalues will be removed. Keys will be compared with the givenComparator.
-
-
Method Details
-
data
-
size
public final int size() -
isEmpty
public final boolean isEmpty() -
asMap
-
get
Returns the value for the givenkey, ornullif the key is not present. -
forEach
Iterates over all the key-value pairs of labels contained by this instance. -
sortAndFilter
Sorts and dedupes the key/value pairs indata.nullvalues will be removed. Keys will be compared with the givenComparator. -
mergeSort
-
splitAndMerge
private static void splitAndMerge(Object[] workArray, int beginIndex, int endIndex, Object[] targetArray, Comparator<?> keyComparator) Sort the given run of array targetArray[] using array workArray[] as a source. beginIndex is inclusive; endIndex is exclusive (targetArray[endIndex] is not in the set). -
merge
private static <K> void merge(Object[] sourceArray, int beginIndex, int middleIndex, int endIndex, Object[] targetArray, Comparator<K> keyComparator) Left source half is sourceArray[ beginIndex:middleIndex-1]. Right source half is sourceArray[ middleIndex:endIndex-1]. Result is targetArray[ beginIndex:endIndex-1]. -
compareToNullSafe
private static <K> int compareToNullSafe(@Nullable K key, @Nullable K pivotKey, Comparator<K> keyComparator) -
dedupe
-
equals
-
hashCode
public int hashCode() -
toString
-
getData
Return the backing data array for these attributes. This is only exposed for internal use by opentelemetry authors. The contents of the array MUST NOT be modified.
-