Class ModuleFactory

java.lang.Object
com.calebleavell.jatui.modules.ModuleFactory

public class ModuleFactory extends Object
Provides abstractions for common TUI patterns.
  • Constructor Details

    • ModuleFactory

      public ModuleFactory()
  • Method Details

    • empty

      public static ContainerModule.Builder empty(String name)
      Returns an empty ContainerModule - simply wraps
      ContainerModule.builder([name])
      to allow for code that consistently uses ModuleFactory if desired.
      Parameters:
      name - The name of the module
      Returns:
      The empty ContainerModule
    • terminate

      public static FunctionModule.Builder terminate(String name, TUIModule moduleToTerminate)
      Returns a FunctionModule that 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 FunctionModule that terminates the inputted module
    • terminate

      public static FunctionModule.Builder terminate(String name, String moduleToTerminate, TUIModule parent)
      Returns a FunctionModule that terminates the child of name moduleToTerminate that is a child of parent.
      Note: moduleToTerminate doesn't have to be a direct child of parent. 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 terminate
      parent - The parent module that will terminate the module
      Returns:
      The FunctionModule that terminates the module corresponding to moduleToTerminate
    • run

      public static FunctionModule.Builder run(String name, TUIModule parent, String moduleToRun)
      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 if parentModule isn't running when the returned FunctionModule runs.
      Note: parentModule is usually the ApplicationModule for 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 FunctionModule that calls another module's run method
      Implementation Note:
      Runs moduleToRun via TUIModule.navigateTo(TUIModule.Builder) to ensure there is only one scheduler.
    • restart

      public static FunctionModule.Builder restart(String name, TUIModule moduleToRestart)
      Restarts moduleToRestart when the returned FunctionModule is run. Nothing happens if moduleToRestart isn't running.
      Parameters:
      name - The name of this module (the one that is returned).
      moduleToRestart - The module that will be restarted.
      Returns:
      The FunctionModule that will restart moduleToRestart when run.
    • restart

      public static FunctionModule.Builder restart(String name, TUIModule parent, String moduleToRestart)
      Restarts moduleToRestart when the returned FunctionModule is run. Nothing happens if moduleToRestart isn't running.
      Parameters:
      name - The name of this module (the one that is returned).
      parent - The module that moduleToRestart is the child of (directly or indirectly)
      moduleToRestart - The module that will be restarted.
      Returns:
      The FunctionModule that will restart moduleToRestart when run.
      Implementation Note:
      Calls TUIModule.restartChild(String) and thus is dependent on the behavior of the implementation of that method.
    • counter

      public static FunctionModule.Builder counter(String name, ApplicationModule app)
      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 returned
      app - 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 returned
      app - The Application Module that this module will be the child of
      begin - 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