Class ContextualMapBasedParser<T>
java.lang.Object
net.apartium.cocoabeans.commands.parsers.ArgumentParser<T>
net.apartium.cocoabeans.commands.parsers.ContextualMapBasedParser<T>
- Type Parameters:
T- result type
- All Implemented Interfaces:
Comparable<ArgumentParser<?>>
- Direct Known Subclasses:
MapBasedParser
@AvailableSince("0.0.39")
public abstract class ContextualMapBasedParser<T>
extends ArgumentParser<T>
Contextual Map-based parser that map of keyword to value
When Map entry not found report
NoSuchElementInMapResponse- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class net.apartium.cocoabeans.commands.parsers.ArgumentParser
ArgumentParser.ParseResult<T>, ArgumentParser.TabCompletionResult -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedContextualMapBasedParser(String keyword, Class<T> clazz, int priority) ConstructorprotectedContextualMapBasedParser(String keyword, Class<T> clazz, int priority, boolean ignoreCase) Constructor with an ignoreCaseprotectedContextualMapBasedParser(String keyword, Class<T> clazz, int priority, boolean ignoreCase, boolean lax) Constructor with an ignoreCase and lax -
Method Summary
Modifier and TypeMethodDescriptiongetMap(CommandProcessingContext context) If you want to ignore case to be applied, then remember to lowercase the keywordparse(CommandProcessingContext commandProcessingContext) Tries to parse next argument in the contexttabCompletion(CommandProcessingContext commandProcessingContext) Retrieves available options for tab completion of this argumenttryParse(CommandProcessingContext commandProcessingContext) Tries to lazily parse next argument in the contextMethods inherited from class net.apartium.cocoabeans.commands.parsers.ArgumentParser
compareTo, getArgumentType, getKeyword, getPriority
-
Constructor Details
-
ContextualMapBasedParser
Constructor- Parameters:
keyword- keywordclazz- result classpriority- priority
-
ContextualMapBasedParser
protected ContextualMapBasedParser(String keyword, Class<T> clazz, int priority, boolean ignoreCase) Constructor with an ignoreCase- Parameters:
keyword- keywordclazz- result classpriority- priorityignoreCase- whether is it case-sensitive or not
-
ContextualMapBasedParser
protected ContextualMapBasedParser(String keyword, Class<T> clazz, int priority, boolean ignoreCase, boolean lax) Constructor with an ignoreCase and lax- Parameters:
keyword- keywordclazz- result classpriority- priorityignoreCase- whether is it case-sensitive or notlax- lazy mapping
-
-
Method Details
-
getMap
If you want to ignore case to be applied, then remember to lowercase the keyword- Parameters:
context- the context that you can use to change the map for it- Returns:
- map of keyword to value
-
parse
public Optional<ArgumentParser.ParseResult<T>> parse(CommandProcessingContext commandProcessingContext) Description copied from class:ArgumentParserTries to parse next argument in the context- Specified by:
parsein classArgumentParser<T>- Parameters:
commandProcessingContext- cmd processing context- Returns:
- empty if failed, otherwise result
-
tryParse
Description copied from class:ArgumentParserTries to lazily parse next argument in the context- Specified by:
tryParsein classArgumentParser<T>- Parameters:
commandProcessingContext- cmd processing context- Returns:
- new index int if success, empty if not
-
tabCompletion
public Optional<ArgumentParser.TabCompletionResult> tabCompletion(CommandProcessingContext commandProcessingContext) Description copied from class:ArgumentParserRetrieves available options for tab completion of this argument- Specified by:
tabCompletionin classArgumentParser<T>- Parameters:
commandProcessingContext- cmd processing context- Returns:
- tab completion result if success, otherwise empty option
-