Class GenericScene

java.lang.Object
com.calebleavell.textinterface.scenes.GenericScene
All Implemented Interfaces:
Function, Scene
Direct Known Subclasses:
ContainerScene, NumberedListInputScene, NumberedListScene, NumberedSceneSelectorScene, TextApplication, TextInputScene, TextScene

public abstract class GenericScene extends Object implements Scene

GenericScene Class

A simple, abstract implementation of the Scene interface

This class is easily extendable, but subclasses will be more difficult (due to the way the Builder pattern is implemented)

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Uses a Builder design pattern Extending this class makes extending this Builder easy, but extending any subclasses of this class will be difficult
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static int
    The number of layers of children to add to the toString()
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Takes a builder and extracts necessary fields out of it
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addChild(Scene child)
    Add a child to the list of children
    void
    Linearlly executes each function
    getChild(long ID)
    Executes a depth-first seach on the children Returns the first child with name matching param ID Unlike searching by name, there will only ever be up to one matching child
    <T extends Scene>
    T
    getChild(long ID, Class<T> intendedClass)
    Attempts to find a child scene that matches the ID and type of Scene Executes a depth-first search
    Executes a depth-first seach on the children Returns the first child with name matching param name
    <T extends Scene>
    T
    getChild(String name, Class<T> intendedClass)
    Attempts to find a child scene that matches the name and type of Scene Executes a depth-first search
    Getter for children
    Getter for functions
    long
    Getter for id
    Getter for name
    boolean
    Return whether or not the scene is in a termninated state note that the scene comes out of a termniated state when it is run again
    void
    run()
    Executes its functions, then displays its children
    void
    Linearly displays Children
    void
    setChildren(List<Scene> children)
    Setter for children
    void
    Setter for name
    void
    Terminates scene execution
    Recursively generates toString with info for this scene and all children Will only go as deep as MAX_ITERATIONS_ON_TOSTRING
    toString(int indent, boolean displayChildren)
    recursive helper method for toString()

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • MAX_ITERATIONS_ON_TOSTRING

      public static int MAX_ITERATIONS_ON_TOSTRING
      The number of layers of children to add to the toString()
  • Constructor Details

    • GenericScene

      protected GenericScene(GenericScene.Builder<?> builder)
      Takes a builder and extracts necessary fields out of it
      Parameters:
      builder - a GenericScene.Builder (or something that extends it)
  • Method Details

    • run

      public void run() throws Exception
      Executes its functions, then displays its children
      Specified by:
      run in interface Function
      Throws:
      Exception
    • getName

      public String getName()
      Getter for name
      Specified by:
      getName in interface Scene
      Returns:
      the current name of the scene
    • setName

      public void setName(String name)
      Setter for name
      Specified by:
      setName in interface Scene
      Parameters:
      name - - the new name fore the scene
    • getID

      public long getID()
      Getter for id
      Specified by:
      getID in interface Scene
      Returns:
      the scene id - the id is a unique, immutable identifier
    • getChildren

      public List<Scene> getChildren()
      Getter for children
      Specified by:
      getChildren in interface Scene
      Returns:
      the list of child scenes attatched to the scene
    • setChildren

      public void setChildren(List<Scene> children)
      Setter for children
      Specified by:
      setChildren in interface Scene
      Parameters:
      children - the new list of child scenes
    • addChild

      public void addChild(Scene child)
      Add a child to the list of children
      Specified by:
      addChild in interface Scene
      Parameters:
      child - the new child to be added
    • runChildren

      public void runChildren() throws Exception
      Linearly displays Children
      Specified by:
      runChildren in interface Scene
      Throws:
      Exception
    • getFunctions

      public List<Function> getFunctions()
      Getter for functions
      Specified by:
      getFunctions in interface Scene
      Returns:
      the list of functions it can execute
    • executeFunctions

      public void executeFunctions() throws Exception
      Linearlly executes each function
      Specified by:
      executeFunctions in interface Scene
      Throws:
      Exception
    • getChild

      public Scene getChild(String name)
      Executes a depth-first seach on the children Returns the first child with name matching param name
      Specified by:
      getChild in interface Scene
      Parameters:
      name - the name to search for
      Returns:
      the first child that matches name
    • getChild

      public Scene getChild(long ID)
      Executes a depth-first seach on the children Returns the first child with name matching param ID Unlike searching by name, there will only ever be up to one matching child
      Specified by:
      getChild in interface Scene
      Parameters:
      ID - the ID to search for
      Returns:
      the first child that matches ID
    • getChild

      public <T extends Scene> T getChild(String name, Class<T> intendedClass)
      Attempts to find a child scene that matches the name and type of Scene Executes a depth-first search
      Specified by:
      getChild in interface Scene
      Type Parameters:
      T - the desired type to find
      Parameters:
      name - the name of the class to find
      intendedClass - the indended class of the child to find
      Returns:
      the found child, or null if no child is found
    • getChild

      public <T extends Scene> T getChild(long ID, Class<T> intendedClass)
      Attempts to find a child scene that matches the ID and type of Scene Executes a depth-first search
      Specified by:
      getChild in interface Scene
      Type Parameters:
      T - the desired type to find
      Parameters:
      ID - the id of the class to find
      intendedClass - the indended class of the child to find
      Returns:
      the found child, or null if no child is found
    • terminate

      public void terminate()
      Terminates scene execution
      Specified by:
      terminate in interface Scene
    • isTerminated

      public boolean isTerminated()
      Return whether or not the scene is in a termninated state note that the scene comes out of a termniated state when it is run again
      Specified by:
      isTerminated in interface Scene
      Returns:
      whether or not the scene is in a terminate state
    • toString

      public String toString()
      Recursively generates toString with info for this scene and all children Will only go as deep as MAX_ITERATIONS_ON_TOSTRING
      Overrides:
      toString in class Object
      Returns:
      formatted string
    • toString

      public String toString(int indent, boolean displayChildren)
      recursive helper method for toString()
      Specified by:
      toString in interface Scene
      Parameters:
      indent - the amount of tab (base case call is 0)
      Returns:
      the formatted string of the object and its children