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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(T t)
    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
    Adds all elements to the default controller, if they are not already added.
    boolean
    Adds all elements with the specific layer to this controller, if they are not already added.
    void
    Clears the entire controller (removes all elements).
    void
    Removes all elements in the specific layer.
    boolean
    Returns true, if the element is in this controller.
    void
    forEach(Consumer<? super T> action)
     
    boolean
    Tests, if this controller has no elements.
     
    boolean
    Removes the element from this controller, if it is in this controller.
    int
     
     
    void
    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

      public boolean contains(Object t)
      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

      public boolean add(T t)
      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

      public boolean add(T t, ControllerLayer layer)
      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

      public boolean addAll(Collection<T> c)
      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

      public boolean addAll(Collection<T> c, ControllerLayer layer)
      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

      public boolean remove(Object t)
      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

      public void clearLayer(ControllerLayer layer)
      Removes all elements in the specific layer.
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T extends DungeonElement>
      Returns:
      An iterator.
    • size

      public int size()
    • forEach

      public void forEach(Consumer<? super T> action)
      Specified by:
      forEach in interface Iterable<T extends DungeonElement>
    • toString

      public String toString()
      Overrides:
      toString in class Object