Package com.calebleavell.jatui.modules
Class ApplicationModule
java.lang.Object
com.calebleavell.jatui.modules.TUIModule
com.calebleavell.jatui.modules.ApplicationModule
The root TUIModule of an application. This class handles:
- Arbitrary Input storage/management
- Entering/Exiting the TUI (via Home and onExit)
- Name collision enforcement (logging)
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class com.calebleavell.jatui.modules.TUIModule
TUIModule.Property -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final TUIModule.Builder<?> The module that runs by default when the application finishes runningFields inherited from class com.calebleavell.jatui.modules.TUIModule
DEFAULT_SCANNER, logger, restart, UNNAMED_ERROR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ApplicationModule.BuilderConstructs a newApplicationModulebuilder.voidThe module-specific logic to run.voidforceUpdateInput(String identifier, Object input) Updates the input ininputMap, where the key isidentifierand the value isinput.getHome()The home of aApplicationModuleis simply it's first child.Return the input corresponding to a given name.<T> TReturns the input for the given module only if 1.<T> TgetInputOrDefault(String inputName, Class<T> type, T defaultValue) Returns the input for the given module only if 1.The onExit of aApplicationModuleis not a child of the application module.voidClears the hashmap of inputs for reuse.voidsetHome(TUIModule.Builder<?> home) The home of aApplicationModuleis simply it's first child.voidsetOnExit(TUIModule.Builder<?> onExit) The onExit of aApplicationModuleis not a child of the application module.voidstart()OverridesTUIModule.start().booleanChecks equality for properties given by the builder.voidupdateInput(TUIModule module, Object input) Updates the input ininputMap, where the key is the name ofmoduleand the value isinput.voidupdateInput(String moduleName, Object input) Updates the input ininputMap, where the key ismoduleNameand the value isinput.Methods inherited from class com.calebleavell.jatui.modules.TUIModule
getAnsi, getAnsiEnabled, getApplication, getChild, getChild, getChildren, getCurrentRunningBranch, getCurrentRunningChild, getCurrentRunningChild, getName, getPrintStream, getScanner, navigateTo, restart, restartChild, shallowStructuralEquals, structuralEquals, terminate, terminateChild, toString, toTreeString, toTreeString
-
Field Details
-
DEFAULT_EXIT
The module that runs by default when the application finishes running
-
-
Constructor Details
-
ApplicationModule
Builds aApplicationModulebased on the state ofbuilder- Parameters:
builder- TheApplicationModule.Builderthat is building the module.
-
-
Method Details
-
start
public void start()OverridesTUIModule.start().
Checks and logs name duplicates, runs children (where "home" is the first child), and then runsonExitif not disabled. -
doRunLogic
public void doRunLogic()Description copied from class:TUIModuleThe module-specific logic to run.- Specified by:
doRunLogicin classTUIModule
-
resetMemory
public void resetMemory()Clears the hashmap of inputs for reuse. Fills all char arrays with spaces for security. -
getInput
Return the input corresponding to a given name.- Parameters:
inputName- The name that corresponds to the requested input. In general, this is the name of the module that supplied the input (it may also just be the provided name of the input ifforceUpdateInput(String, Object)is used.
Also seegetInput(String, Class)andgetInputOrDefault(String, Class, Object)- Returns:
- The input corresponding to
inputName, or null if it doesn't exist.
-
getInput
Returns the input for the given module only if 1. it exists 2. it is of the correct type.- Type Parameters:
T- The type to safely cast to.- Parameters:
inputName- The name that corresponds to the requested input. In general, this is the * name of the module that supplied the input (it may also just be the * provided name of the input ifforceUpdateInput(String, Object)* is used.type- The class type of the input- Returns:
- The input, which will be the same type as the "type" parameter, or null if it either doesn't exist in general or doesn't exist of the provided type.
-
getInputOrDefault
Returns the input for the given module only if 1. it exists 2. it is of the correct type.- Type Parameters:
T- The type to safely cast to.- Parameters:
inputName- The name that corresponds to the requested input. In general, this is the name of the module that supplied the input (it may also just be the provided name of the input ifforceUpdateInput(String, Object)is used.type- The class type of the inputdefaultValue- The value to return if the requested value doesn't exist.- Returns:
- The input, which will be the same type as the "type" parameter, or
defaultValueif it either doesn't exist in general or doesn't exist of the provided type.
-
updateInput
Updates the input ininputMap, where the key is the name ofmoduleand the value isinput.
In general, it shouldn't be necessary to update input apart from a TUIModule, but if it is needed, useforceUpdateInput(String, Object).- Parameters:
module- The module whose name corresponds to the input.input- The new input to store.
-
updateInput
Updates the input ininputMap, where the key ismoduleNameand the value isinput. Note that this searches for an existing module attached to this application module, and if none is found, the input will not be updated.
In general, it shouldn't be necessary to update input apart from a TUIModule, but if it is needed, useforceUpdateInput(String, Object).- Parameters:
moduleName- The name of an existing module that corresponds to the input.input- The new input to store.
-
forceUpdateInput
Updates the input ininputMap, where the key isidentifierand the value isinput. This always updates input, regardless of whether a corresponding module exists or not. Be aware that this can make it more difficult to debug the state of the application.- Parameters:
identifier- The name of the input.input- The new input to store.
-
setHome
The home of aApplicationModuleis simply it's first child. This means it will be the first module to run when this application is run.- Parameters:
home- The first module to run when this application is run.
-
getHome
The home of aApplicationModuleis simply it's first child. This means it will be the first module to run when this application is run.- Returns:
- The home of this application module.
-
setOnExit
The onExit of aApplicationModuleis not a child of the application module. It is a distinct module to run after every child has completed running.- Parameters:
onExit- The module that runs at the end of this application module's run.
-
getOnExit
The onExit of aApplicationModuleis not a child of the application module. It is a distinct module to run after every child has completed running.- Returns:
- The module that runs at the end of this application module's run.
-
structuralEquals
Checks equality for properties given by the builder. ForApplicationModule, this includesonExit, as well as other requirements provided byTUIModule.structuralEquals(TUIModule). -
builder
Constructs a newApplicationModulebuilder.- Parameters:
name- The name of the builder.- Returns:
- The new builder.
-