Record Class HashNode<T>

java.lang.Object
java.lang.Record
cloud.opencode.base.hash.consistent.HashNode<T>
Type Parameters:
T - data type | 数据类型

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
  • Null-safe: Yes (validates inputs) - 空值安全: 是(验证输入)
Record Components:
id - unique node identifier | 唯一节点标识符
data - node data | 节点数据
weight - node weight (affects virtual node count) | 节点权重(影响虚拟节点数量)

public record HashNode<T>(String id, T data, int weight) extends Record
Hash ring node representation 哈希环节点表示

Represents a physical node in a consistent hash ring with an identifier, associated data, and weight for load balancing.

表示一致性哈希环中的物理节点,包含标识符、关联数据和用于负载均衡的权重。

Features | 主要功能:

  • Unique identifier - 唯一标识符
  • Associated data - 关联数据
  • Weight for load balancing - 用于负载均衡的权重

Usage Examples | 使用示例:

// Create a node with default weight
HashNode<String> node = HashNode.of("server1", "192.168.1.1");

// Create a weighted node
HashNode<String> weighted = HashNode.of("server2", "192.168.1.2", 2);
Since:
JDK 25, opencode-base-hash V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    HashNode(String id, T data, int weight)
    Compact constructor with validation 带验证的紧凑构造函数
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value of the data record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    id()
    Returns the value of the id record component.
    static <T> HashNode<T>
    of(String id, T data)
    Creates a node with default weight (1) 使用默认权重(1)创建节点
    static <T> HashNode<T>
    of(String id, T data, int weight)
    Creates a weighted node 创建带权重的节点
    Returns a string representation of this record class.
    int
    Returns the value of the weight record component.

    Methods inherited from class Object

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

    • HashNode

      public HashNode(String id, T data, int weight)
      Compact constructor with validation 带验证的紧凑构造函数
  • Method Details

    • of

      public static <T> HashNode<T> of(String id, T data)
      Creates a node with default weight (1) 使用默认权重(1)创建节点
      Type Parameters:
      T - data type | 数据类型
      Parameters:
      id - node id | 节点ID
      data - node data | 节点数据
      Returns:
      hash node | 哈希节点
    • of

      public static <T> HashNode<T> of(String id, T data, int weight)
      Creates a weighted node 创建带权重的节点
      Type Parameters:
      T - data type | 数据类型
      Parameters:
      id - node id | 节点ID
      data - node data | 节点数据
      weight - node weight | 节点权重
      Returns:
      hash node | 哈希节点
    • toString

      public 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      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.
    • id

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

      public T data()
      Returns the value of the data record component.
      Returns:
      the value of the data record component
    • weight

      public int weight()
      Returns the value of the weight record component.
      Returns:
      the value of the weight record component