Package net.dv8tion.jda.api.utils
Interface SplitUtil.Strategy
- Enclosing class:
SplitUtil
public static interface SplitUtil.Strategy
Function which applies a programmable strategy used to determine a splitting point.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final SplitUtil.Strategy
Strategy which splits at any character to satisfy the limit.static final SplitUtil.Strategy
Splits on newline characters.static final SplitUtil.Strategy
Splits on every character which is consideredwhitespace
. -
Method Summary
Modifier and TypeMethodDescriptionint
Implements a splitting strategy.static SplitUtil.Strategy
onChar
(char c) Strategy to split on the provided character.static SplitUtil.Strategy
Strategy to split on the provided character tests.
-
Field Details
-
ANYWHERE
Strategy which splits at any character to satisfy the limit.
This is the default strategy if none is provided, and should ideally only be the final one in your list. -
NEWLINE
Splits on newline characters. Specifically on'\n'
. -
WHITESPACE
Splits on every character which is consideredwhitespace
.
-
-
Method Details
-
apply
Implements a splitting strategy.The goal of a strategy is to implement a greedy algorithm to find the optimal point to split the string. Ideally, this should be close to the
limit
.This should not return an offset larger than
limit
. Any offset lower than the input offset, is interpreted as unsuccessful.- Parameters:
string
- The input stringoffset
- The current offset where to start your substringlimit
- The maximum length your substring should be- Returns:
- The exclusive end index of your chunk, negative to indicate failure. (should be in range of
offset < x <= limit
).
-
onChar
Strategy to split on the provided character.An example use-case would be to define places via
'\0'
and then splitting exactly on those.- Parameters:
c
- The splitting character- Returns:
- The strategy to split on that character
-
onChar
Strategy to split on the provided character tests.- Parameters:
predicate
- The splitting character test- Returns:
- The strategy to split on characters that pass the test
- Throws:
IllegalArgumentException
- If the predicate is null
-