Record Class DiffLineNumber
java.lang.Object
java.lang.Record
org.variantsync.diffdetective.diff.text.DiffLineNumber
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 Summary
Modifier and TypeFieldDescriptionprivate final int
The field for theafterEdit
record component.private final int
The field for thebeforeEdit
record component.private final int
The field for theinDiff
record component.static final int
Index for invalid line numbers. -
Constructor Summary
ConstructorDescriptionDiffLineNumber
(int inDiff, int beforeEdit, int afterEdit) Creates a line number of a diff. -
Method Summary
Modifier and TypeMethodDescriptionadd
(int offset) Shifts this line number by adding the given offset.Shifts this line number by adding the given offset.int
Returns the value of theafterEdit
record component.Filters this line number to only represent line numbers for the given diff type.int
Returns the line number at the given time.int
Returns the value of thebeforeEdit
record component.boolean
Indicates whether some other object is "equal to" this one.int
hashCode()
Returns a hash code value for this object.int
inDiff()
Returns the value of theinDiff
record component.static DiffLineNumber
Invalid()
Creates an invalid line number usingInvalidLineNumber
.static LineRange
rangeAtTime
(DiffLineNumber from, DiffLineNumber to, Time time) Returns the range between two line numbers at a given time.static LineRange
rangeInDiff
(DiffLineNumber from, DiffLineNumber to) Returns the range between two line numbers in the diff.toString()
Returns a string representation of this record class.withLineNumberAtTime
(int lineNumber, Time time) withLineNumberInDiff
(int lineNumber)
-
Field Details
-
inDiff
private final int inDiffThe field for theinDiff
record component. -
beforeEdit
private final int beforeEditThe field for thebeforeEdit
record component. -
afterEdit
private final int afterEditThe field for theafterEdit
record component. -
InvalidLineNumber
public static final int InvalidLineNumberIndex 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 diffbeforeEdit
- number of corresponding line before the editafterEdit
- number of corresponding line after the edit
-
-
Method Details
-
Invalid
Creates an invalid line number usingInvalidLineNumber
. Use this go obtain a line number that represents an invalid state.- Returns:
- An invalid line number.
-
withLineNumberAtTime
-
withLineNumberInDiff
-
add
Shifts this line number by adding the given offset.- Parameters:
offset
- value to add to this line number.- Returns:
- a new
DiffLineNumber
shifted byoffset
-
add
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 byoffset
-
as
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 toInvalidLineNumber
.- Parameters:
diffType
- The diff type according to which this line number should be filtered.
-
atTime
Returns the line number at the given time.- Parameters:
time
- the time at which to return the line range- Returns:
beforeEdit
orafterEdit
, depending ontime
-
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. -
equals
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 '=='. -
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. -
rangeInDiff
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
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 theinDiff
record component.- Returns:
- the value of the
inDiff
record component
-
beforeEdit
public int beforeEdit()Returns the value of thebeforeEdit
record component.- Returns:
- the value of the
beforeEdit
record component
-
afterEdit
public int afterEdit()Returns the value of theafterEdit
record component.- Returns:
- the value of the
afterEdit
record component
-