Record Class DiffResult

java.lang.Object
java.lang.Record
cloud.opencode.base.string.diff.DiffResult

public record DiffResult(List<DiffLine> lines, int additions, int deletions, int modifications) extends Record
Diff Result - Record holding the result of a string diff operation. 差异结果 - 持有字符串差异操作结果的记录。

Features | 主要功能:

  • Unified diff output - 统一差异输出
  • HTML diff output - HTML差异输出
  • Addition/deletion/modification counts - 增/删/改计数

Usage Examples | 使用示例:

DiffResult result = OpenDiff.diff("hello", "world");
boolean changed = result.hasDiff();
String unified = result.toUnifiedDiff();
String html = result.toHtml();

Security | 安全性:

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

    • DiffResult

      public DiffResult(List<DiffLine> lines, int additions, int deletions, int modifications)
      Creates an instance of a DiffResult record class.
      Parameters:
      lines - the value for the lines record component
      additions - the value for the additions record component
      deletions - the value for the deletions record component
      modifications - the value for the modifications record component
  • Method Details

    • hasDiff

      public boolean hasDiff()
    • toUnifiedDiff

      public String toUnifiedDiff()
    • toHtml

      public String toHtml()
    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      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.
    • lines

      public List<DiffLine> lines()
      Returns the value of the lines record component.
      Returns:
      the value of the lines record component
    • additions

      public int additions()
      Returns the value of the additions record component.
      Returns:
      the value of the additions record component
    • deletions

      public int deletions()
      Returns the value of the deletions record component.
      Returns:
      the value of the deletions record component
    • modifications

      public int modifications()
      Returns the value of the modifications record component.
      Returns:
      the value of the modifications record component