java.lang.Object
java.lang.Record
net.luis.utils.io.token.rule.rules.RepeatedTokenRule
- Record Components:
tokenRule- The token rule to matchminOccurrences- The minimum number of occurrencesmaxOccurrences- The maximum number of occurrences
- All Implemented Interfaces:
TokenRule
public record RepeatedTokenRule(@NotNull TokenRule tokenRule, int minOccurrences, int maxOccurrences)
extends Record
implements TokenRule
A token rule that matches a token rule a number of times.
This rule is useful for creating complex matching logic by repeating a rule.
It will match the token rule a number of times between the min and max occurrences.
If the min and max occurrences are the same, it will match exactly that number of times.
This rule is useful for creating complex matching logic by repeating a rule.
It will match the token rule a number of times between the min and max occurrences.
If the min and max occurrences are the same, it will match exactly that number of times.
- API Note:
- This class does not allow the creation of a optional token rule by setting the min and max occurrences to 0.
This is because the implementation ofmatch(List, int)will return null if there is no match.
UseOptionalTokenRulefor that purpose.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intThe field for themaxOccurrencesrecord component.private final intThe field for theminOccurrencesrecord component.private final @NotNull TokenRuleThe field for thetokenRulerecord component. -
Constructor Summary
ConstructorsConstructorDescriptionRepeatedTokenRule(@NotNull TokenRule tokenRule, int occurrences) Constructs a new repeated token rule with the given token rule and exact number of occurrences.RepeatedTokenRule(@NotNull TokenRule tokenRule, int minOccurrences, int maxOccurrences) Constructs a new repeated token rule with the given token rule and min and max number of occurrences. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.@Nullable TokenRuleMatchChecks if the given tokens match this rule starting from the specified index.
If the match is successful, aTokenRuleMatchis returned, otherwise null.intReturns the value of themaxOccurrencesrecord component.intReturns the value of theminOccurrencesrecord component.@NotNull TokenRuleReturns the value of thetokenRulerecord component.final StringtoString()Returns a string representation of this record class.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface net.luis.utils.io.token.rule.rules.TokenRule
optional, repeatAtLeast, repeatAtMost, repeatBetween, repeatExactly, repeatInfinitely
-
Field Details
-
tokenRule
The field for thetokenRulerecord component. -
minOccurrences
private final int minOccurrencesThe field for theminOccurrencesrecord component. -
maxOccurrences
private final int maxOccurrencesThe field for themaxOccurrencesrecord component.
-
-
Constructor Details
-
RepeatedTokenRule
Constructs a new repeated token rule with the given token rule and exact number of occurrences.- Parameters:
tokenRule- The token rule to matchoccurrences- The exact number of occurrences- Throws:
NullPointerException- If the token rule is nullIllegalArgumentException- If the number of occurrences is lower than 0
-
RepeatedTokenRule
public RepeatedTokenRule(@NotNull @NotNull TokenRule tokenRule, int minOccurrences, int maxOccurrences) Constructs a new repeated token rule with the given token rule and min and max number of occurrences.- Parameters:
tokenRule- The token rule to matchminOccurrences- The minimum number of occurrencesmaxOccurrences- The maximum number of occurrences- Throws:
NullPointerException- If the token rule is nullIllegalArgumentException- If the min or max occurrences are lower than 0, or if the max occurrences are lower than the min occurrences, or if both are 0
-
-
Method Details
-
match
@Nullable public @Nullable TokenRuleMatch match(@NotNull @NotNull List<Token> tokens, int startIndex) Description copied from interface:TokenRuleChecks if the given tokens match this rule starting from the specified index.
If the match is successful, aTokenRuleMatchis 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. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
tokenRule
Returns the value of thetokenRulerecord component.- Returns:
- the value of the
tokenRulerecord component
-
minOccurrences
public int minOccurrences()Returns the value of theminOccurrencesrecord component.- Returns:
- the value of the
minOccurrencesrecord component
-
maxOccurrences
public int maxOccurrences()Returns the value of themaxOccurrencesrecord component.- Returns:
- the value of the
maxOccurrencesrecord component
-