Package controller
Class AbstractController<T extends DungeonElement>
java.lang.Object
controller.AbstractController<T>
- Type Parameters:
T
- Type of elements to manage.
- All Implemented Interfaces:
Iterable<T>
- Direct Known Subclasses:
EntityController
,HUDController
public abstract class AbstractController<T extends DungeonElement>
extends Object
implements Iterable<T>
A controller manages elements of a certain type and is based on a layer system.
Layer system means: All elements are listed in ascending order according to the layers in this controller and in the order they are arranged in the layer.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds the element with default layer (20) to this controller, if it is not already added.boolean
add
(T t, ControllerLayer layer) Adds the element with the specific layer to this controller, if it is not already added.boolean
addAll
(Collection<T> c) Adds all elements to the default controller, if they are not already added.boolean
addAll
(Collection<T> c, ControllerLayer layer) Adds all elements with the specific layer to this controller, if they are not already added.void
clear()
Clears the entire controller (removes all elements).void
clearLayer
(ControllerLayer layer) Removes all elements in the specific layer.boolean
Returns true, if the element is in this controller.void
boolean
isEmpty()
Tests, if this controller has no elements.iterator()
boolean
Removes the element from this controller, if it is in this controller.int
size()
toString()
void
update()
Updates all elements that are registered at this controller, removes deletable elements and calls the update and draw method for every registered element.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
spliterator
-
Constructor Details
-
AbstractController
public AbstractController()
-
-
Method Details
-
update
public void update()Updates all elements that are registered at this controller, removes deletable elements and calls the update and draw method for every registered element. -
contains
Returns true, if the element is in this controller.- Parameters:
t
- Element to look for.- Returns:
- true, if the element is in this controller.
-
add
Adds the element with default layer (20) to this controller, if it is not already added.- Parameters:
t
- Element to add.- Returns:
- true, if this was successful.
-
add
Adds the element with the specific layer to this controller, if it is not already added.- Parameters:
t
- Element to add.layer
- Layer to add the element in.- Returns:
- true, if this was successful.
-
addAll
Adds all elements to the default controller, if they are not already added.- Parameters:
c
- Collection to add.- Returns:
- true, if this was modified.
-
addAll
Adds all elements with the specific layer to this controller, if they are not already added.- Parameters:
c
- Collection to add.layer
- Layer to add the element in.- Returns:
- true, if this was modified.
-
remove
Removes the element from this controller, if it is in this controller.- Parameters:
t
- Element to remove.- Returns:
- true, if this was successful.
-
isEmpty
public boolean isEmpty()Tests, if this controller has no elements.- Returns:
- true, if empty.
-
clear
public void clear()Clears the entire controller (removes all elements). -
clearLayer
Removes all elements in the specific layer. -
iterator
- Specified by:
iterator
in interfaceIterable<T extends DungeonElement>
- Returns:
- An iterator.
-
size
public int size() -
forEach
- Specified by:
forEach
in interfaceIterable<T extends DungeonElement>
-
toString
-