Package com.calebleavell.jatui.modules
Class ModuleFactory
java.lang.Object
com.calebleavell.jatui.modules.ModuleFactory
Provides abstractions for common TUI patterns.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FunctionModule.Buildercounter(String name, ApplicationModule app) Returns a Function Module that increments a counter every time it's run (starts at 1).static FunctionModule.Buildercounter(String name, ApplicationModule app, int begin, int step) Returns a Function Module that increments a counter every time it's run (starts at 1).static ContainerModule.BuilderReturns an emptyContainerModule- simply wrapsstatic FunctionModule.BuilderRestartsmoduleToRestartwhen the returnedFunctionModuleis run.static FunctionModule.BuilderRestartsmoduleToRestartwhen the returnedFunctionModuleis run.static FunctionModule.BuilderReturns a Function Module that finds the child of a parent by name then runs it.static FunctionModule.BuilderReturns aFunctionModulethat calls another module's terminate method.static FunctionModule.BuilderReturns aFunctionModulethat terminates the child of namemoduleToTerminatethat is a child ofparent.
-
Constructor Details
-
ModuleFactory
public ModuleFactory()
-
-
Method Details
-
empty
Returns an emptyContainerModule- simply wraps
to allow for code that consistently uses ModuleFactory if desired.ContainerModule.builder([name])- Parameters:
name- The name of the module- Returns:
- The empty
ContainerModule
-
terminate
Returns aFunctionModulethat calls another module's terminate method.- Parameters:
name- The name of this module (the one that is returned).moduleToTerminate- The module to terminate (it will terminate when this module is run)- Returns:
- The
FunctionModulethat terminates the inputted module
-
terminate
public static FunctionModule.Builder terminate(String name, String moduleToTerminate, TUIModule parent) Returns aFunctionModulethat terminates the child of namemoduleToTerminatethat is a child ofparent.
Note:moduleToTerminatedoesn't have to be a direct child ofparent. It can be multiple layers deep.- Parameters:
name- The name of this module (the one that is returned).moduleToTerminate- The name of the module to terminateparent- The parent module that will terminate the module- Returns:
- The
FunctionModulethat terminates the module corresponding tomoduleToTerminate
-
run
Returns a Function Module that finds the child of a parent by name then runs it. Will do nothing if the parent's module tree does not have a child with the given name. Nothing happens ifparentModuleisn't running when the returnedFunctionModuleruns.
Note:parentModuleis usually theApplicationModulefor the program.- Parameters:
name- The name of this module (the one that is returned).parent- The module that the module to run is the child of (directly or indirectly)moduleToRun- The name of the module to run (it will run when this module is run)- Returns:
- The
FunctionModulethat calls another module's run method - Implementation Note:
- Runs
moduleToRunviaTUIModule.navigateTo(TUIModule.Builder)to ensure there is only one scheduler.
-
restart
RestartsmoduleToRestartwhen the returnedFunctionModuleis run. Nothing happens ifmoduleToRestartisn't running.- Parameters:
name- The name of this module (the one that is returned).moduleToRestart- The module that will be restarted.- Returns:
- The
FunctionModulethat will restartmoduleToRestartwhen run.
-
restart
RestartsmoduleToRestartwhen the returnedFunctionModuleis run. Nothing happens ifmoduleToRestartisn't running.- Parameters:
name- The name of this module (the one that is returned).parent- The module thatmoduleToRestartis the child of (directly or indirectly)moduleToRestart- The module that will be restarted.- Returns:
- The
FunctionModulethat will restartmoduleToRestartwhen run. - Implementation Note:
- Calls
TUIModule.restartChild(String)and thus is dependent on the behavior of the implementation of that method.
-
counter
Returns a Function Module that increments a counter every time it's run (starts at 1). To access the counter, call
[app].getInput([name], Integer.class)).
Note that this will likely be null before this module is run.- Parameters:
name- The name of the module to be returnedapp- The Application Module that this module will be the child of- Returns:
- The Function Module that increments a counter
-
counter
public static FunctionModule.Builder counter(String name, ApplicationModule app, int begin, int step) Returns a Function Module that increments a counter every time it's run (starts at 1). To access the counter, call
[app].getInput([name], Integer.class)).
Note that this will likely be null before this module is run.- Parameters:
name- The name of the module to be returnedapp- The Application Module that this module will be the child ofbegin- The number to begin at (e.g. begin = 5 -> 5, 6, 7, 8, ...)step- The amount to increment each time (e.g. step = 5 -> 1, 6, 11, ...)- Returns:
- The Function Module that increments a counter
-