Record Class Tag

java.lang.Object
java.lang.Record
cloud.opencode.base.observability.metric.Tag
Record Components:
key - the tag key, must not be null or blank | 标签键,不能为 null 或空白
value - the tag value, must not be null | 标签值,不能为 null

public record Tag(String key, String value) extends Record
Tag - A key-value pair for metric dimensioning Tag - 用于指标维度化的键值对

Tags provide dimensional metadata to metrics, enabling filtering and grouping in monitoring systems. Keys must be non-blank; values must be non-null.

标签为指标提供维度元数据,支持监控系统中的过滤和分组。 键不能为空白;值不能为 null。

Since:
JDK 25, opencode-base-observability V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Tag(String key, String value)
    Compact constructor with validation.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    key()
    Returns the value of the key record component.
    static Tag
    of(String key, String value)
    Creates a new Tag with the given key and value.
    final String
    Returns a string representation of this record class.
    Returns the value of the value record component.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Tag

      public Tag(String key, String value)
      Compact constructor with validation. 紧凑构造器,包含参数验证。
  • Method Details

    • of

      public static Tag of(String key, String value)
      Creates a new Tag with the given key and value. 使用给定的键和值创建新标签。
      Parameters:
      key - the tag key | 标签键
      value - the tag value | 标签值
      Returns:
      a new Tag instance | 新的 Tag 实例
      Throws:
      ObservabilityException - if key is null/blank or value is null | 如果键为 null/空白或值为 null
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • key

      public String key()
      Returns the value of the key record component.
      Returns:
      the value of the key record component
    • value

      public String value()
      Returns the value of the value record component.
      Returns:
      the value of the value record component