Extract foreach implementation in the super class (#2690)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
This commit is contained in:
parent
009e1c8054
commit
88bbdc86d1
|
@ -13,7 +13,6 @@ import io.opentelemetry.api.internal.StringUtils;
|
|||
import io.opentelemetry.context.Context;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
|
@ -35,14 +34,6 @@ abstract class ImmutableBaggage extends ImmutableKeyValuePairs<String, BaggageEn
|
|||
@Override
|
||||
protected abstract List<Object> data();
|
||||
|
||||
@Override
|
||||
public void forEach(BiConsumer<String, BaggageEntry> consumer) {
|
||||
for (int i = 0; i < data().size(); i += 2) {
|
||||
ImmutableEntry entry = (ImmutableEntry) data().get(i + 1);
|
||||
consumer.accept((String) data().get(i), entry);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getEntryValue(String entryKey) {
|
||||
|
|
|
@ -10,7 +10,6 @@ import io.opentelemetry.api.internal.ImmutableKeyValuePairs;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@AutoValue
|
||||
|
@ -35,15 +34,6 @@ abstract class ArrayBackedAttributes extends ImmutableKeyValuePairs<AttributeKey
|
|||
return new ArrayBackedAttributesBuilder(new ArrayList<>(data()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void forEach(BiConsumer<AttributeKey<?>, Object> consumer) {
|
||||
List<Object> data = data();
|
||||
for (int i = 0; i < data.size(); i += 2) {
|
||||
consumer.accept((AttributeKey<?>) data.get(i), data.get(i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T get(AttributeKey<T> key) {
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.util.Collections;
|
|||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
|
@ -55,6 +56,14 @@ public abstract class ImmutableKeyValuePairs<K, V> {
|
|||
return null;
|
||||
}
|
||||
|
||||
/** Iterates over all the key-value pairs of labels contained by this instance. */
|
||||
@SuppressWarnings("unchecked")
|
||||
public void forEach(BiConsumer<K, V> consumer) {
|
||||
for (int i = 0; i < data().size(); i += 2) {
|
||||
consumer.accept((K) data().get(i), (V) data().get(i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts and dedupes the key/value pairs in {@code data}. If {@code filterNullValues} is {@code
|
||||
* true}, {@code null} values will be removed. Keys must be {@link Comparable}.
|
||||
|
|
|
@ -8,7 +8,6 @@ package io.opentelemetry.api.metrics.common;
|
|||
import com.google.auto.value.AutoValue;
|
||||
import io.opentelemetry.api.internal.ImmutableKeyValuePairs;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@AutoValue
|
||||
|
@ -25,14 +24,6 @@ abstract class ArrayBackedLabels extends ImmutableKeyValuePairs<String, String>
|
|||
@Override
|
||||
protected abstract List<Object> data();
|
||||
|
||||
@Override
|
||||
public void forEach(BiConsumer<String, String> consumer) {
|
||||
List<Object> data = data();
|
||||
for (int i = 0; i < data.size(); i += 2) {
|
||||
consumer.accept((String) data.get(i), (String) data.get(i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
static Labels sortAndFilterToLabels(Object... data) {
|
||||
return new AutoValue_ArrayBackedLabels(sortAndFilter(data, /* filterNullValues= */ false));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue