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 classGenericScene.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 intThe number of layers of children to add to the toString() -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedGenericScene(GenericScene.Builder<?> builder) Takes a builder and extracts necessary fields out of it -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a child to the list of childrenvoidLinearlly 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 functionslonggetID()Getter for idgetName()Getter for namebooleanReturn whether or not the scene is in a termninated state note that the scene comes out of a termniated state when it is run againvoidrun()Executes its functions, then displays its childrenvoidLinearly displays ChildrenvoidsetChildren(List<Scene> children) Setter for childrenvoidSetter for namevoidTerminates 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:
getChildrenin interfaceScene- Returns:
- the list of child scenes attatched to the scene
-
setChildren
Setter for children- Specified by:
setChildrenin interfaceScene- Parameters:
children- the new list of child scenes
-
addChild
Add a child to the list of children -
runChildren
Linearly displays Children- Specified by:
runChildrenin interfaceScene- Throws:
Exception
-
getFunctions
Getter for functions- Specified by:
getFunctionsin interfaceScene- Returns:
- the list of functions it can execute
-
executeFunctions
Linearlly executes each function- Specified by:
executeFunctionsin 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:
isTerminatedin 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()
-