java.lang.Object
java.lang.Record
net.luis.utils.io.token.rule.rules.OptionalTokenRule
- Record Components:
tokenRule
- The token rule to match optionally
- All Implemented Interfaces:
TokenRule
A token rule that matches optionally a single token rule.
This rule is useful for creating optional matching logic.
It will match the token rule if it is present, otherwise it will return an empty match.
This rule is useful for creating optional matching logic.
It will match the token rule if it is present, otherwise it will return an empty match.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionOptionalTokenRule
(@NotNull TokenRule tokenRule) Constructs a new optional token rule with the given token rule. -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
Indicates whether some other object is "equal to" this one.final int
hashCode()
Returns a hash code value for this object.@Nullable TokenRuleMatch
Checks if the given tokens match this rule starting from the specified index.
If the match is successful, aTokenRuleMatch
is returned, otherwise null.@NotNull TokenRule
Returns the value of thetokenRule
record component.final String
toString()
Returns a string representation of this record class.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface net.luis.utils.io.token.rule.rules.TokenRule
optional, repeatAtLeast, repeatAtMost, repeatBetween, repeatExactly, repeatInfinitely
-
Field Details
-
tokenRule
The field for thetokenRule
record component.
-
-
Constructor Details
-
OptionalTokenRule
Constructs a new optional token rule with the given token rule.- Parameters:
tokenRule
- The token rule to match optionally- Throws:
NullPointerException
- If the token rule is null
-
-
Method Details
-
match
@Nullable public @Nullable TokenRuleMatch match(@NotNull @NotNull List<Token> tokens, int startIndex) Description copied from interface:TokenRule
Checks if the given tokens match this rule starting from the specified index.
If the match is successful, aTokenRuleMatch
is returned, otherwise null. -
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)
. -
tokenRule
Returns the value of thetokenRule
record component.- Returns:
- the value of the
tokenRule
record component
-