Interface VCSFile.Position
-
- All Superinterfaces:
VCSModelElement
- Enclosing interface:
- VCSFile
public static interface VCSFile.Position extends VCSModelElement
A position within a file. As a line of text does not include new line characters, a position can not point to new line delimiters, such as '\n', '\r', and '\r\n'. UseVCSFile.positionOf(int, int, int)
orVCSFile.positionOf(int, int)
to create instances of this class.
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.Comparator<VCSFile.Position>
OFFSET_COMPARATOR
Compares two positions using their offsets (getOffset()
).static java.util.function.BiPredicate<VCSFile.Position,VCSFile.Position>
RELATIVE_PATH_PREDICATE
Tests if two positions are equal according to their offset (usingOFFSET_COMPARATOR
) and their relative path (usingVCSFile.toRelativePath()
andPath.equals(Object)
).
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default java.util.Optional<VCSFile.Position>
apply(FileChange fileChange)
Applies the diff offileChange
(seeFileChange.computeDiff()
) and computes the resulting position.default VCSFile.Position
beginOfLine()
Returns the position located at the first column of the current line.default VCSFile.Position
endOfLine()
Returns the position located at the last column of the current line.int
getColumn()
Returns the column of this position>= 1
.VCSFile
getFile()
Returns the referenced file.int
getLine()
Returns the line of this position>= 1
.int
getLineOffset()
Returns the line offset of this position>= 0
.int
getOffset()
Returns the offset of this position>= 0
.int
getTabSize()
Returns the tab size of this position>= 1
.default java.util.Optional<VCSFile.Position>
mapTo(VCSFile file)
Returns a position with same line, column, offset, line offset, and tab size, but located infile
.default java.util.Optional<VCSFile.Position>
nextLine()
Returns the position located at the first column of the next line.default java.util.Optional<VCSFile.Position>
previousLine()
Returns the position located at the first column of the previous line.default VCSFile.Range
rangeTo(VCSFile.Position other)
Creates a range from this and the given position.default char
readChar()
Reads the character this position points to.-
Methods inherited from interface de.unibremen.informatik.st.libvcs4j.VCSModelElement
getVCSEngine
-
-
-
-
Field Detail
-
OFFSET_COMPARATOR
static final java.util.Comparator<VCSFile.Position> OFFSET_COMPARATOR
Compares two positions using their offsets (getOffset()
).
-
RELATIVE_PATH_PREDICATE
static final java.util.function.BiPredicate<VCSFile.Position,VCSFile.Position> RELATIVE_PATH_PREDICATE
Tests if two positions are equal according to their offset (usingOFFSET_COMPARATOR
) and their relative path (usingVCSFile.toRelativePath()
andPath.equals(Object)
).null
matchesnull
, but not anon-null
value.
-
-
Method Detail
-
getFile
VCSFile getFile()
Returns the referenced file.- Returns:
- The referenced file.
-
getLine
int getLine()
Returns the line of this position>= 1
.- Returns:
- The line of this position
>= 1
.
-
getColumn
int getColumn()
Returns the column of this position>= 1
.- Returns:
- The column of this position
>= 1
.
-
getOffset
int getOffset()
Returns the offset of this position>= 0
.- Returns:
- The offset of this position
>= 0
.
-
getLineOffset
int getLineOffset()
Returns the line offset of this position>= 0
.- Returns:
- The line offset of this position
>= 0
.
-
getTabSize
int getTabSize()
Returns the tab size of this position>= 1
.- Returns:
- The tab size of this position
>= 1
.
-
apply
default java.util.Optional<VCSFile.Position> apply(FileChange fileChange) throws java.lang.NullPointerException, java.lang.IllegalArgumentException, java.io.IOException
Applies the diff offileChange
(seeFileChange.computeDiff()
) and computes the resulting position. Returns an empty Optional iffileChange
is of typeFileChange.Type.REMOVE
, or if the line of this position was deleted without a corresponding insertion. If the line of this position was changed to a non-empty string, the resulting column is set to 1. If the line of this position was changed to an empty string, an emptyOptional
is returned.- Parameters:
fileChange
- The file change to apply.- Returns:
- The updated position.
- Throws:
java.lang.NullPointerException
- IffileChange
isnull
.java.lang.IllegalArgumentException
- If the file referenced byfileChange
differs from the file referenced by this position.java.io.IOException
- If computing the line diff (seeFileChange.computeDiff()
) fails.
-
nextLine
default java.util.Optional<VCSFile.Position> nextLine() throws java.io.IOException
Returns the position located at the first column of the next line. If this position is located at the last line, or if the next line is empty, an emptyOptional
is returned.- Returns:
- The position located at the first column of the next line.
- Throws:
java.io.IOException
- If an error occurred while reading the file content.
-
previousLine
default java.util.Optional<VCSFile.Position> previousLine() throws java.io.IOException
Returns the position located at the first column of the previous line. If this position is located at the first line, or if the previous line is empty, an emptyOptional
is returned.- Returns:
- The position located at the first column of the previous line.
- Throws:
java.io.IOException
- If an error occurred while reading the file content.
-
beginOfLine
default VCSFile.Position beginOfLine() throws java.io.IOException
Returns the position located at the first column of the current line.- Returns:
- The position located at the first column of the current line.
- Throws:
java.io.IOException
- If an error occurred while reading the file content.
-
endOfLine
default VCSFile.Position endOfLine() throws java.io.IOException
Returns the position located at the last column of the current line.- Returns:
- The position located at the last column of the current line.
- Throws:
java.io.IOException
- If an error occurred while reading the file content.
-
mapTo
default java.util.Optional<VCSFile.Position> mapTo(VCSFile file) throws java.io.IOException
Returns a position with same line, column, offset, line offset, and tab size, but located infile
. Returns an empty optional if this position does not exist infile
.- Parameters:
file
- The file to map this position to.- Returns:
- A position with same line, column, offset, line offset, and tab
size, but located in
file
. - Throws:
java.lang.NullPointerException
- Iffile
isnull
.java.io.IOException
- If an error occurred while reading the file content.
-
readChar
default char readChar() throws java.io.IOException
Reads the character this position points to.- Returns:
- The character this position points to.
- Throws:
java.io.IOException
- If an error occurred while reading the file content.
-
rangeTo
default VCSFile.Range rangeTo(VCSFile.Position other)
Creates a range from this and the given position. Automatically computes which position is the begin and which position is the end.- Parameters:
other
- The position to create the range to.- Returns:
- A range from this and the given position.
- Throws:
java.lang.NullPointerException
- Ifother
isnull
.java.lang.IllegalArgumentException
- Ifthis
andother
reference different files.
-
-