public class Node<T>
extends java.lang.Object
Constructor and Description |
---|
Node()
Default constructor.
|
Node(T data)
Convenience ctor to create a Node
|
Modifier and Type | Method and Description |
---|---|
void |
addChild(Node<T> child)
Adds a child to the list of children for this Node
|
void |
addChildren(java.util.List<Node<T>> newChildren)
Adds a list of children to this Node
|
void |
clear()
Removes the branch below this item, clearing children if this is the only
parent
|
void |
consolidate()
merges children with equal content, reducing branches
|
void |
detachFromParent(Node<T> parent)
Removes child from a particular parent
|
void |
detachFromParents()
Removes node from all parents
|
Node<T> |
getChild(int idx)
Gets a child at a particular index
|
java.util.List<Node<T>> |
getChildren()
Return the children of Node
|
T |
getData() |
int |
getNumberOfChildren()
Returns the number of immediate children of this Node
|
int |
getNumberOfParents()
Returns the number of immediate parents of this Node
|
Node<T> |
getParent(int idx) |
java.util.List<Node<T>> |
getParents() |
void |
insertChildAt(int index,
Node<T> child)
Adds a child to the list of children for this Node
|
void |
removeAllChildren()
Clears all children, ensuring to remove the parent entry
|
void |
removeChild(int index)
Remove the Node
|
void |
removeChild(Node<T> child)
Remove the Node
|
void |
setChildren(java.util.List<Node<T>> children)
Sets the children of a Node
|
void |
setData(T data) |
java.lang.String |
toString() |
public Node()
public Node(T data)
data
- an instance of T.public java.util.List<Node<T>> getChildren()
public Node<T> getChild(int idx) throws java.lang.IndexOutOfBoundsException
idx
- the index of the child to getjava.lang.IndexOutOfBoundsException
public void setChildren(java.util.List<Node<T>> children)
children
- the Listpublic int getNumberOfChildren()
public int getNumberOfParents()
public void addChild(Node<T> child)
child
- a Nodepublic void insertChildAt(int index, Node<T> child)
index
- the index at which to insert the childchild
- a Nodepublic void addChildren(java.util.List<Node<T>> newChildren)
newChildren
- list of Nodepublic void removeChild(int index) throws java.lang.IndexOutOfBoundsException
index
- the index of the element to delete.java.lang.IndexOutOfBoundsException
- if thrown.public void removeChild(Node<T> child)
child
- the node to removepublic void removeAllChildren()
public void detachFromParents()
public void detachFromParent(Node<T> parent)
parent
- public T getData()
public void setData(T data)
public java.lang.String toString()
toString
in class java.lang.Object
public void clear()
public void consolidate()