T - the value type@NonnullByDefault public interface ArgumentParser<T>
| Modifier and Type | Method and Description |
|---|---|
default CommandInterruptException |
generateException(int missingArgumentIndex)
Generates a
CommandInterruptException for when parsing fails due to the lack of an argument. |
default CommandInterruptException |
generateException(String s)
Generates a
CommandInterruptException for when parsing fails with the given content. |
static <T> ArgumentParser<T> |
of(Function<String,Optional<T>> parseFunction) |
static <T> ArgumentParser<T> |
of(Function<String,Optional<T>> parseFunction,
Function<String,CommandInterruptException> generateExceptionFunction) |
default Optional<T> |
parse(Argument argument)
Tries to parse the value from the argument
|
Optional<T> |
parse(String s)
Parses the value from a string
|
default T |
parseOrFail(Argument argument)
Parses the value from an argument, throwing an interrupt exception if
parsing failed.
|
default T |
parseOrFail(String s)
Parses the value from a string, throwing an interrupt exception if
parsing failed.
|
default ArgumentParser<T> |
thenTry(ArgumentParser<T> other)
Creates a new parser which first tries to obtain a value from
this parser, then from another if the former was not successful.
|
static <T> ArgumentParser<T> of(Function<String,Optional<T>> parseFunction)
static <T> ArgumentParser<T> of(Function<String,Optional<T>> parseFunction, Function<String,CommandInterruptException> generateExceptionFunction)
Optional<T> parse(@Nonnull String s)
s - the stringdefault CommandInterruptException generateException(@Nonnull String s)
CommandInterruptException for when parsing fails with the given content.s - the string inputdefault CommandInterruptException generateException(int missingArgumentIndex)
CommandInterruptException for when parsing fails due to the lack of an argument.missingArgumentIndex - the missing argument index@Nonnull default T parseOrFail(@Nonnull String s) throws CommandInterruptException
s - the stringCommandInterruptException@Nonnull default Optional<T> parse(@Nonnull Argument argument)
argument - the argument@Nonnull default T parseOrFail(@Nonnull Argument argument) throws CommandInterruptException
argument - the argumentCommandInterruptException@Nonnull default ArgumentParser<T> thenTry(@Nonnull ArgumentParser<T> other)
other - the other parserCopyright © 2020. All rights reserved.