public class Node<T>
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Field and Description |
---|---|
java.util.List<Node<T>> |
children |
T |
data |
Node<T> |
parent |
Constructor and Description |
---|
Node() |
Node(T data)
Convenience constructor to create a
Node<T> with an instance of T. |
Modifier and Type | Method and Description |
---|---|
void |
addChild(Node<T> child)
Adds a child to the list of children for this
Node<T> . |
java.util.List<Node<T>> |
getChildren()
Return the children of
Node<T> . |
T |
getData() |
int |
getNumberOfChildren()
Returns the number of immediate children of this
Node<T> . |
Node<T> |
getParent() |
void |
insertChildAt(int index,
Node<T> child)
Inserts a
Node<T> at the specified position in the child list. |
void |
removeChildAt(int index)
Remove the
Node<T> element at index index of the List<Node<T>> . |
void |
setChildren(java.util.List<Node<T>> children)
Sets the children of a
Node<T> object. |
void |
setData(T data) |
java.lang.String |
toString() |
public T data
public Node()
public Node(T data)
Node<T>
with an instance of T.data
- an instance of T.public java.util.List<Node<T>> getChildren()
Node<T>
. The Tree<T>
is represented by a single
root Node<T>
whose children are represented by a List<Node<T>>
. Each of
these Node<T>
elements in the List can have children. The getChildren()
method will return the children of a Node<T>
.Node<T>
public void setChildren(java.util.List<Node<T>> children)
Node<T>
object. See docs for getChildren() for
more information.children
- the List<Node<T>>
to set.public int getNumberOfChildren()
Node<T>
.public void addChild(Node<T> child)
Node<T>
. The addition of
the first child will create a new List<Node<T>>
.child
- a Node<T>
object to set.public void insertChildAt(int index, Node<T> child) throws java.lang.IndexOutOfBoundsException
Node<T>
at the specified position in the child list. Will
throw an ArrayIndexOutOfBoundsException if the index does not exist.index
- the position to insert at.child
- the Node<T>
object to insert.java.lang.IndexOutOfBoundsException
- if thrown.public void removeChildAt(int index) throws java.lang.IndexOutOfBoundsException
Node<T>
element at index index of the List<Node<T>>
.index
- the index of the element to delete.java.lang.IndexOutOfBoundsException
- if thrown.public T getData()
public void setData(T data)
public java.lang.String toString()
toString
in class java.lang.Object