Record Class DiffLineNumber

java.lang.Object
java.lang.Record
org.variantsync.diffdetective.diff.text.DiffLineNumber

public record DiffLineNumber(int inDiff, int beforeEdit, int afterEdit) extends Record
Identifies a line number in a textual diff. A DiffLineNumber consists of
  • the line number in the diff,
  • the corresponding line number before the edit
  • the corresponding line number after the edit
Author:
Paul Bittner
  • Field Details

    • inDiff

      private final int inDiff
      The field for the inDiff record component.
    • beforeEdit

      private final int beforeEdit
      The field for the beforeEdit record component.
    • afterEdit

      private final int afterEdit
      The field for the afterEdit record component.
    • InvalidLineNumber

      public static final int InvalidLineNumber
      Index for invalid line numbers.
      See Also:
  • Constructor Details

    • DiffLineNumber

      public DiffLineNumber(int inDiff, int beforeEdit, int afterEdit)
      Creates a line number of a diff.
      Parameters:
      inDiff - line number in the diff
      beforeEdit - number of corresponding line before the edit
      afterEdit - number of corresponding line after the edit
  • Method Details

    • Invalid

      public static DiffLineNumber Invalid()
      Creates an invalid line number using InvalidLineNumber. Use this go obtain a line number that represents an invalid state.
      Returns:
      An invalid line number.
    • withLineNumberAtTime

      public DiffLineNumber withLineNumberAtTime(int lineNumber, Time time)
    • withLineNumberInDiff

      public DiffLineNumber withLineNumberInDiff(int lineNumber)
    • add

      public DiffLineNumber add(int offset)
      Shifts this line number by adding the given offset.
      Parameters:
      offset - value to add to this line number.
      Returns:
      a new DiffLineNumber shifted by offset
    • add

      public DiffLineNumber add(int offset, DiffType diffType)
      Shifts this line number by adding the given offset.
      Parameters:
      offset - value to add to this line number.
      diffType - specifies which components are shifted
      Returns:
      a new DiffLineNumber shifted by offset
    • as

      public DiffLineNumber as(DiffType diffType)
      Filters this line number to only represent line numbers for the given diff type. In particular, added artifacts do not have a line number before the edit and removed artifacts do not have a line number after the edit. Non-existing values will be set to InvalidLineNumber.
      Parameters:
      diffType - The diff type according to which this line number should be filtered.
    • atTime

      public int atTime(Time time)
      Returns the line number at the given time.
      Parameters:
      time - the time at which to return the line range
      Returns:
      beforeEdit or afterEdit, depending on time
    • toString

      public 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
    • equals

      public 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 '=='.
      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.
    • hashCode

      public 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
    • rangeInDiff

      public static LineRange rangeInDiff(DiffLineNumber from, DiffLineNumber to)
      Returns the range between two line numbers in the diff.
      Parameters:
      from - The start line number.
      to - The end line number.
      Returns:
      [from.inDiff, to.inDiff)
      See Also:
    • rangeAtTime

      public static LineRange rangeAtTime(DiffLineNumber from, DiffLineNumber to, Time time)
      Returns the range between two line numbers at a given time.
      Parameters:
      from - The start line number.
      to - The end line number.
      time - The time at which to return the line range.
      Returns:
      [from.beforeEdit, to.beforeEdit) or [from.afterEdit, to.afterEdit)
      See Also:
    • inDiff

      public int inDiff()
      Returns the value of the inDiff record component.
      Returns:
      the value of the inDiff record component
    • beforeEdit

      public int beforeEdit()
      Returns the value of the beforeEdit record component.
      Returns:
      the value of the beforeEdit record component
    • afterEdit

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