Package com.calebleavell.jatui.modules
Class ModuleTemplate<B extends ModuleTemplate<B>>
java.lang.Object
com.calebleavell.jatui.modules.TUIModule.Builder<B>
com.calebleavell.jatui.modules.ModuleTemplate<B>
- Type Parameters:
B- The class extending this (e.g.,class MyTemplate extends ModuleTemplate<MyTemplate>).
- All Implemented Interfaces:
DirectedGraphNode<TUIModule.Property,TUIModule.Builder<?>, B>
- Direct Known Subclasses:
ConfirmationPrompt,InputHandler,NumberedList,NumberedModuleSelector,PasswordInput,TextChain
This class is an extension of
This adds the child at index 2, potentially puts the new child inside the automatically added children and breaking the atomicity of the template (i.e., that it runs as intended before user-added logic runs). Putting the children inside
Template also enforces building to a
TUIModule.Builder that provides a main field
which will be accessible inside the class extending this. The purpose of main is
to separate children added from inside the class from children added from whoever is
instantiating the class. For example, suppose MyTemplate extends Template, and a user
calls it as follows:
MyTemplate = new MyTemplate("template").addChild(child, 2)
This adds the child at index 2, potentially puts the new child inside the automatically added children and breaking the atomicity of the template (i.e., that it runs as intended before user-added logic runs). Putting the children inside
main ensures all automatically added children
run as expected and are organized.
Template also enforces building to a
ContainerModule, which improves modularity.-
Nested Class Summary
Nested classes/interfaces inherited from interface com.calebleavell.jatui.core.DirectedGraphNode
DirectedGraphNode.PropertyUpdateFlag -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ContainerModule.BuilderA container for separating children essential to the function of the class from children added after instantiation.Fields inherited from class com.calebleavell.jatui.modules.TUIModule.Builder
ansi, application, children, enableAnsi, logger, name, printStream, propertyUpdateFlags, scanner, type, usedNames -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedModuleTemplate(Class<B> type) Creates a fresh instance for copying utility.ModuleTemplate(Class<B> type, String name) Creates the new Template and addsmainas the first child. -
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds the finalized ContainerModule
Note: If you are going to override this method, ensure any changes made to main or other children are reset each time it's called.protected BdeepCopy(B original, Map<TUIModule.Builder<?>, TUIModule.Builder<?>> visited) Copies all data oforiginalinto this module, including a deep copy of all children.Methods inherited from class com.calebleavell.jatui.modules.TUIModule.Builder
addChild, addChild, addChildren, addChildren, appendStyle, application, clearChildren, createInstance, deepCopy, enableAnsi, getAnsi, getAnsiEnabled, getApplication, getChild, getChild, getChildren, getCopy, getDeepCopy, getName, getPrintStream, getPropertyUpdateFlags, getScanner, getType, lockProperty, name, prependStyle, prependToName, printStream, scanner, self, shallowCopy, shallowStructuralEquals, structuralEquals, style, toString, unlockProperty, updateFlag, updatePropertiesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.calebleavell.jatui.core.DirectedGraphNode
abstractSelf, containsNullNode, containsNullNode, dfs, dfs, forEach, forEachChild, structuralEquals, structuralEquals, updateProperty, updateProperty
-
Field Details
-
main
A container for separating children essential to the function of the class from children added after instantiation. SeeTUIModulefor intuition.
-
-
Constructor Details
-
ModuleTemplate
Creates the new Template and addsmainas the first child.- Parameters:
type- The type of the class extendingModuleTemplatename- The unique identifier for the module.
-
ModuleTemplate
Creates a fresh instance for copying utility.- Parameters:
type- The type of the class extendingModuleTemplate
-
-
Method Details
-
deepCopy
Copies all data oforiginalinto this module, including a deep copy of all children.- Overrides:
deepCopyin classTUIModule.Builder<B extends ModuleTemplate<B>>- Parameters:
original- The module to copy from.visited- All children that have already been deep-copied.- Returns:
- The instance that was copied into (self if
originalhasn't been visited yet). - Implementation Note:
- Re-assigns
mainto the copy that was created from the recursive children copying.
-
build
Builds the finalized ContainerModule
Note: If you are going to override this method, ensure any changes made to main or other children are reset each time it's called. We want to ensure calling build() multiple times returns the same output. Most likely, you'll want to call main.clearChildren() as the first line of the override.- Specified by:
buildin classTUIModule.Builder<B extends ModuleTemplate<B>>- Returns:
- The built ContainerModule
-