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

su.nlq.prometheus.jmx.bean.Labels Maven / Gradle / Ivy

There is a newer version: 0.8.0
Show newest version
package su.nlq.prometheus.jmx.bean;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
import java.util.StringJoiner;
import java.util.stream.IntStream;

public final class Labels {
  private final @NotNull List names = new ArrayList<>();
  private final @NotNull List values = new ArrayList<>();

  public void add(@NotNull String name, @NotNull String value) {
    if (!name.isEmpty() && !value.isEmpty()) {
      names.add(name);
      values.add(value);
    }
  }

  public @NotNull List getNames() {
    return names;
  }

  public @NotNull List getValues() {
    return values;
  }

  @Override
  public @NotNull String toString() {
    final StringJoiner joiner = new StringJoiner(", ");
    IntStream.range(0, Math.min(names.size(), values.size()))
        .mapToObj(index -> names.get(index) + ':' + values.get(index))
        .forEach(joiner::add);
    return joiner.toString();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy