Class TokenReader.PositionTracker

java.lang.Object
net.luis.utils.io.token.TokenReader.PositionTracker
Enclosing class:
TokenReader

private static final class TokenReader.PositionTracker extends Object
A class that tracks the position of the current character in the input string.
It keeps track of the line number, character position, and character index in the line.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int
    The index of the current character in the line.
    private int
    The line number of the current character in the input string.
    private int
    The index of the current character in the input string.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    Copies the position from another position tracker.
    It sets the line number, character position, and character index to the values of the other position tracker.
    private void
    Counts a new character in the input string.
    It increments the position and character index.
    private void
    Counts a new line in the input string.
    It increments the position and character index, and resets the character in line index to 0.
    private @NotNull TokenPosition
    Creates a new token position based on the current position tracker.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • line

      private int line
      The line number of the current character in the input string.
    • position

      private int position
      The index of the current character in the input string.
    • charInLine

      private int charInLine
      The index of the current character in the line.
  • Constructor Details

    • PositionTracker

      private PositionTracker()
  • Method Details

    • increment

      private void increment()
      Counts a new character in the input string.
      It increments the position and character index.
    • newLine

      private void newLine()
      Counts a new line in the input string.
      It increments the position and character index, and resets the character in line index to 0.
    • copyFrom

      private void copyFrom(@NotNull @NotNull TokenReader.PositionTracker other)
      Copies the position from another position tracker.
      It sets the line number, character position, and character index to the values of the other position tracker.
      Parameters:
      other - The other position tracker to copy from
      Throws:
      NullPointerException - If the other position tracker is null
    • toTokenPosition

      @NotNull private @NotNull TokenPosition toTokenPosition()
      Creates a new token position based on the current position tracker.
      Returns:
      A new token position