Package com.io7m.jorchard.core
Class JOTreeNode<A>
java.lang.Object
com.io7m.jorchard.core.JOTreeNode<A>
- Type Parameters:
A- The type of values contained within the tree
- All Implemented Interfaces:
JOTreeNodeReadableType<A>,JOTreeNodeType<A>
The default implementation of the
JOTreeNodeType type.-
Method Summary
Modifier and TypeMethodDescriptionchildAdd(JOTreeNodeType<A> child) Add a child to this node.childRemove(JOTreeNodeType<A> child) Remove a child from this node.children()voidchildrenSortNodes(Comparator<JOTreeNodeType<A>> comparator) Sort the children of this node.static <A> JOTreeNodeType<A>create(A in_value) Create a new node with the given value.static <A> JOTreeNodeType<A>createWithDetachCheck(A in_value, BooleanSupplier in_detach_check) Create a new node with the given value.detach()Detach this node from its parent node.<T> voidforEachBreadthFirst(T context, JOTreeNodeForEachFunctionType<A, T> f) Visit each node in the tree in breadth-first order.<T> voidforEachDepthFirst(T context, JOTreeNodeForEachFunctionType<A, T> f) Visit each node in the tree in depth-first order.booleanisDescendantOf(JOTreeNodeReadableType<A> other) boolean<T,B> JOTreeNodeType<B> mapBreadthFirst(T context, JOTreeNodeMapFunctionType<A, T, B> f) Visit each node in the tree in breadth-first order.<T,B> JOTreeNodeType<B> mapDepthFirst(T context, JOTreeNodeMapFunctionType<A, T, B> f) Visit each node in the tree in depth-first order.parent()setParent(JOTreeNodeType<A> parent_new) Set this node's parent tonew_parent.toString()value()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.io7m.jorchard.core.JOTreeNodeReadableType
isRootMethods inherited from interface com.io7m.jorchard.core.JOTreeNodeType
childrenSort
-
Method Details
-
create
Create a new node with the given value. The node has no parent and no children.- Type Parameters:
A- The type of values- Parameters:
in_value- The value- Returns:
- A new node
-
createWithDetachCheck
public static <A> JOTreeNodeType<A> createWithDetachCheck(A in_value, BooleanSupplier in_detach_check) Create a new node with the given value. The node has no parent and no children. The node is equipped with a function that is evaluated each before the node is detached from any node, with atruevalue indicating that the node is allowed to be detached.- Type Parameters:
A- The type of values- Parameters:
in_value- The valuein_detach_check- A detach check function- Returns:
- A new node
-
isDetachAllowed
public boolean isDetachAllowed()- Specified by:
isDetachAllowedin interfaceJOTreeNodeReadableType<A>- Returns:
trueiff this node may be detached from its parent
-
value
- Specified by:
valuein interfaceJOTreeNodeReadableType<A>- Returns:
- The value contained within the node
-
parentReadable
- Specified by:
parentReadablein interfaceJOTreeNodeReadableType<A>- Returns:
- A readable reference to the parent node
-
childrenReadable
- Specified by:
childrenReadablein interfaceJOTreeNodeReadableType<A>- Returns:
- A read-only collection containing the children of this node
-
toString
-
setParent
Description copied from interface:JOTreeNodeTypeSet this node's parent tonew_parent.- Specified by:
setParentin interfaceJOTreeNodeType<A>- Parameters:
parent_new- The new parent node- Returns:
- this
-
parent
- Specified by:
parentin interfaceJOTreeNodeType<A>- Returns:
- A reference to the parent node, if any
-
childrenSortNodes
Description copied from interface:JOTreeNodeTypeSort the children of this node. This will affect subsequent calls toJOTreeNodeReadableType.forEachDepthFirst(Object, JOTreeNodeForEachFunctionType)andJOTreeNodeReadableType.forEachBreadthFirst(Object, JOTreeNodeForEachFunctionType), and will affect the order ofJOTreeNodeType.children().- Specified by:
childrenSortNodesin interfaceJOTreeNodeType<A>- Parameters:
comparator- A node comparator
-
detach
Description copied from interface:JOTreeNodeTypeDetach this node from its parent node.- Specified by:
detachin interfaceJOTreeNodeType<A>- Returns:
- this
-
children
- Specified by:
childrenin interfaceJOTreeNodeType<A>- Returns:
- A read-only collection containing the children of this node
-
childRemove
Description copied from interface:JOTreeNodeTypeRemove a child from this node. Has no effect if the given node is not a child of this node.- Specified by:
childRemovein interfaceJOTreeNodeType<A>- Parameters:
child- A child node- Returns:
- this
-
childAdd
Description copied from interface:JOTreeNodeTypeAdd a child to this node. Has no effect if the given node is already a child of this node.- Specified by:
childAddin interfaceJOTreeNodeType<A>- Parameters:
child- A child node- Returns:
- this
-
isDescendantOf
- Specified by:
isDescendantOfin interfaceJOTreeNodeReadableType<A>- Parameters:
other- A node- Returns:
trueiff this node is a descendant ofother
-
forEachDepthFirst
Description copied from interface:JOTreeNodeReadableTypeVisit each node in the tree in depth-first order.
The function allows for the use of a context value. This is useful for avoiding the use of capturing lambdas, reducing GC pressure.
- Specified by:
forEachDepthFirstin interfaceJOTreeNodeReadableType<A>- Type Parameters:
T- The type of context values- Parameters:
context- A context value passed to each application offf- A function used to receive each node
-
forEachBreadthFirst
Description copied from interface:JOTreeNodeReadableTypeVisit each node in the tree in breadth-first order.
The function allows for the use of a context value. This is useful for avoiding the use of capturing lambdas, reducing GC pressure.
- Specified by:
forEachBreadthFirstin interfaceJOTreeNodeReadableType<A>- Type Parameters:
T- The type of context values- Parameters:
context- A context value passed to each application offf- A function used to receive each node
-
mapDepthFirst
Description copied from interface:JOTreeNodeReadableTypeVisit each node in the tree in depth-first order.
The function allows for the use of a context value. This is useful for avoiding the use of capturing lambdas, reducing GC pressure.
- Specified by:
mapDepthFirstin interfaceJOTreeNodeReadableType<A>- Type Parameters:
T- The type of context valuesB- The type of values in the returned tree- Parameters:
context- A context value passed to each application offf- A function used to receive each node- Returns:
- A new structurally equal tree with nodes of type
B
-
mapBreadthFirst
Description copied from interface:JOTreeNodeReadableTypeVisit each node in the tree in breadth-first order.
The function allows for the use of a context value. This is useful for avoiding the use of capturing lambdas, reducing GC pressure.
- Specified by:
mapBreadthFirstin interfaceJOTreeNodeReadableType<A>- Type Parameters:
T- The type of context valuesB- The type of values in the returned tree- Parameters:
context- A context value passed to each application offf- A function used to receive each node- Returns:
- A new structurally equal tree with nodes of type
B
-