java.lang.Object
java.lang.Record
net.luis.utils.io.token.tokens.TokenGroup
- Record Components:
tokens
- The list of tokens in the groupdefinition
- 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.
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
FieldsModifier and TypeFieldDescriptionprivate final @NotNull TokenDefinition
The field for thedefinition
record component.The field for thetokens
record component. -
Constructor Summary
ConstructorsConstructorDescriptionTokenGroup
(@NotNull List<Token> tokens, @NotNull TokenDefinition definition) Constructs a new token group for a list of tokens. -
Method Summary
Modifier and TypeMethodDescription@NotNull TokenDefinition
Returns the value of thedefinition
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
hashCode()
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.tokens()
Returns the value of thetokens
record component.final String
toString()
Returns a string representation of this record class.@NotNull String
value()
Returns the value of the token group.
The value is the concatenation of all token values in the group.
-
Field Details
-
tokens
The field for thetokens
record component. -
definition
The field for thedefinition
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 groupdefinition
- The token definition- Throws:
NullPointerException
- If the list of tokens, the token definition or any of the tokens are nullIllegalArgumentException
- 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
Returns the value of the token group.
The value is the concatenation of all token values in the group. -
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
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 interfaceToken
- Returns:
- The start position
- API Note:
- If
isPositioned()
returns false, the start position can be unpositioned
-
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 interfaceToken
- Returns:
- The end position
- API Note:
- If
isPositioned()
returns false, the end position can be 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 withObjects::equals(Object,Object)
. -
tokens
Returns the value of thetokens
record component.- Returns:
- the value of the
tokens
record component
-
definition
Returns the value of thedefinition
record component.- Specified by:
definition
in interfaceToken
- Returns:
- the value of the
definition
record component
-