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 int
The field for thecharacter
record component.private final int
The field for thecharacterInLine
record component.private final int
The field for theline
record component.static final TokenPosition
Constant which represents an unpositioned token. -
Constructor Summary
ConstructorsConstructorDescriptionTokenPosition
(int line, int characterInLine, int character) Constructs a new token position. -
Method Summary
Modifier and TypeMethodDescriptionint
Returns the value of thecharacter
record component.int
Returns the value of thecharacterInLine
record component.final boolean
Indicates whether some other object is "equal to" this one.final int
hashCode()
Returns a hash code value for this object.boolean
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).int
line()
Returns the value of theline
record component.final String
toString()
Returns a string representation of this record class.
-
Field Details
-
line
private final int lineThe field for theline
record component. -
characterInLine
private final int characterInLineThe field for thecharacterInLine
record component. -
character
private final int characterThe field for thecharacter
record 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 theline
record component.- Returns:
- the value of the
line
record component
-
characterInLine
public int characterInLine()Returns the value of thecharacterInLine
record component.- Returns:
- the value of the
characterInLine
record component
-
character
public int character()Returns the value of thecharacter
record component.- Returns:
- the value of the
character
record component
-