Record Class EscapedToken

java.lang.Object
java.lang.Record
net.luis.utils.io.token.tokens.EscapedToken
Record Components:
definition - The token definition
value - The string value of the token
startPosition - The start position of the token
endPosition - The end position of the token
All Implemented Interfaces:
Token

public record EscapedToken(@NotNull TokenDefinition definition, @NotNull String value, @NotNull TokenPosition startPosition, @NotNull TokenPosition endPosition) extends Record implements Token
Special token implementation for escaped tokens.
An escaped token is a token that starts with a backslash and has a length of 2.
  • Field Details

    • definition

      @NotNull private final @NotNull TokenDefinition definition
      The field for the definition record component.
    • value

      @NotNull private final @NotNull String value
      The field for the value record component.
    • startPosition

      @NotNull private final @NotNull TokenPosition startPosition
      The field for the startPosition record component.
    • endPosition

      @NotNull private final @NotNull TokenPosition endPosition
      The field for the endPosition record component.
  • Constructor Details

    • EscapedToken

      public EscapedToken(@NotNull @NotNull TokenDefinition definition, @NotNull @NotNull String value, @NotNull @NotNull TokenPosition startPosition, @NotNull @NotNull TokenPosition endPosition)
      Constructs a new escaped token for a string value.
      Parameters:
      definition - The token definition
      value - The string value of the token
      startPosition - The start position of the token
      endPosition - The end position of the token
      Throws:
      NullPointerException - If any of the parameters are null
      IllegalArgumentException - If the token value does not have a length of 2, does not start with a backslash or does not match the token definition. If the start and end positions are positioned, the distance between them must be equal to the length of the token value minus 1 (inclusive).
  • Method Details

    • createUnpositioned

      @NotNull public static @NotNull EscapedToken createUnpositioned(@NotNull @NotNull TokenDefinition definition, @NotNull @NotNull String value)
      Creates an unpositioned escaped token for the given token definition and value.
      Parameters:
      definition - The token definition
      value - The string value of the token
      Returns:
      The unpositioned escaped token
      Throws:
      NullPointerException - If the token definition or the token value is null
      IllegalArgumentException - If the token value does not have a length of 2, does not start with a backslash or does not match the token definition
    • toString

      @NotNull public @NotNull 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 Objects::equals(Object,Object).
      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.
    • definition

      @NotNull public @NotNull TokenDefinition definition()
      Returns the value of the definition record component.
      Specified by:
      definition in interface Token
      Returns:
      the value of the definition record component
    • value

      @NotNull public @NotNull String value()
      Returns the value of the value record component.
      Specified by:
      value in interface Token
      Returns:
      the value of the value record component
    • startPosition

      @NotNull public @NotNull TokenPosition startPosition()
      Returns the value of the startPosition record component.
      Specified by:
      startPosition in interface Token
      Returns:
      the value of the startPosition record component
    • endPosition

      @NotNull public @NotNull TokenPosition endPosition()
      Returns the value of the endPosition record component.
      Specified by:
      endPosition in interface Token
      Returns:
      the value of the endPosition record component