Class GenericScene
java.lang.Object
com.calebleavell.textinterface.scenes.GenericScene
- Direct Known Subclasses:
ContainerScene
,NumberedListInputScene
,NumberedListScene
,NumberedSceneSelectorScene
,TextApplication
,TextInputScene
,TextScene
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 ClassesModifier and TypeClassDescriptionstatic class
GenericScene.Builder<B extends GenericScene.Builder<B>>
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
FieldsModifier and TypeFieldDescriptionstatic int
The number of layers of children to add to the toString() -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
GenericScene
(GenericScene.Builder<?> builder) Takes a builder and extracts necessary fields out of it -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a child to the list of childrenvoid
Linearlly executes each functiongetChild
(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>
TAttempts to find a child scene that matches the ID and type of Scene Executes a depth-first searchExecutes a depth-first seach on the children Returns the first child with name matching param name<T extends Scene>
TAttempts to find a child scene that matches the name and type of Scene Executes a depth-first searchGetter for childrenGetter for functionslong
getID()
Getter for idgetName()
Getter for nameboolean
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 againvoid
run()
Executes its functions, then displays its childrenvoid
Linearly displays Childrenvoid
setChildren
(List<Scene> children) Setter for childrenvoid
Setter for namevoid
Terminates scene executiontoString()
Recursively generates toString with info for this scene and all children Will only go as deep as MAX_ITERATIONS_ON_TOSTRINGtoString
(int indent, boolean displayChildren) recursive helper method for toString()
-
Field Details
-
MAX_ITERATIONS_ON_TOSTRING
public static int MAX_ITERATIONS_ON_TOSTRINGThe number of layers of children to add to the toString()
-
-
Constructor Details
-
GenericScene
Takes a builder and extracts necessary fields out of it- Parameters:
builder
- a GenericScene.Builder (or something that extends it)
-
-
Method Details
-
run
Executes its functions, then displays its children -
getName
Getter for name -
setName
Setter for name -
getID
public long getID()Getter for id -
getChildren
Getter for children- Specified by:
getChildren
in interfaceScene
- Returns:
- the list of child scenes attatched to the scene
-
setChildren
Setter for children- Specified by:
setChildren
in interfaceScene
- Parameters:
children
- the new list of child scenes
-
addChild
Add a child to the list of children -
runChildren
Linearly displays Children- Specified by:
runChildren
in interfaceScene
- Throws:
Exception
-
getFunctions
Getter for functions- Specified by:
getFunctions
in interfaceScene
- Returns:
- the list of functions it can execute
-
executeFunctions
Linearlly executes each function- Specified by:
executeFunctions
in interfaceScene
- Throws:
Exception
-
getChild
Executes a depth-first seach on the children Returns the first child with name matching param name -
getChild
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 -
getChild
Attempts to find a child scene that matches the name and type of Scene Executes a depth-first search -
getChild
Attempts to find a child scene that matches the ID and type of Scene Executes a depth-first search -
terminate
public void terminate()Terminates scene execution -
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 interfaceScene
- Returns:
- whether or not the scene is in a terminate state
-
toString
Recursively generates toString with info for this scene and all children Will only go as deep as MAX_ITERATIONS_ON_TOSTRING -
toString
recursive helper method for toString()
-