Record Class DiffEntry

java.lang.Object
java.lang.Record
cloud.opencode.base.yml.diff.DiffEntry
Record Components:
type - the type of change | 变更类型
path - the dot-notation path where change occurred | 变更发生位置的点号路径
oldValue - the previous value (null for ADDED) | 先前的值(ADDED 时为 null)
newValue - the new value (null for REMOVED) | 新值(REMOVED 时为 null)

public record DiffEntry(DiffType type, String path, Object oldValue, Object newValue) extends Record
Diff Entry - Represents a single difference between two YAML documents 差异条目 - 表示两个 YAML 文档之间的单个差异

An immutable record that captures the type of change, the path where it occurred, and the old/new values involved.

一个不可变记录,捕获变更类型、发生位置的路径以及涉及的旧/新值。

Features | 主要功能:

  • Immutable record with type, path, old value, new value - 不可变记录:类型、路径、旧值、新值
  • Factory methods for creating entries - 创建条目的工厂方法
  • Dot-notation paths with array index support - 点号路径表示法,支持数组索引

Usage Examples | 使用示例:

DiffEntry added = DiffEntry.added("server.port", 8080);
DiffEntry removed = DiffEntry.removed("logging.level", "DEBUG");
DiffEntry modified = DiffEntry.modified("app.name", "old", "new");

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
Since:
JDK 25, opencode-base-yml V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • DiffEntry

      public DiffEntry(DiffType type, String path, Object oldValue, Object newValue)
      Canonical constructor with validation. 带校验的规范构造器。
      Parameters:
      type - the type of change | 变更类型
      path - the path | 路径
      oldValue - the old value | 旧值
      newValue - the new value | 新值
      Throws:
      NullPointerException - if type or path is null | 当 type 或 path 为 null 时
  • Method Details

    • added

      public static DiffEntry added(String path, Object value)
      Creates an ADDED entry. 创建新增条目。
      Parameters:
      path - the path where value was added | 新增值的路径
      value - the added value | 新增的值
      Returns:
      the diff entry | 差异条目
    • removed

      public static DiffEntry removed(String path, Object value)
      Creates a REMOVED entry. 创建移除条目。
      Parameters:
      path - the path where value was removed | 移除值的路径
      value - the removed value | 移除的值
      Returns:
      the diff entry | 差异条目
    • modified

      public static DiffEntry modified(String path, Object oldValue, Object newValue)
      Creates a MODIFIED entry. 创建修改条目。
      Parameters:
      path - the path where value was modified | 修改值的路径
      oldValue - the previous value | 先前的值
      newValue - the new value | 新值
      Returns:
      the diff entry | 差异条目
    • 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.
    • type

      public DiffType type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • path

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

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

      public Object newValue()
      Returns the value of the newValue record component.
      Returns:
      the value of the newValue record component