Class Node<N extends Node<N>>

java.lang.Object
com.thecsdev.common.scene.Node<N>
Type Parameters:
N - The getBaseType(), in generic form.
All Implemented Interfaces:
INode<N>, Iterable<N>, Collection<N>
Direct Known Subclasses:
TElement

public abstract class Node<N extends Node<N>> extends Object implements INode<N>
Represents a unique node that is present in a given scene graph.
API Note:
https://en.wikipedia.org/wiki/Scene_graph
  • Constructor Details

    • Node

      public Node()
  • Method Details

    • getSelf

      @NotNull public abstract N getSelf()
      Returns this Node, cast to its concrete type.

      Override this method in your subclasses and return this. For example:

      public class MyNode extends Node<MyNode>
      {
          protected MyNode getSelf() { return this; }
      }
      
      Returns:
      this Node instance, cast to the type parameter E.
    • getBaseType

      @NotNull public abstract @NotNull Class<N> getBaseType()
      Returns the Class object that represents the base type of this node.

      The base type is the "root" Class in an Node hierarchy, from which all other specific Node types in a scene graph are derived. For example, if LightNode, MeshNode, and CameraNode all extend a common Node class, then Node is the base type for that hierarchy.

      Override this method in your subclasses and return the class literal of your subclass. For example:

      public class MyNode extends Node<MyNode>
      {
          public Class<MyNode> getBaseType() { return MyNode.class; }
      }
      
      Specified by:
      getBaseType in interface INode<N extends Node<N>>
      See Also:
    • equals

      public final boolean equals(Object obj)
      Specified by:
      equals in interface Collection<N extends Node<N>>
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Specified by:
      hashCode in interface Collection<N extends Node<N>>
      Overrides:
      hashCode in class Object
    • rootProperty

      public final NotNullProperty<N> rootProperty()
      The NotNullProperty that holds a reference to the "root" Node in the scene graph. If getParent() is null, this NotNullProperty will treat this Node as the "root" node.
      API Note:
      Owned by Node.NodePropertyAccessor.
    • parentProperty

      public final ObjectProperty<N> parentProperty()
      The ObjectProperty that holds a reference to this Node's parent.
      API Note:
      Owned by Node.NodePropertyAccessor.
    • childAddedCallback

      @Deprecated @Virtual protected void childAddedCallback(@NotNull N child)
      Deprecated.
      Callback function that is invoked after an Node is added as a child to this Node.
      Parameters:
      child - The now new child.
    • childRemovedCallback

      @Deprecated @Virtual protected void childRemovedCallback(@NotNull N pastChild)
      Deprecated.
      Callback function that is invoked after an Node is removed from this Node.
      Parameters:
      pastChild - The now "ex" child.
    • getParent

      @Nullable public final N getParent()
      Convenience function that returns the value parentProperty().
    • findParent

      @NotNull public final @NotNull Optional<@Nullable N> findParent(@NotNull @NotNull Predicate<N> predicate) throws NullPointerException
      Attempts to find a parent or grandparent Node that matches a given Predicate.
      Parameters:
      predicate - The Predicate to test.
      Returns:
      The first parent/grandparent that matches the Predicate.
      Throws:
      NullPointerException - If an argument is null.
    • findChild

      @NotNull public final @NotNull Optional<@Nullable N> findChild(@NotNull @NotNull Predicate<N> predicate, boolean nested) throws NullPointerException
      Attempts to find a child (or even a grandchild) Node (depending on arguments) that matches a given Predicate.
      Parameters:
      predicate - The Predicate to test.
      nested - Whether to check grandchildren in nested branches.
      Throws:
      NullPointerException - If an argument is null.
      API Note:
      May run in nondeterministic polynomial time. May be expensive to call.
    • findSibling

      @NotNull public final @NotNull Optional<@Nullable N> findSibling(@NotNull @NotNull Predicate<N> predicate) throws NullPointerException
      Attempts to find a sibling Node that matches a given Predicate.
      Parameters:
      predicate - The Predicate to test.
      Returns:
      The first sibling that matches the Predicate.
      Throws:
      NullPointerException - If the argument is null.
    • get

      @Nullable public final N get(int index) throws IndexOutOfBoundsException
      Returns the child Node at the specified index.
      Parameters:
      index - The index of the child to return.
      Returns:
      The child Node at the specified index.
      Throws:
      IndexOutOfBoundsException - If the index is out of range (index < 0 || index >= size()).
    • getFirst

      @NotNull public final N getFirst() throws NoSuchElementException
      Gets the first element of this collection.
      Throws:
      NoSuchElementException - If this collection is empty.
    • getLast

      @NotNull public final N getLast() throws NoSuchElementException
      Gets the last element of this collection.
      Throws:
      NoSuchElementException - If this collection is empty.
    • indexOf

      public final int indexOf(Object o)
      Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
      Parameters:
      o - The element to search for.
      Returns:
      The index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
    • size

      public final int size()
      Specified by:
      size in interface Collection<N extends Node<N>>
    • isEmpty

      public final boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<N extends Node<N>>
    • contains

      public final boolean contains(Object o)
      Specified by:
      contains in interface Collection<N extends Node<N>>
    • toArray

      @NotNull public final @NotNull Object @NotNull [] toArray()
      Specified by:
      toArray in interface Collection<N extends Node<N>>
    • toArray

      @NotNull public final <T> T @NotNull [] toArray(@NotNull T @NotNull [] a)
      Specified by:
      toArray in interface Collection<N extends Node<N>>
    • containsAll

      public final boolean containsAll(@NotNull @NotNull Collection<?> c)
      Specified by:
      containsAll in interface Collection<N extends Node<N>>
    • clear

      public final void clear()
      Specified by:
      clear in interface Collection<N extends Node<N>>
    • addAll

      public final boolean addAll(@NotNull @NotNull Collection<? extends N> c)
      Specified by:
      addAll in interface Collection<N extends Node<N>>
    • removeAll

      public final boolean removeAll(@NotNull @NotNull Collection<?> c)
      Specified by:
      removeAll in interface Collection<N extends Node<N>>
    • retainAll

      public final boolean retainAll(@NotNull @NotNull Collection<?> c)
      Specified by:
      retainAll in interface Collection<N extends Node<N>>
    • iterator

      @NotNull public final @NotNull Iterator<N> iterator()
      Specified by:
      iterator in interface Collection<N extends Node<N>>
      Specified by:
      iterator in interface Iterable<N extends Node<N>>
    • forEach

      public final void forEach(Consumer<N> action, boolean recursive) throws NullPointerException
      Similar to Iterable.forEach(Consumer), but with an additional ability to recursively apply the Consumer to all children and grandchildren.
      Parameters:
      action - The action to be performed for each element.
      recursive - Whether to recursively call this same method for children as well.
      Throws:
      NullPointerException - If the specified action is null.
    • add

      public final boolean add(@NotNull N child) throws NullPointerException, ClassCastException, IllegalArgumentException
      Specified by:
      add in interface Collection<N extends Node<N>>
    • remove

      public final boolean remove()
      Removes this Node instance from its parent. If this Node does not have a parent, nothing happens.
      Returns:
      true if getParent() is not null and parent's remove(Node) operation returned true.
    • remove

      public final boolean remove(Object child)
      Specified by:
      remove in interface Collection<N extends Node<N>>
    • remove

      public final boolean remove(N child)
      Same as remove(Object).
      Removes a child Node instance from this Node.
      Parameters:
      child - The Node to be removed.
      Returns:
      true if a node was removed as a result of this call.