Class Node<N extends Node<N>>
java.lang.Object
com.thecsdev.common.scene.Node<N>
- Type Parameters:
N- ThegetBaseType(), in generic form.
- All Implemented Interfaces:
INode<N>, Iterable<N>, Collection<N>
- Direct Known Subclasses:
TElement
Represents a unique node that is present in a given scene graph.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanfinal booleanaddAll(@NotNull Collection<? extends N> c) protected voidchildAddedCallback(N child) Deprecated.protected voidchildRemovedCallback(N pastChild) Deprecated.final voidclear()final booleanfinal booleancontainsAll(@NotNull Collection<?> c) final booleanfindParent(@NotNull Predicate<N> predicate) findSibling(@NotNull Predicate<N> predicate) final voidSimilar toIterable.forEach(Consumer), but with an additional ability to recursively apply theConsumerto all children and grandchildren.final Nget(int index) Returns the childNodeat the specified index.Returns theClassobject that represents the base type of this node.final NgetFirst()Gets the first element of this collection.final NgetLast()Gets the last element of this collection.final NConvenience function that returns the valueparentProperty().abstract NgetSelf()Returns thisNode, cast to its concrete type.final inthashCode()final intReturns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.final booleanisEmpty()iterator()final ObjectProperty<N> TheObjectPropertythat holds a reference to thisNode's parent.final booleanremove()Removes thisNodeinstance from its parent.final booleanfinal booleanfinal booleanremoveAll(@NotNull Collection<?> c) final booleanretainAll(@NotNull Collection<?> c) final NotNullProperty<N> TheNotNullPropertythat holds a reference to the "root"Nodein the scene graph.final intsize()final @NotNull Object @NotNull []toArray()final <T> T @NotNull []toArray(T @NotNull [] a) Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Collection
parallelStream, removeIf, spliterator, stream, toArray
-
Constructor Details
-
Node
public Node()
-
-
Method Details
-
getSelf
-
getBaseType
Returns theClassobject that represents the base type of this node.The base type is the "root"
Classin anNodehierarchy, from which all other specificNodetypes in a scene graph are derived. For example, ifLightNode,MeshNode, andCameraNodeall extend a commonNodeclass, thenNodeis 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:
getBaseTypein interfaceINode<N extends Node<N>>- See Also:
-
equals
-
hashCode
-
rootProperty
TheNotNullPropertythat holds a reference to the "root"Nodein the scene graph. IfgetParent()isnull, thisNotNullPropertywill treat thisNodeas the "root" node.- API Note:
- Owned by
Node.NodePropertyAccessor.
-
parentProperty
TheObjectPropertythat holds a reference to thisNode's parent.- API Note:
- Owned by
Node.NodePropertyAccessor.
-
childAddedCallback
Deprecated.- Parameters:
child- The now new child.
-
childRemovedCallback
Deprecated.- Parameters:
pastChild- The now "ex" child.
-
getParent
Convenience function that returns the valueparentProperty(). -
findParent
@NotNull public final @NotNull Optional<@Nullable N> findParent(@NotNull @NotNull Predicate<N> predicate) throws NullPointerException - Parameters:
predicate- ThePredicateto test.- Returns:
- The first parent/grandparent that matches the
Predicate. - Throws:
NullPointerException- If an argument isnull.
-
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 givenPredicate.- Parameters:
predicate- ThePredicateto test.nested- Whether to check grandchildren in nested branches.- Throws:
NullPointerException- If an argument isnull.- 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 - Parameters:
predicate- ThePredicateto test.- Returns:
- The first sibling that matches the
Predicate. - Throws:
NullPointerException- If the argument isnull.
-
get
Returns the childNodeat the specified index.- Parameters:
index- The index of the child to return.- Returns:
- The child
Nodeat the specified index. - Throws:
IndexOutOfBoundsException- If the index is out of range (index < 0 || index >= size()).
-
getFirst
Gets the first element of this collection.- Throws:
NoSuchElementException- If this collection is empty.
-
getLast
Gets the last element of this collection.- Throws:
NoSuchElementException- If this collection is empty.
-
indexOf
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:
sizein interfaceCollection<N extends Node<N>>
-
isEmpty
public final boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<N extends Node<N>>
-
contains
-
toArray
-
toArray
@NotNull public final <T> T @NotNull [] toArray(@NotNull T @NotNull [] a) - Specified by:
toArrayin interfaceCollection<N extends Node<N>>
-
containsAll
- Specified by:
containsAllin interfaceCollection<N extends Node<N>>
-
clear
public final void clear()- Specified by:
clearin interfaceCollection<N extends Node<N>>
-
addAll
- Specified by:
addAllin interfaceCollection<N extends Node<N>>
-
removeAll
- Specified by:
removeAllin interfaceCollection<N extends Node<N>>
-
retainAll
- Specified by:
retainAllin interfaceCollection<N extends Node<N>>
-
iterator
-
forEach
Similar toIterable.forEach(Consumer), but with an additional ability to recursively apply theConsumerto 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 isnull.
-
add
public final boolean add(@NotNull N child) throws NullPointerException, ClassCastException, IllegalArgumentException - Specified by:
addin interfaceCollection<N extends Node<N>>
-
remove
public final boolean remove()- Returns:
trueifgetParent()is notnulland parent'sremove(Node)operation returnedtrue.
-
remove
-
remove
- Parameters:
child- TheNodeto be removed.- Returns:
trueif a node was removed as a result of this call.
-