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.
UseOptionalTokenRule
for that purpose.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int
The field for themaxOccurrences
record component.private final int
The field for theminOccurrences
record component.private final @NotNull TokenRule
The field for thetokenRule
record 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 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.int
Returns the value of themaxOccurrences
record component.int
Returns the value of theminOccurrences
record component.@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. -
minOccurrences
private final int minOccurrencesThe field for theminOccurrences
record component. -
maxOccurrences
private final int maxOccurrencesThe field for themaxOccurrences
record 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: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. Reference components are compared withObjects::equals(Object,Object)
; primitive components are compared with '=='. -
tokenRule
Returns the value of thetokenRule
record component.- Returns:
- the value of the
tokenRule
record component
-
minOccurrences
public int minOccurrences()Returns the value of theminOccurrences
record component.- Returns:
- the value of the
minOccurrences
record component
-
maxOccurrences
public int maxOccurrences()Returns the value of themaxOccurrences
record component.- Returns:
- the value of the
maxOccurrences
record component
-