001package io.prometheus.metrics.model.snapshots;
002
003import java.util.Objects;
004
005/** Utility for iterating over {@link Labels}. */
006public final class Label implements Comparable<Label> {
007
008  private final String name;
009  private final String value;
010
011  public Label(String name, String value) {
012    this.name = name;
013    this.value = value;
014  }
015
016  public String getName() {
017    return name;
018  }
019
020  public String getValue() {
021    return value;
022  }
023
024  @Override
025  public int compareTo(Label other) {
026    int nameCompare = name.compareTo(other.name);
027    return nameCompare != 0 ? nameCompare : value.compareTo(other.value);
028  }
029
030  @Override
031  public String toString() {
032    return "Label{" + "name='" + name + '\'' + ", value='" + value + '\'' + '}';
033  }
034
035  @Override
036  public boolean equals(Object o) {
037    if (this == o) {
038      return true;
039    }
040    if (o == null || getClass() != o.getClass()) {
041      return false;
042    }
043    Label label = (Label) o;
044    return Objects.equals(name, label.name) && Objects.equals(value, label.value);
045  }
046
047  @Override
048  public int hashCode() {
049    return Objects.hash(name, value);
050  }
051}