simple.util.tree
Class FullNode<T,K,V>

java.lang.Object
  extended by simple.util.tree.FullNode<T,K,V>
Type Parameters:
T - Type for node content.
K - Type for property Keys.
V - Type for property Values.
Direct Known Subclasses:
Tag

public class FullNode<T,K,V>
extends java.lang.Object

Node that has it all.


other dependencies:
simple.CIString

Version:
1.2
Author:
Kenneth Pierce

Field Summary
protected  java.util.Vector<FullNode<T,K,V>> children
          Vector of Nodes to hold any children.
private  T content
           
private  int depth
           
private  CIString nName
           
private  FullNode<T,K,V> parent
           
protected  java.util.HashMap<K,V> properties
          HashMap to hold properties for this node.
 
Constructor Summary
protected FullNode()
           
  FullNode(java.lang.String name)
          Creates a Node and sets its name.
  FullNode(java.lang.String name, FullNode<T,K,V> parent)
          Creates a Node and sets its name and parent.
  FullNode(java.lang.String name, FullNode<T,K,V> parent, T content)
           
  FullNode(java.lang.String name, T content)
           
 
Method Summary
 void addChild(FullNode<T,K,V> cnode)
          Adds a child Node and sets this as the node's parent.
 int childCount()
           
 FullNode<T,K,V> getChild(int index)
          Gets a child at the index specified.
 T getContent()
           
 int getDepth()
          Get which level of the tree the element is on.
 CIString getName()
           
 FullNode<T,K,V> getParent()
           
 V getProperty(K key)
           
 boolean hasChild()
          Checks if it has any children.
 boolean hasChild(FullNode<T,K,V> child)
           
 boolean hasParent()
           
 boolean hasProperty(K key)
           
 boolean isChildOf(FullNode<T,K,V> parent)
           
 boolean isRoot()
          Checks if it has a parent and returns the result.
 void removeChild(FullNode<T,K,V> child)
          Removes the specified Node from the list of children if it has any.
 void removeChild(int index)
          Removes the child Node at the specified index if getChild(index)!=null.
 V removeProperty(K key)
          Removes the key/value pair.
 void setContent(T object)
          Sets the contents of the node.
 void setName(java.lang.String name)
          Sets the name of the node.
 void setParent(FullNode<T,K,V> pnode)
          Sets the parent of this node.
 V setProperty(K key, V value)
          Adds the key/value pair to the properties.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

children

protected final java.util.Vector<FullNode<T,K,V>> children
Vector of Nodes to hold any children.


properties

protected java.util.HashMap<K,V> properties
HashMap to hold properties for this node.


parent

private FullNode<T,K,V> parent

nName

private CIString nName

content

private T content

depth

private int depth
Constructor Detail

FullNode

protected FullNode()

FullNode

public FullNode(java.lang.String name)
Creates a Node and sets its name.

Parameters:
name - Name of the node.

FullNode

public FullNode(java.lang.String name,
                FullNode<T,K,V> parent,
                T content)

FullNode

public FullNode(java.lang.String name,
                T content)

FullNode

public FullNode(java.lang.String name,
                FullNode<T,K,V> parent)
Creates a Node and sets its name and parent.

Parameters:
name - Name of the node.
parent - Parent of the node.
Method Detail

setContent

public final void setContent(T object)
Sets the contents of the node.

Parameters:
object - Object to set as the contents.

getContent

public final T getContent()
Returns:
The contents of the node.

setName

public final void setName(java.lang.String name)
Sets the name of the node.

Parameters:
name - String to set as the Node's name.

getName

public final CIString getName()
Returns:
The name of this node.

setParent

public final void setParent(FullNode<T,K,V> pnode)
Sets the parent of this node. If it already has a parent then it calls removeChild(this) on its parent before setting its parent to the specified Node. Also adds itself to the new parent if node.hasChild(this)!=true.
This function sets the depth.

Parameters:
pnode - Node to be set as the parent of this Node.

hasParent

public final boolean hasParent()
Returns:
The result of getParent()!=null.

getParent

public final FullNode<T,K,V> getParent()
Returns:
The parent of this node.

isRoot

public final boolean isRoot()
Checks if it has a parent and returns the result.

Returns:
True if it has no parent.

hasChild

public final boolean hasChild()
Checks if it has any children.

Returns:
True if it has one or more children.

hasChild

public final boolean hasChild(FullNode<T,K,V> child)
Parameters:
child - Node to test if it is a child.
Returns:
True if the specified Node is a child of this node.

isChildOf

public final boolean isChildOf(FullNode<T,K,V> parent)
Parameters:
parent - Possible parent node.
Returns:
The result of parent.hasChild(this).

addChild

public final void addChild(FullNode<T,K,V> cnode)
Adds a child Node and sets this as the node's parent. Does nothing if node==null.

Parameters:
cnode - Node to be added as a child.

getChild

public final FullNode<T,K,V> getChild(int index)
Gets a child at the index specified.

Parameters:
index - Index of the child wanted.
Returns:
Child Node at specified index or null if it has no children or the index is out of the valid range(0>= index > childCount()).

childCount

public final int childCount()
Returns:
The number of children this node has.

removeChild

public void removeChild(FullNode<T,K,V> child)
Removes the specified Node from the list of children if it has any.

Parameters:
child - Node to be removed.

removeChild

public final void removeChild(int index)
Removes the child Node at the specified index if getChild(index)!=null.

Parameters:
index - Index of Node to be removed.

getProperty

public final V getProperty(K key)
Parameters:
key - The key for the value.
Returns:
The value of the property.

setProperty

public final V setProperty(K key,
                           V value)
Adds the key/value pair to the properties. If the key already exists then the value for that key is replaced with the one provided.

Parameters:
key - Key for the value.
value - Value to be set for the property.
Returns:
The old value if previously set

removeProperty

public final V removeProperty(K key)
Removes the key/value pair.

Parameters:
key -
Returns:
The value associated with the key.

hasProperty

public final boolean hasProperty(K key)
Parameters:
key -
Returns:
True if the properties table contains the specified key.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getDepth

public final int getDepth()
Get which level of the tree the element is on. 0 based.

Returns:
The depth of this node