Record Class ConfigChangeEvent

java.lang.Object
java.lang.Record
cloud.opencode.base.config.ConfigChangeEvent
Record Components:
key - configuration key | 配置键
oldValue - old value | 旧值
newValue - new value | 新值
changeType - change type | 变更类型
timestamp - event timestamp | 事件时间戳

public record ConfigChangeEvent(String key, String oldValue, String newValue, ConfigChangeEvent.ChangeType changeType, Instant timestamp) extends Record
Configuration Change Event 配置变更事件

Represents a configuration change event, including the key, old value, new value, change type, and timestamp.

表示配置变更事件,包括键、旧值、新值、变更类型和时间戳。

Features | 主要功能:

  • Configuration change tracking - 配置变更跟踪
  • Change type identification (ADDED/MODIFIED/REMOVED) - 变更类型识别
  • Timestamp recording - 时间戳记录
  • Factory methods for creating events - 创建事件的工厂方法

Usage Examples | 使用示例:

// Create events
ConfigChangeEvent added = ConfigChangeEvent.added("new.key", "value");
ConfigChangeEvent modified = ConfigChangeEvent.modified("key", "old", "new");
ConfigChangeEvent removed = ConfigChangeEvent.removed("old.key", "value");

// Use in listener
config.addListener(event -> {
    if (event.isModified()) {
        System.out.println(event.key() + " changed: " +
                         event.oldValue() + " -> " + event.newValue());
    }
});

Performance | 性能特性:

  • Time complexity: O(1) for all operations - 时间复杂度: 所有操作为O(1)
  • Space complexity: O(1) - 空间复杂度: O(1)
  • Immutable and lightweight - 不可变且轻量级

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
  • Immutable: Yes - 不可变: 是
Since:
JDK 25, opencode-base-config V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • ConfigChangeEvent

      public ConfigChangeEvent(String key, String oldValue, String newValue, ConfigChangeEvent.ChangeType changeType, Instant timestamp)
      Creates an instance of a ConfigChangeEvent record class.
      Parameters:
      key - the value for the key record component
      oldValue - the value for the oldValue record component
      newValue - the value for the newValue record component
      changeType - the value for the changeType record component
      timestamp - the value for the timestamp record component
  • Method Details

    • isAdded

      public boolean isAdded()
      Check if configuration was added 检查是否为配置添加
      Returns:
      true if added | 如果是添加返回true
    • isModified

      public boolean isModified()
      Check if configuration was modified 检查是否为配置修改
      Returns:
      true if modified | 如果是修改返回true
    • isRemoved

      public boolean isRemoved()
      Check if configuration was removed 检查是否为配置删除
      Returns:
      true if removed | 如果是删除返回true
    • added

      public static ConfigChangeEvent added(String key, String newValue)
      Create configuration added event 创建配置添加事件
      Parameters:
      key - configuration key | 配置键
      newValue - new value | 新值
      Returns:
      change event | 变更事件
    • modified

      public static ConfigChangeEvent modified(String key, String oldValue, String newValue)
      Create configuration modified event 创建配置修改事件
      Parameters:
      key - configuration key | 配置键
      oldValue - old value | 旧值
      newValue - new value | 新值
      Returns:
      change event | 变更事件
    • removed

      public static ConfigChangeEvent removed(String key, String oldValue)
      Create configuration removed event 创建配置删除事件
      Parameters:
      key - configuration key | 配置键
      oldValue - old value | 旧值
      Returns:
      change event | 变更事件
    • 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. 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
    • oldValue

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

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

      public ConfigChangeEvent.ChangeType changeType()
      Returns the value of the changeType record component.
      Returns:
      the value of the changeType record component
    • timestamp

      public Instant timestamp()
      Returns the value of the timestamp record component.
      Returns:
      the value of the timestamp record component