Record Class DiffResult<T>

java.lang.Object
java.lang.Record
cloud.opencode.base.core.bean.DiffResult<T>
Type Parameters:
T - the object type | 对象类型
Record Components:
type - the class of the compared objects | 比较对象的类
diffs - the list of property diffs | 属性差异列表

public record DiffResult<T>(Class<T> type, List<Diff<?>> diffs) extends Record
Diff Result Record - Contains the complete comparison result between two objects 差异结果记录 - 包含两个对象之间的完整比较结果

Provides convenience methods to filter diffs by change type.

提供按变更类型过滤差异的便捷方法。

Usage Examples | 使用示例:

DiffResult<User> result = ObjectDiff.compare(oldUser, newUser);
boolean changed = result.hasDiffs();
List<Diff<?>> modified = result.getModified();
List<Diff<?>> added = result.getAdded();
List<Diff<?>> removed = result.getRemoved();
Since:
JDK 25, opencode-base-core V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    DiffResult(Class<T> type, List<Diff<?>> diffs)
    Creates a DiffResult with validation and defensive copy 创建 DiffResult(带验证和防御性拷贝)
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value of the diffs record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    Returns only ADDED diffs 返回仅 ADDED 类型的差异
    Returns only MODIFIED diffs 返回仅 MODIFIED 类型的差异
    Returns only REMOVED diffs 返回仅 REMOVED 类型的差异
    boolean
    Returns true if there are any non-UNCHANGED diffs 是否存在非 UNCHANGED 的差异
    final int
    Returns a hash code value for this object.
    final String
    Returns a string representation of this record class.
    Returns the value of the type record component.

    Methods inherited from class Object

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

    • DiffResult

      public DiffResult(Class<T> type, List<Diff<?>> diffs)
      Creates a DiffResult with validation and defensive copy 创建 DiffResult(带验证和防御性拷贝)
      Parameters:
      type - the class of the compared objects | 比较对象的类
      diffs - the list of property diffs | 属性差异列表
  • Method Details

    • hasDiffs

      public boolean hasDiffs()
      Returns true if there are any non-UNCHANGED diffs 是否存在非 UNCHANGED 的差异
      Returns:
      true if any property changed | 如有属性变更返回 true
    • getModified

      public List<Diff<?>> getModified()
      Returns only MODIFIED diffs 返回仅 MODIFIED 类型的差异
      Returns:
      the list of modified diffs | MODIFIED 差异列表
    • getAdded

      public List<Diff<?>> getAdded()
      Returns only ADDED diffs 返回仅 ADDED 类型的差异
      Returns:
      the list of added diffs | ADDED 差异列表
    • getRemoved

      public List<Diff<?>> getRemoved()
      Returns only REMOVED diffs 返回仅 REMOVED 类型的差异
      Returns:
      the list of removed diffs | REMOVED 差异列表
    • 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 Class<T> type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • diffs

      public List<Diff<?>> diffs()
      Returns the value of the diffs record component.
      Returns:
      the value of the diffs record component