Record Class TokenGroup

java.lang.Object
java.lang.Record
net.luis.utils.io.token.tokens.TokenGroup
Record Components:
tokens - The list of tokens in the group
definition - The token definition
All Implemented Interfaces:
Token

public record TokenGroup(@NotNull List<Token> tokens, @NotNull TokenDefinition definition) extends Record implements Token
Token implementation for a group of tokens.
A token group is a sequence of tokens that have been grouped together and match the token definition.

The token group must contain at least two tokens.
The tokens must be continuous; this means that no token can be removed in the middle of the group.
The group is continuous if the distance between the start position of the first token and the end position of the last token
is equal to the length of the group value minus one (inclusive).

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final @NotNull TokenDefinition
    The field for the definition record component.
    private final @NotNull List<Token>
    The field for the tokens record component.
  • Constructor Summary

    Constructors
    Constructor
    Description
    TokenGroup(@NotNull List<Token> tokens, @NotNull TokenDefinition definition)
    Constructs a new token group for a list of tokens.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value of the definition record component.
    @NotNull TokenPosition
    Returns the end position of the token group.
    The end position is the end position of the last token in the group.
    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 group is positioned.
    A token group is positioned if all tokens in the group are positioned.
    @NotNull TokenPosition
    Returns the start position of the token group.
    The start position is the start position of the first token in the group.
    @NotNull List<Token>
    Returns the value of the tokens record component.
    final String
    Returns a string representation of this record class.
    @NotNull String
    Returns the value of the token group.
    The value is the concatenation of all token values in the group.

    Methods inherited from class java.lang.Object

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

    • tokens

      @NotNull private final @NotNull List<Token> tokens
      The field for the tokens record component.
    • definition

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

    • TokenGroup

      public TokenGroup(@NotNull @NotNull List<Token> tokens, @NotNull @NotNull TokenDefinition definition)
      Constructs a new token group for a list of tokens.
      Parameters:
      tokens - The list of tokens in the group
      definition - The token definition
      Throws:
      NullPointerException - If the list of tokens, the token definition or any of the tokens are null
      IllegalArgumentException - If the list of tokens is empty, contains a single element, does not match the token definition or the start and end positions do not match the length of the token group
  • Method Details

    • value

      @NotNull public @NotNull String value()
      Returns the value of the token group.
      The value is the concatenation of all token values in the group.
      Specified by:
      value in interface Token
      Returns:
      The concatenated values
    • isPositioned

      public boolean isPositioned()
      Checks if the token group is positioned.
      A token group is positioned if all tokens in the group are positioned.
      Returns:
      True if this token group is positioned, false otherwise
      See Also:
    • startPosition

      @NotNull public @NotNull TokenPosition startPosition()
      Returns the start position of the token group.
      The start position is the start position of the first token in the group.
      Specified by:
      startPosition in interface Token
      Returns:
      The start position
      API Note:
      If isPositioned() returns false, the start position can be unpositioned
    • endPosition

      @NotNull public @NotNull TokenPosition endPosition()
      Returns the end position of the token group.
      The end position is the end position of the last token in the group.
      Specified by:
      endPosition in interface Token
      Returns:
      The end position
      API Note:
      If isPositioned() returns false, the end position can be 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 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.
    • tokens

      @NotNull public @NotNull List<Token> tokens()
      Returns the value of the tokens record component.
      Returns:
      the value of the tokens record component
    • 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