JavaScript is disabled on your browser.
All Superinterfaces:
TokenRule
All Known Implementing Classes:
CharTokenDefinition
, EscapedTokenDefinition
, StringTokenDefinition
, WordTokenDefinition
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Functional interface for a token definition.
A token definition defines a token and provides a method to check if a word matches the token.
For easier usage in rules this interface extends TokenRule
.
This means a token definition can be used as a rule in a TokenRule
.
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods
Combines multiple token definitions into a single token definition.
The resulting token definition contains the concatenated string of all token definitions.
If only one token definition is provided, it is returned as is.
Checks if the given tokens match this rule starting from the specified index.
If the match is successful, a
TokenRuleMatch
is returned, otherwise null.
boolean
Checks if the given word matches this token definition.
Creates a new token definition for a single character.
of (@NotNull String token,
boolean equalsIgnoreCase)
Creates a new token definition for a string.
Creates a new escaped token definition for a single character.
Method Details
of
Creates a new token definition for a single character.
Parameters:
token
- The token character
Returns:
The token definition
See Also:
of
Creates a new token definition for a string.
Parameters:
token
- The token string
equalsIgnoreCase
- If the token should be compared case insensitive
Returns:
The token definition
Throws:
NullPointerException
- If the token is null
IllegalArgumentException
- If the token is empty
See Also:
ofEscaped
Creates a new escaped token definition for a single character.
Parameters:
token
- The token character
Returns:
The token definition
See Also:
combine
Combines multiple token definitions into a single token definition.
The resulting token definition contains the concatenated string of all token definitions.
If only one token definition is provided, it is returned as is.
Parameters:
definitions
- The token definitions to combine
Returns:
The combined token definition
Throws:
NullPointerException
- If the token definition array is null
IllegalArgumentException
- If the token definition array is empty or contains an unsupported token definition type
matches
boolean matches (@NotNull
@NotNull String word)
Checks if the given word matches this token definition.
Parameters:
word
- The word to check
Returns:
True if the word matches this token definition, false otherwise
Throws:
NullPointerException
- If the word is null
match
Checks if the given tokens match this rule starting from the specified index.
If the match is successful, a
TokenRuleMatch
is returned, otherwise null.
Specified by:
match
in interface TokenRule
Parameters:
tokens
- The list of tokens to match against
startIndex
- The index to start matching from
Returns:
A token rule match if successful, otherwise null