jasi.sim.basic.tree
Class AbstractNode<T>

java.lang.Object
  extended by jasi.sim.basic.tree.AbstractNode<T>
Type Parameters:
T - Content type of node.
Direct Known Subclasses:
ListNode, SetNode

public abstract class AbstractNode<T>
extends java.lang.Object

Abstract base node class.


Constructor Summary
AbstractNode()
          Create a root node with no leafs and no content.
AbstractNode(T content)
          Create a root node with no leafs.
 
Method Summary
abstract  AbstractNode<T> add(AbstractNode<T> child)
          Add a node as child to this node.
 boolean equals(java.lang.Object node)
          Test this node with that node for equality by comparing their content.
 java.util.Collection<AbstractNode<T>> findChildren(T content)
          Get all children with a given content.
 AbstractNode<T> findRoot()
          Get this node's root node.
abstract  java.util.Collection<AbstractNode<T>> getChildren()
          Get all children of this node.
 T getContent()
          Get this node's content.
 AbstractNode<T> getParent()
          Get this node's parent.
 boolean has(AbstractNode<T> child)
          Check, if this node contains that child node.
 boolean hasChild(T content)
          Check, if this node contains that child node.
 int hashCode()
          Return a hash code value.
 boolean hasParent()
          Check, if this node has a parent node.
 boolean isLeafNode()
          Check, if this node has no children.
 boolean isRootNode()
          Check, if this node has no parent node.
 java.lang.String printTree(AbstractNode<T> current)
          Print this node in a tree.
 java.lang.String printTree(int level, AbstractNode<T> current)
          Print this node in a tree.
abstract  void remove(AbstractNode<T> child)
          Remove a child node.
abstract  java.util.Collection<AbstractNode<T>> remove(T content)
          Remove a child node.
 java.util.Collection<AbstractNode<T>> removeAll()
          Remove a all children.
 void setChildren(java.util.Collection<AbstractNode<T>> children)
          Set all children of this node.
 void setContent(T content)
          Set this node's content.
 void setParent(AbstractNode<T> parent)
          Set this node's parent.
abstract  int size()
          Get the number of children nodes of this node.
 java.lang.String toString()
          Get string representation of this node.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractNode

public AbstractNode()
Create a root node with no leafs and no content.


AbstractNode

public AbstractNode(T content)
Create a root node with no leafs.

Parameters:
content - The node's content.
Method Detail

getContent

public final T getContent()
Get this node's content.

Returns:
The content.

setContent

public final void setContent(T content)
Set this node's content.

Parameters:
content - The content.

getParent

public final AbstractNode<T> getParent()
Get this node's parent.

Returns:
The parent.

setParent

public final void setParent(AbstractNode<T> parent)
Set this node's parent.

Parameters:
parent - The parent.

hasParent

public final boolean hasParent()
Check, if this node has a parent node.

Returns:
True, if parent node exists.

getChildren

public abstract java.util.Collection<AbstractNode<T>> getChildren()
Get all children of this node.

Returns:
The children.

setChildren

public final void setChildren(java.util.Collection<AbstractNode<T>> children)
Set all children of this node.

Parameters:
children - The children.

isRootNode

public final boolean isRootNode()
Check, if this node has no parent node.

Returns:
True, if root node.

isLeafNode

public final boolean isLeafNode()
Check, if this node has no children.

Returns:
True, if root node.

size

public abstract int size()
Get the number of children nodes of this node.

Returns:
The number of children.

add

public abstract AbstractNode<T> add(AbstractNode<T> child)
Add a node as child to this node.

Parameters:
child - The new child node.
Returns:
The child node.

remove

public abstract java.util.Collection<AbstractNode<T>> remove(T content)
Remove a child node.

Parameters:
content - The content of the child node.
Returns:
The removed children.

remove

public abstract void remove(AbstractNode<T> child)
Remove a child node.

Parameters:
child - The child node.

removeAll

public java.util.Collection<AbstractNode<T>> removeAll()
Remove a all children.

Returns:
The children.

findChildren

public final java.util.Collection<AbstractNode<T>> findChildren(T content)
Get all children with a given content.

Parameters:
content - The content of the children.
Returns:
The children.

hasChild

public final boolean hasChild(T content)
Check, if this node contains that child node.

Parameters:
content - That child node's content.
Returns:
True, if there is a child node with that content.

has

public final boolean has(AbstractNode<T> child)
Check, if this node contains that child node.

Parameters:
child - That child node.
Returns:
True, if node is a child node.

findRoot

public final AbstractNode<T> findRoot()
Get this node's root node.

Returns:
The root node.

equals

public final boolean equals(java.lang.Object node)
Test this node with that node for equality by comparing their content.

Overrides:
equals in class java.lang.Object
Parameters:
node - That node.
Returns:
True, if both contents are equal.

hashCode

public final int hashCode()
Return a hash code value.

Overrides:
hashCode in class java.lang.Object
Returns:
The hash code.
See Also:
Object.hashCode()

printTree

public final java.lang.String printTree(AbstractNode<T> current)
Print this node in a tree.

Parameters:
current - The current node of the tree
Returns:
The string.

printTree

public final java.lang.String printTree(int level,
                                        AbstractNode<T> current)
Print this node in a tree.

Parameters:
level - The current tree level.
current - The current node of the tree
Returns:
The string.

toString

public java.lang.String toString()
Get string representation of this node.

Overrides:
toString in class java.lang.Object
Returns:
The string.