Class BooleanParser<C>
- All Implemented Interfaces:
ArgumentParser<C,,Boolean> BlockingSuggestionProvider<C>,BlockingSuggestionProvider.Strings<C>,SuggestionProvider<C>,SuggestionProviderHolder<C>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBoolean parse exceptionNested classes/interfaces inherited from interface org.incendo.cloud.parser.ArgumentParser
ArgumentParser.FutureArgumentParser<C,T> Nested classes/interfaces inherited from interface org.incendo.cloud.suggestion.BlockingSuggestionProvider
BlockingSuggestionProvider.Strings<C> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <C> @NonNull CommandComponent.Builder<C, Boolean> Returns aCommandComponent.BuilderusingbooleanParser()as the parser.static <C> @NonNull ParserDescriptor<C, Boolean> Creates a new boolean parser that only acceptstrueandfalse.static <C> @NonNull ParserDescriptor<C, Boolean> booleanParser(boolean liberal) Creates a new boolean parser.parse(@NonNull CommandContext<C> commandContext, @NonNull CommandInput commandInput) Attempts to parse theinputinto an object of typeArgumentParser.stringSuggestions(@NonNull CommandContext<C> commandContext, @NonNull CommandInput input) Returns the suggestions for the giveninput.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.incendo.cloud.parser.ArgumentParser
flatMap, flatMapSuccess, mapSuccess, parseFuture, suggestionProviderMethods inherited from interface org.incendo.cloud.suggestion.BlockingSuggestionProvider
suggestionsFutureMethods inherited from interface org.incendo.cloud.suggestion.BlockingSuggestionProvider.Strings
suggestions
-
Constructor Details
-
BooleanParser
public BooleanParser(boolean liberal) Construct a new boolean parser- Parameters:
liberal- Whether it'll accept boolean-esque strings, or just booleans
-
-
Method Details
-
booleanParser
Creates a new boolean parser that only acceptstrueandfalse.- Type Parameters:
C- the command sender type- Returns:
- the created parser
-
booleanParser
@API(status=STABLE) public static <C> @NonNull ParserDescriptor<C,Boolean> booleanParser(boolean liberal) Creates a new boolean parser. Ifliberalistruethe parser only acceptstrueandfalse.- Type Parameters:
C- the command sender type- Parameters:
liberal- whether the parser should be liberal, seeCommandInput.isValidBoolean(boolean)- Returns:
- the created parser
-
booleanComponent
@API(status=STABLE) public static <C> @NonNull CommandComponent.Builder<C,Boolean> booleanComponent()Returns aCommandComponent.BuilderusingbooleanParser()as the parser.- Type Parameters:
C- the command sender type- Returns:
- the component builder
-
parse
public @NonNull ArgumentParseResult<Boolean> parse(@NonNull CommandContext<C> commandContext, @NonNull CommandInput commandInput) Description copied from interface:ArgumentParserAttempts to parse theinputinto an object of typeArgumentParser.This method may be called when a command chain is being parsed for execution (using
CommandExecutor.executeCommand(Object, String)) or when a command is being parsed to provide context for suggestions (usingSuggestionFactory.suggest(Object, String)). It is possible to useCommandContext.isSuggestions()} to see what the purpose of the parsing is. Particular care should be taken when parsing for suggestions, as the parsing method is then likely to be called once for every character written by the command sender.This method should never throw any exceptions under normal circumstances. Instead, if the parsing for some reason cannot be done successfully
ArgumentParseResult.failure(Throwable)should be returned. This then wraps any exception that should be forwarded to the command sender.The parser is assumed to be completely stateless and should not store any information about the command sender or the command context. Instead, information should be stored in the
CommandContext.- Specified by:
parsein interfaceArgumentParser<C,Boolean> - Parameters:
commandContext- Command contextcommandInput- Command Input- Returns:
- Parsed command result
-
stringSuggestions
public @NonNull Iterable<@NonNull String> stringSuggestions(@NonNull CommandContext<C> commandContext, @NonNull CommandInput input) Description copied from interface:BlockingSuggestionProvider.StringsReturns the suggestions for the giveninput.The
inputparameter contains all sender-provided input that has not yet been consumed by the argument parsers. If the component that the suggestion provider is generating suggestions for consumes multiple tokens the suggestion provider might receive aCommandInputinstance containing multiple tokens.CommandInput.lastRemainingToken()may be used to extract the part of the command that is currently being completed by the command sender.- Specified by:
stringSuggestionsin interfaceBlockingSuggestionProvider.Strings<C>- Parameters:
commandContext- Command contextinput- Input string- Returns:
- List of suggestions
-