nu.staldal.xtree
Class NodeWithChildren

java.lang.Object
  extended by nu.staldal.xtree.Node
      extended by nu.staldal.xtree.NodeWithChildren
All Implemented Interfaces:
java.io.Serializable, org.xml.sax.Locator
Direct Known Subclasses:
Element

public abstract class NodeWithChildren
extends Node

Base class for a node with children. The children are ordered.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class nu.staldal.xtree.Node
parent, XML_NS
 
Constructor Summary
NodeWithChildren(int capacity)
          Construct a node which children.
 
Method Summary
 void addChild(Node newChild)
          Add a new child to this node, last in sequence.
 Node getChild(int index)
          Get a specific child of this node.
 void insertChild(Node newChild, int index)
          Insert a new child at a specific point in sequence.
 int numberOfChildren()
          Get the current number of children this node have.
 Node removeChild(int index)
          Remove a child from this node.
 Node replaceChild(Node newChild, int index)
          Replace a child with another.
 
Methods inherited from class nu.staldal.xtree.Node
getBaseURI, getColumnNumber, getInheritedAttribute, getLineNumber, getParent, getPreserveSpace, getPublicId, getSystemId, isWhitespaceNode, lookupNamespacePrefix, lookupNamespaceURI, setColumn, setLine, setPublicId, setSystemId, toSAX
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NodeWithChildren

public NodeWithChildren(int capacity)
Construct a node which children.

Parameters:
capacity - the number of children this node should have, use -1 if unknown
Method Detail

numberOfChildren

public int numberOfChildren()
Get the current number of children this node have.


getChild

public Node getChild(int index)
              throws java.lang.IndexOutOfBoundsException
Get a specific child of this node.

Parameters:
index - index of the node to get, the first child is 0.
Throws:
java.lang.IndexOutOfBoundsException - if no such child exist.

addChild

public void addChild(Node newChild)
Add a new child to this node, last in sequence.


replaceChild

public Node replaceChild(Node newChild,
                         int index)
                  throws java.lang.IndexOutOfBoundsException
Replace a child with another.

Parameters:
newChild - the new child
index - index of the child to replace
Returns:
the replaced child
Throws:
java.lang.IndexOutOfBoundsException - if no such child exist

removeChild

public Node removeChild(int index)
                 throws java.lang.IndexOutOfBoundsException
Remove a child from this node. This method is a bit inefficient.

Parameters:
index - index of the child to replace
Returns:
the removed child
Throws:
java.lang.IndexOutOfBoundsException - if no such child exist

insertChild

public void insertChild(Node newChild,
                        int index)
                 throws java.lang.IndexOutOfBoundsException
Insert a new child at a specific point in sequence. This method is a bit inefficient. Inserts the new child at the specified index. Each child with an index greater or equal to the specified index is shifted upward to have an index one greater than the value it had previously.

Parameters:
newChild - the new child
index - index of the new child
Throws:
java.lang.IndexOutOfBoundsException - if the index is invalid.