- Type Parameters:
P- The primitive type to be parsed.T- The type of argument that is provided.
- All Superinterfaces:
ArgumentParser<P,,T> BiFunction<CommandContext,,P, Mono<T>> InputParser<P,,T> ParserFunction<P,T>
- All Known Subinterfaces:
FloatParser<T>,IntegerParser<T>,ListParser<T>,NumberParser<P,,T> StringParser<T>
public sealed interface ChoicesParser<P extends @NonNull Object,T extends @NonNull Object>
extends InputParser<P,T>
permits StringParser<T>, NumberParser<P,T>
Parses received input arguments, potentially restricting the acceptable values to a
set of choices.
- Since:
- 1.0
- Version:
- 1.0
- API Note:
- Implementations do not have to verify in parsing that the received raw value is one of the valid choices. The system will automatically do this verification before invoking the parser.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordChoicesParser.Choice<P extends @NonNull Object>A possible choice to be selected.Nested classes/interfaces inherited from interface dev.sympho.modular_commands.api.command.parameter.parse.ParserFunction
ParserFunction.PostParser<R extends @NonNull Object,I extends @NonNull Object, T extends @NonNull Object, P1 extends @NonNull ParserFunction<R, I>, P2 extends @NonNull ParserFunction<I, T>> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe maximum number of choices allowed. -
Method Summary
Modifier and TypeMethodDescriptiondefault @Nullable List<ChoicesParser.Choice<P>>choices()The allowed choices.default PvalidateRaw(P raw) Validates the raw value before parsing.default PverifyChoice(P value) Verifies that the given value is one of the allowed choices.Methods inherited from interface dev.sympho.modular_commands.api.command.parameter.parse.ArgumentParser
parse, parseArgumentMethods inherited from interface java.util.function.BiFunction
andThenMethods inherited from interface dev.sympho.modular_commands.api.command.parameter.parse.ParserFunction
apply, then
-
Field Details
-
MAX_CHOICES
static final int MAX_CHOICESThe maximum number of choices allowed.- See Also:
-
-
Method Details
-
choices
The allowed choices.- Returns:
- The choices, or
nullif any value is allowed. Must have between 1 and 25 elements if notnull.
-
verifyChoice
Verifies that the given value is one of the allowed choices.- Parameters:
value- The value to validate.- Returns:
- The value.
- Throws:
InvalidArgumentException- If the value is not a valid choice.
-
validateRaw
Description copied from interface:ArgumentParserValidates the raw value before parsing.- Specified by:
validateRawin interfaceArgumentParser<P extends @NonNull Object,T extends @NonNull Object> - Parameters:
raw- The raw value.- Returns:
- The raw value.
- Throws:
InvalidArgumentException- if the value is invalid.
-