Record Class TokenPosition

java.lang.Object
java.lang.Record
net.luis.utils.io.token.TokenPosition
Record Components:
line - The line number of the token
characterInLine - The character number in the line of the token
character - The character number of the token in the file

public record TokenPosition(int line, int characterInLine, int character) extends Record
Class which represents the position of a token in a file.
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

    Fields
    Modifier and Type
    Field
    Description
    private final int
    The field for the character record component.
    private final int
    The field for the characterInLine record component.
    private final int
    The field for the line record component.
    static final TokenPosition
    Constant which represents an unpositioned token.
  • Constructor Summary

    Constructors
    Constructor
    Description
    TokenPosition(int line, int characterInLine, int character)
    Constructs a new token position.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the value of the character record component.
    int
    Returns the value of the characterInLine record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    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
    Returns the value of the line record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • line

      private final int line
      The field for the line record component.
    • characterInLine

      private final int characterInLine
      The field for the characterInLine record component.
    • character

      private final int character
      The field for the character record component.
    • UNPOSITIONED

      public static final TokenPosition 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 token
      characterInLine - The character number in the line of the token
      character - 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

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • line

      public int line()
      Returns the value of the line record component.
      Returns:
      the value of the line record component
    • characterInLine

      public int characterInLine()
      Returns the value of the characterInLine record component.
      Returns:
      the value of the characterInLine record component
    • character

      public int character()
      Returns the value of the character record component.
      Returns:
      the value of the character record component