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
@Immutable public abstract class ImmutableKeyValuePairs<K,V> extends java.lang.ObjectAn immutable set of key-value pairs.Key-value pairs are dropped for
nullor 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.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedImmutableKeyValuePairs(java.lang.Object[] data)Stores the raw object data directly.protectedImmutableKeyValuePairs(java.lang.Object[] data, java.util.Comparator<?> keyComparator)Sorts and dedupes the key/value pairs indata.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<K,V>asMap()private static <K> intcompareToNullSafe(K key, K pivotKey, java.util.Comparator<K> keyComparator)protected java.util.List<java.lang.Object>data()private static <K> java.lang.Object[]dedupe(java.lang.Object[] data, java.util.Comparator<K> keyComparator)booleanequals(java.lang.Object o)voidforEach(java.util.function.BiConsumer<? super K,? super V> consumer)Iterates over all the key-value pairs of labels contained by this instance.Vget(K key)Returns the value for the givenkey, ornullif the key is not present.java.lang.Object[]getData()Return the backing data array for these attributes.inthashCode()booleanisEmpty()private static <K> voidmerge(java.lang.Object[] sourceArray, int beginIndex, int middleIndex, int endIndex, java.lang.Object[] targetArray, java.util.Comparator<K> keyComparator)Left source half is sourceArray[ beginIndex:middleIndex-1].private static voidmergeSort(java.lang.Object[] data, java.util.Comparator<?> keyComparator)intsize()private static java.lang.Object[]sortAndFilter(java.lang.Object[] data, java.util.Comparator<?> keyComparator)Sorts and dedupes the key/value pairs indata.private static voidsplitAndMerge(java.lang.Object[] workArray, int beginIndex, int endIndex, java.lang.Object[] targetArray, java.util.Comparator<?> keyComparator)Sort the given run of array targetArray[] using array workArray[] as a source.java.lang.StringtoString()
-
-
-
Constructor Detail
-
ImmutableKeyValuePairs
protected ImmutableKeyValuePairs(java.lang.Object[] data)
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
protected ImmutableKeyValuePairs(java.lang.Object[] data, java.util.Comparator<?> keyComparator)Sorts and dedupes the key/value pairs indata.nullvalues will be removed. Keys will be compared with the givenComparator.
-
-
Method Detail
-
data
protected final java.util.List<java.lang.Object> data()
-
size
public final int size()
-
isEmpty
public final boolean isEmpty()
-
get
@Nullable public final V get(K key)
Returns the value for the givenkey, ornullif the key is not present.
-
forEach
public final void forEach(java.util.function.BiConsumer<? super K,? super V> consumer)
Iterates over all the key-value pairs of labels contained by this instance.
-
sortAndFilter
private static java.lang.Object[] sortAndFilter(java.lang.Object[] data, java.util.Comparator<?> keyComparator)Sorts and dedupes the key/value pairs indata.nullvalues will be removed. Keys will be compared with the givenComparator.
-
mergeSort
private static void mergeSort(java.lang.Object[] data, java.util.Comparator<?> keyComparator)
-
splitAndMerge
private static void splitAndMerge(java.lang.Object[] workArray, int beginIndex, int endIndex, java.lang.Object[] targetArray, java.util.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(java.lang.Object[] sourceArray, int beginIndex, int middleIndex, int endIndex, java.lang.Object[] targetArray, java.util.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, java.util.Comparator<K> keyComparator)
-
dedupe
private static <K> java.lang.Object[] dedupe(java.lang.Object[] data, java.util.Comparator<K> keyComparator)
-
equals
public boolean equals(@Nullable java.lang.Object o)- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getData
public java.lang.Object[] 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.
-
-