Package kboyle.oktane.core
Class CommandHandler.Builder<CONTEXT extends CommandContext>
java.lang.Object
kboyle.oktane.core.CommandHandler.Builder<CONTEXT>
- Type Parameters:
CONTEXT
- The type of context that's used in commands.
- Enclosing class:
- CommandHandler<CONTEXT extends CommandContext>
A builder for the
CommandHandler
.-
Method Summary
Modifier and TypeMethodDescriptionapplyConfigurator(CommandHandlerConfigurator configurator)
Applies the givenCommandHandlerConfigurator
to theCommandHandler.Builder
.build()
Builds theCommandHandler
.withArgumentParser(ArgumentParser argumentParser)
Sets theArgumentParser
that will be used, if none is specified then the default will be used.withBeanProvider(BeanProvider beanProvider)
Adds theBeanProvider
that will be used to fetch dependencies for singletonCommandModule
s.<MODULE extends ModuleBase<CONTEXT>>
CommandHandler.Builder<CONTEXT>withModule(Class<MODULE> moduleClass)
Adds aCommandModule
that will be used by theCommandHandler
.<MODULE extends ModuleBase<CONTEXT>>
CommandHandler.Builder<CONTEXT>withModule(Class<MODULE> moduleClass, Consumer<CommandModule.Builder> builderConsumer)
Adds aCommandModule
that will be used by theCommandHandler
.withModule(Consumer<CommandModule.Builder> builderConsumer)
Adds aCommandModule
using only the builders and not from a class.<MODULE extends ModuleBase<CONTEXT>>
CommandHandler.Builder<CONTEXT>withModules(Class<MODULE> moduleClass)
Adds all theCommandModule
's that link in the same package as themoduleClass
.<MODULE extends ModuleBase<CONTEXT>>
CommandHandler.Builder<CONTEXT>withModules(Class<MODULE> moduleClass, Consumer<CommandModule.Builder> builderConsumer)
Adds all theCommandModule
's that link in the same package as themoduleClass
.withPreconditionFactory(PreconditionFactory<?> factory)
Adds aPreconditionFactory
that will be used to instantiate preconditions.withPrefixHandler(PrefixHandler prefixHandler)
Sets thePrefixHandler
that will be used to supply prefixes.withTokeniser(Tokeniser tokeniser)
Sets theTokeniser
that will be used, if none is specified then the default will be used.<TARGET> CommandHandler.Builder<CONTEXT>
withTypeParser(Class<TARGET> cl, TypeParser<TARGET> parser)
Adds aTypeParser
that will be used by theCommandHandler
.
-
Method Details
-
withTypeParser
public <TARGET> CommandHandler.Builder<CONTEXT> withTypeParser(Class<TARGET> cl, TypeParser<TARGET> parser)Adds aTypeParser
that will be used by theCommandHandler
.- Type Parameters:
TARGET
- The type that theTypeParser
is for.- Parameters:
cl
- The class representing the type that theTypeParser
is for.parser
- TheTypeParser
.- Returns:
- The
CommandHandler.Builder
. - Throws:
NullPointerException
- whencl
is null.NullPointerException
- whenparser
is null.
-
withModule
Adds aCommandModule
using only the builders and not from a class.- Parameters:
builderConsumer
- A consumer used to modify the state of theCommandModule.Builder
.- Returns:
- The
CommandHandler.Builder
. - Throws:
NullPointerException
- whenbuilderConsumer
is null.
-
withModule
public <MODULE extends ModuleBase<CONTEXT>> CommandHandler.Builder<CONTEXT> withModule(Class<MODULE> moduleClass)Adds aCommandModule
that will be used by theCommandHandler
.- Type Parameters:
MODULE
- The type of module you want to add.- Parameters:
moduleClass
- The class representing the type of module that you want to add.- Returns:
- The
CommandHandler.Builder
. - Throws:
NullPointerException
- whenmoduleClass
is null.
-
withModule
public <MODULE extends ModuleBase<CONTEXT>> CommandHandler.Builder<CONTEXT> withModule(Class<MODULE> moduleClass, Consumer<CommandModule.Builder> builderConsumer)Adds aCommandModule
that will be used by theCommandHandler
.- Type Parameters:
MODULE
- The type of module you want to add.- Parameters:
moduleClass
- The class representing the type of module that you want to add.builderConsumer
- A consumer used to modify the state of theCommandModule.Builder
.- Returns:
- The
CommandHandler.Builder
. - Throws:
NullPointerException
- whenmoduleClass
is null.NullPointerException
- whenbuilderConsumer
is null.
-
withModules
public <MODULE extends ModuleBase<CONTEXT>> CommandHandler.Builder<CONTEXT> withModules(Class<MODULE> moduleClass)Adds all theCommandModule
's that link in the same package as themoduleClass
. This method is not type safe and will add modules that don't inherit fromModuleBase<CONTEXT>
- Parameters:
moduleClass
- The module that lives in the same package as your other modules.- Returns:
- The
CommandHandler.Builder
. - Throws:
RuntimeIOException
- if the attempt to read class path resources (jar files or directories) failed.
-
withModules
public <MODULE extends ModuleBase<CONTEXT>> CommandHandler.Builder<CONTEXT> withModules(Class<MODULE> moduleClass, Consumer<CommandModule.Builder> builderConsumer)Adds all theCommandModule
's that link in the same package as themoduleClass
. This method is not type safe and will add modules that don't inherit fromModuleBase<CONTEXT>
- Parameters:
moduleClass
- The module that lives in the same package as your other modules.builderConsumer
- A consumer used to modify the state of theCommandModule.Builder
.- Returns:
- The
CommandHandler.Builder
. - Throws:
RuntimeIOException
- if the attempt to read class path resources (jar files or directories) failed.
-
withBeanProvider
Adds theBeanProvider
that will be used to fetch dependencies for singletonCommandModule
s.- Parameters:
beanProvider
- TheBeanProvider
.- Returns:
- The
CommandHandler.Builder
. - Throws:
NullPointerException
- whenbeanProvider
is null.
-
withArgumentParser
Sets theArgumentParser
that will be used, if none is specified then the default will be used.- Parameters:
argumentParser
- TheArgumentParser
.- Returns:
- The
CommandHandler.Builder
. - Throws:
NullPointerException
- whenargumentParser
is null.
-
withTokeniser
Sets theTokeniser
that will be used, if none is specified then the default will be used.- Parameters:
tokeniser
- TheTokeniser
.- Returns:
- The
CommandHandler.Builder
. - Throws:
NullPointerException
- whentokeniser
is null.
-
withPreconditionFactory
Adds aPreconditionFactory
that will be used to instantiate preconditions.- Parameters:
factory
- ThePreconditionFactory
that will be used instead ofPrecondition
of the given type.- Returns:
- The
CommandHandler.Builder
. - Throws:
NullPointerException
- whenfactory
is null.
-
withPrefixHandler
Sets thePrefixHandler
that will be used to supply prefixes.- Parameters:
prefixHandler
- ThePrefixHandler
to use.- Returns:
- The
CommandHandler.Builder
.
-
applyConfigurator
Applies the givenCommandHandlerConfigurator
to theCommandHandler.Builder
.- Parameters:
configurator
- TheCommandHandlerConfigurator
to apply.- Returns:
- The
CommandHandler.Builder
.
-
build
Builds theCommandHandler
.- Returns:
- The built
CommandHandler
.
-