Interface VCSFile.Range
-
- All Superinterfaces:
VCSModelElement
- Enclosing interface:
- VCSFile
public static interface VCSFile.Range extends VCSModelElement
A range within a file. Ranges cannot be empty or negative. UseVCSFile.Position.rangeTo(Position)
to create instances of this class.
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.Comparator<VCSFile.Range>
BEGIN_COMPARATOR
Compares two ranges using their begin position (getBegin()
) andVCSFile.Position.OFFSET_COMPARATOR
.static java.util.function.BiPredicate<VCSFile.Range,VCSFile.Range>
RELATIVE_PATH_PREDICATE
Tests if two ranges are equal according to their begin and end positions (by matching thegetBegin()
andgetEnd()
positions withVCSFile.Position.RELATIVE_PATH_PREDICATE
).
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default java.util.Optional<VCSFile.Range>
apply(FileChange fileChange)
DelegatesfileChange
togetBegin()
andgetEnd()
(seeVCSFile.Position.apply(FileChange)
) and computes the resulting range.VCSFile.Position
getBegin()
Returns the begin position of this range.VCSFile.Position
getEnd()
Returns the end position of this range.VCSFile
getFile()
Returns the referenced file.default int
length()
Returns the length of this range.static int
lengthOf(java.util.Collection<VCSFile.Range> ranges)
Calculates the sum of the lengths of the given ranges.default java.util.Optional<VCSFile.Range>
mapTo(VCSFile file)
Returns a range with same begin and end, but located infile
.default java.util.Optional<VCSFile.Range>
merge(VCSFile.Range range)
Creates a new range that merges the positions of this and the given range.default java.lang.String
readContent()
Reads the content of this range.-
Methods inherited from interface de.unibremen.informatik.st.libvcs4j.VCSModelElement
getVCSEngine
-
-
-
-
Field Detail
-
BEGIN_COMPARATOR
static final java.util.Comparator<VCSFile.Range> BEGIN_COMPARATOR
Compares two ranges using their begin position (getBegin()
) andVCSFile.Position.OFFSET_COMPARATOR
.
-
RELATIVE_PATH_PREDICATE
static final java.util.function.BiPredicate<VCSFile.Range,VCSFile.Range> RELATIVE_PATH_PREDICATE
Tests if two ranges are equal according to their begin and end positions (by matching thegetBegin()
andgetEnd()
positions withVCSFile.Position.RELATIVE_PATH_PREDICATE
).null
matchesnull
, but not anon-null
value.
-
-
Method Detail
-
lengthOf
static int lengthOf(java.util.Collection<VCSFile.Range> ranges)
Calculates the sum of the lengths of the given ranges. Overlapping parts are handled accordingly.- Parameters:
ranges
- The collection of ranges to calculate the sum of the lengths from. Ifnull
,0
is returned. The collection may containnull
values.- Returns:
- The sum of the lengths of the given ranges.
- Throws:
java.lang.IllegalArgumentException
- If the ranges reference different files.
-
getBegin
VCSFile.Position getBegin()
Returns the begin position of this range.- Returns:
- The begin position of this range.
-
getEnd
VCSFile.Position getEnd()
Returns the end position of this range.- Returns:
- The end position of this range (inclusive).
-
getFile
VCSFile getFile()
Returns the referenced file.- Returns:
- The referenced. file.
-
length
default int length()
Returns the length of this range.- Returns:
- The length of this range (
>= 1
).
-
readContent
default java.lang.String readContent() throws java.io.IOException
Reads the content of this range.- Returns:
- The content of this range.
- Throws:
java.io.IOException
- If an error occurred while reading the file content.
-
merge
default java.util.Optional<VCSFile.Range> merge(VCSFile.Range range) throws java.lang.NullPointerException, java.lang.IllegalArgumentException
Creates a new range that merges the positions of this and the given range. Returns an emptyOptional
if their positions do not overlap.- Parameters:
range
- The range to merge.- Returns:
- A range that merges the overlapping positions of this and the
given range. An empty
Optional
if their positions do not overlap. - Throws:
java.lang.NullPointerException
- Ifrange
isnull
.java.lang.IllegalArgumentException
- Ifrange
references a different file.
-
apply
default java.util.Optional<VCSFile.Range> apply(FileChange fileChange) throws java.lang.NullPointerException, java.io.IOException
DelegatesfileChange
togetBegin()
andgetEnd()
(seeVCSFile.Position.apply(FileChange)
) and computes the resulting range. Returns an empty Optional iffileChange
is of typeFileChange.Type.REMOVE
, or ifgetBegin()
orgetEnd()
returns an emptyOptional
.- Parameters:
fileChange
- The file change to apply.- Returns:
- The updated range.
- Throws:
java.lang.NullPointerException
- IffileChange
isnull
.java.lang.IllegalArgumentException
- If the file referenced byfileChange
differs from the file referenced by this range.java.io.IOException
- If computing the line diff (seeFileChange.computeDiff()
) fails.
-
mapTo
default java.util.Optional<VCSFile.Range> mapTo(VCSFile file) throws java.io.IOException
Returns a range with same begin and end, but located infile
. Returns an empty optional, if this range does not exist infile
.- Parameters:
file
- The file to map this range to.- Returns:
- A range with same begin and end, but located in
file
. - Throws:
java.lang.NullPointerException
- Iffile
isnull
.java.io.IOException
- If an error occurred while reading the file content.
-
-