Record Class Diff<T>

java.lang.Object
java.lang.Record
cloud.opencode.base.core.bean.Diff<T>
Type Parameters:
T - the value type | 值类型
Record Components:
fieldName - the property name | 属性名称
oldValue - the old value (nullable) | 旧值(可为 null)
newValue - the new value (nullable) | 新值(可为 null)
changeType - the type of change | 变更类型

public record Diff<T>(String fieldName, T oldValue, T newValue, ChangeType changeType) extends Record
Diff Record - Represents a single property difference between two objects 差异记录 - 表示两个对象之间单个属性的差异

Captures the field name, old value, new value, and the type of change.

记录字段名称、旧值、新值以及变更类型。

Usage Examples | 使用示例:

Diff<String> diff = new Diff<>("name", "Alice", "Bob", ChangeType.MODIFIED);
String field = diff.fieldName();   // "name"
String oldVal = diff.oldValue();   // "Alice"
String newVal = diff.newValue();   // "Bob"
ChangeType type = diff.changeType(); // MODIFIED
Since:
JDK 25, opencode-base-core V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • Diff

      public Diff(String fieldName, T oldValue, T newValue, ChangeType changeType)
      Creates a Diff instance with validation 创建 Diff 实例(带验证)
      Parameters:
      fieldName - the property name | 属性名称
      oldValue - the old value (nullable) | 旧值
      newValue - the new value (nullable) | 新值
      changeType - the type of change | 变更类型
  • Method Details

    • 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.
    • fieldName

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

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

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

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