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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumConfiguration Change Type 配置变更类型 -
Constructor Summary
ConstructorsConstructorDescriptionConfigChangeEvent(String key, String oldValue, String newValue, ConfigChangeEvent.ChangeType changeType, Instant timestamp) Creates an instance of aConfigChangeEventrecord class. -
Method Summary
Modifier and TypeMethodDescriptionstatic ConfigChangeEventCreate configuration added event 创建配置添加事件Returns the value of thechangeTyperecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanisAdded()Check if configuration was added 检查是否为配置添加booleanCheck if configuration was modified 检查是否为配置修改booleanCheck if configuration was removed 检查是否为配置删除key()Returns the value of thekeyrecord component.static ConfigChangeEventCreate configuration modified event 创建配置修改事件newValue()Returns the value of thenewValuerecord component.oldValue()Returns the value of theoldValuerecord component.static ConfigChangeEventCreate configuration removed event 创建配置删除事件Returns the value of thetimestamprecord component.toString()Returns a string representation of this record class.
-
Constructor Details
-
ConfigChangeEvent
public ConfigChangeEvent(String key, String oldValue, String newValue, ConfigChangeEvent.ChangeType changeType, Instant timestamp) Creates an instance of aConfigChangeEventrecord class.- Parameters:
key- the value for thekeyrecord componentoldValue- the value for theoldValuerecord componentnewValue- the value for thenewValuerecord componentchangeType- the value for thechangeTyperecord componenttimestamp- the value for thetimestamprecord 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
Create configuration added event 创建配置添加事件- Parameters:
key- configuration key | 配置键newValue- new value | 新值- Returns:
- change event | 变更事件
-
modified
Create configuration modified event 创建配置修改事件- Parameters:
key- configuration key | 配置键oldValue- old value | 旧值newValue- new value | 新值- Returns:
- change event | 变更事件
-
removed
Create configuration removed event 创建配置删除事件- Parameters:
key- configuration key | 配置键oldValue- old value | 旧值- Returns:
- change event | 变更事件
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object). -
key
-
oldValue
-
newValue
-
changeType
Returns the value of thechangeTyperecord component.- Returns:
- the value of the
changeTyperecord component
-
timestamp
-