Class ApplicationModule

java.lang.Object
com.calebleavell.jatui.modules.TUIModule
com.calebleavell.jatui.modules.ApplicationModule

public class ApplicationModule extends TUIModule
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)
  • Field Details

    • DEFAULT_EXIT

      public static final TUIModule.Builder<?> DEFAULT_EXIT
      The module that runs by default when the application finishes running
  • Constructor Details

  • Method Details

    • start

      public void start()
      Overrides TUIModule.start().
      Checks and logs name duplicates, runs children (where "home" is the first child), and then runs onExit if not disabled.
      Overrides:
      start in class TUIModule
      Implementation Note:
      overrides run instead of shallowRun to ensure onExit runs exactly once per run, regardless of restarting or termination.
    • doRunLogic

      public void doRunLogic()
      Description copied from class: TUIModule
      The module-specific logic to run.
      Specified by:
      doRunLogic in class TUIModule
    • resetMemory

      public void resetMemory()
      Clears the hashmap of inputs for reuse. Fills all char arrays with spaces for security.
    • getInput

      public Object getInput(String inputName)
      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 if forceUpdateInput(String, Object) is used.

      Also see getInput(String, Class) and getInputOrDefault(String, Class, Object)
      Returns:
      The input corresponding to inputName, or null if it doesn't exist.
    • getInput

      public <T> T getInput(String inputName, Class<T> type)
      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 if forceUpdateInput(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

      public <T> T getInputOrDefault(String inputName, Class<T> type, T defaultValue)
      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 if forceUpdateInput(String, Object) is used.
      type - The class type of the input
      defaultValue - 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 defaultValue if it either doesn't exist in general or doesn't exist of the provided type.
    • updateInput

      public void updateInput(TUIModule module, Object input)
      Updates the input in inputMap, where the key is the name of module and the value is input.
      In general, it shouldn't be necessary to update input apart from a TUIModule, but if it is needed, use forceUpdateInput(String, Object).
      Parameters:
      module - The module whose name corresponds to the input.
      input - The new input to store.
    • updateInput

      public void updateInput(String moduleName, Object input)
      Updates the input in inputMap, where the key is moduleName and the value is input. 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, use forceUpdateInput(String, Object).
      Parameters:
      moduleName - The name of an existing module that corresponds to the input.
      input - The new input to store.
    • forceUpdateInput

      public void forceUpdateInput(String identifier, Object input)
      Updates the input in inputMap, where the key is identifier and the value is input. 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

      public void setHome(TUIModule.Builder<?> home)
      The home of a ApplicationModule is 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

      public TUIModule.Builder<?> getHome()
      The home of a ApplicationModule is 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

      public void setOnExit(TUIModule.Builder<?> onExit)
      The onExit of a ApplicationModule is 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

      public TUIModule.Builder<?> getOnExit()
      The onExit of a ApplicationModule is 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

      public boolean structuralEquals(ApplicationModule other)
      Checks equality for properties given by the builder. For ApplicationModule, this includes onExit, as well as other requirements provided by TUIModule.structuralEquals(TUIModule).
    • builder

      public static ApplicationModule.Builder builder(String name)
      Constructs a new ApplicationModule builder.
      Parameters:
      name - The name of the builder.
      Returns:
      The new builder.