java.lang.Object
java.lang.Record
net.luis.utils.io.token.TokenPosition
- Record Components:
line- The line number of the tokencharacterInLine- The character number in the line of the tokencharacter- The character number of the token in the file
Class which represents the position of a token in a file.
The line, character in line and character numbers are 0-based.
The line, character in line and character numbers are 0-based.
The unpositioned constant is used to represent a token that is not positioned.
A token is considered unpositioned if it has not been assigned a position in the file.
This is useful for tokens that have been added after the tokenization process.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intThe field for thecharacterrecord component.private final intThe field for thecharacterInLinerecord component.private final intThe field for thelinerecord component.static final TokenPositionConstant which represents an unpositioned token. -
Constructor Summary
ConstructorsConstructorDescriptionTokenPosition(int line, int characterInLine, int character) Constructs a new token position. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the value of thecharacterrecord component.intReturns the value of thecharacterInLinerecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanChecks if the token is positioned.
A token is considered positioned if it has a valid line, character in line and character number (non-negative).intline()Returns the value of thelinerecord component.final StringtoString()Returns a string representation of this record class.
-
Field Details
-
line
private final int lineThe field for thelinerecord component. -
characterInLine
private final int characterInLineThe field for thecharacterInLinerecord component. -
character
private final int characterThe field for thecharacterrecord component. -
UNPOSITIONED
Constant which represents an unpositioned token.
-
-
Constructor Details
-
TokenPosition
public TokenPosition(int line, int characterInLine, int character) Constructs a new token position.- Parameters:
line- The line number of the tokencharacterInLine- The character number in the line of the tokencharacter- The character number of the token in the file- Throws:
IllegalArgumentException- If the line, character in line or character numbers are negative- API Note:
- The unpositioned constant uses -1 for all values to indicate that the token is not positioned. Since the constructor does not accept negative values, there is an exception for callers from within the class.
-
-
Method Details
-
isPositioned
public boolean isPositioned()Checks if the token is positioned.
A token is considered positioned if it has a valid line, character in line and character number (non-negative).- Returns:
- True if the token is positioned, false if it is unpositioned
-
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. -
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. -
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 '=='. -
line
public int line()Returns the value of thelinerecord component.- Returns:
- the value of the
linerecord component
-
characterInLine
public int characterInLine()Returns the value of thecharacterInLinerecord component.- Returns:
- the value of the
characterInLinerecord component
-
character
public int character()Returns the value of thecharacterrecord component.- Returns:
- the value of the
characterrecord component
-