All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aliyun.openservices.shade.io.opentelemetry.api.trace.ArrayBasedTraceState Maven / Gradle / Ivy

There is a newer version: 1.9.4.Final
Show newest version
/*
 * Copyright The OpenTelemetry Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package com.aliyun.openservices.shade.com.aliyun.openservices.shade.io.opentelemetry.api.trace;

import com.aliyun.openservices.shade.com.aliyun.openservices.shade.com.google.auto.value.AutoValue;
import com.aliyun.openservices.shade.com.aliyun.openservices.shade.io.opentelemetry.api.internal.ReadOnlyArrayMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

@Immutable
@AutoValue
abstract class ArrayBasedTraceState implements TraceState {

  @Override
  @Nullable
  public String get(String key) {
    if (key == null) {
      return null;
    }
    List entries = getEntries();
    for (int i = 0; i < entries.size(); i += 2) {
      if (entries.get(i).equals(key)) {
        return entries.get(i + 1);
      }
    }
    return null;
  }

  @Override
  public int size() {
    return getEntries().size() / 2;
  }

  @Override
  public boolean isEmpty() {
    return getEntries().isEmpty();
  }

  @Override
  public void forEach(BiConsumer consumer) {
    if (consumer == null) {
      return;
    }
    List entries = getEntries();
    for (int i = 0; i < entries.size(); i += 2) {
      consumer.accept(entries.get(i), entries.get(i + 1));
    }
  }

  @Override
  @SuppressWarnings({"unchecked", "rawtypes"})
  public Map asMap() {
    return ReadOnlyArrayMap.wrap((List) getEntries());
  }

  abstract List getEntries();

  @Override
  public TraceStateBuilder toBuilder() {
    return new ArrayBasedTraceStateBuilder(this);
  }

  static ArrayBasedTraceState create(List entries) {
    return new AutoValue_ArrayBasedTraceState(entries);
  }

  ArrayBasedTraceState() {}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy