Record Class MetricId

java.lang.Object
java.lang.Record
cloud.opencode.base.observability.metric.MetricId
Record Components:
name - the metric name, must not be null or blank | 指标名称,不能为 null 或空白
tags - the immutable sorted list of tags | 不可变的排序标签列表

public record MetricId(String name, List<Tag> tags) extends Record
MetricId - Unique identifier for a metric, composed of name and tags MetricId - 指标的唯一标识符,由名称和标签组成

Tags are defensively copied and sorted by key for consistent equality semantics. Two MetricIds with the same name and same tags (regardless of original order) are equal.

标签进行防御性拷贝并按键排序,以确保一致的相等性语义。 具有相同名称和相同标签(无论原始顺序)的两个 MetricId 相等。

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

    Constructors
    Constructor
    Description
    MetricId(String name, List<Tag> tags)
    Creates an instance of a MetricId record class.
  • 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.
    Returns the value of the name record component.
    static MetricId
    of(String name, Tag... tags)
    Creates a MetricId with the given name and optional tags.
    Returns the value of the tags record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class Object

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

    • MetricId

      public MetricId(String name, List<Tag> tags)
      Creates an instance of a MetricId record class.
      Parameters:
      name - the value for the name record component
      tags - the value for the tags record component
  • Method Details

    • of

      public static MetricId of(String name, Tag... tags)
      Creates a MetricId with the given name and optional tags. 使用给定名称和可选标签创建 MetricId。
      Parameters:
      name - the metric name | 指标名称
      tags - the tags | 标签
      Returns:
      a new MetricId instance | 新的 MetricId 实例
      Throws:
      ObservabilityException - if name is null or blank | 如果名称为 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.
    • name

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

      public List<Tag> tags()
      Returns the value of the tags record component.
      Returns:
      the value of the tags record component