nu.staldal.xmltree
Class NodeWithChildren

java.lang.Object
  extended by nu.staldal.xmltree.Node
      extended by nu.staldal.xmltree.NodeWithChildren
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<Node>, java.util.Collection<Node>, java.util.List<Node>, org.xml.sax.Locator
Direct Known Subclasses:
Element

public abstract class NodeWithChildren
extends Node
implements java.util.List<Node>

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

See Also:
Serialized Form

Field Summary
 
Fields inherited from class nu.staldal.xmltree.Node
parent
 
Constructor Summary
  NodeWithChildren()
          Construct a node which children.
  NodeWithChildren(int capacity)
          Construct a node which children.
protected NodeWithChildren(NodeWithChildren node)
          Pseudo-copy constructor, do not copy the children, but allocate room for them.
 
Method Summary
 void add(int index, Node element)
           
 boolean add(Node newChild)
           
 boolean addAll(java.util.Collection<? extends Node> c)
           
 boolean addAll(int index, java.util.Collection<? extends Node> c)
           
 void clear()
           
 boolean contains(java.lang.Object o)
           
 boolean containsAll(java.util.Collection<?> c)
           
 Node get(int index)
           
 java.util.Collection<Element> getChildElements()
          Returns an read-only Collection of all children which are Elements.
 Element getFirstChildElement()
          Shortcut method for getting the first Element children with any name.
 Element getFirstChildElement(java.lang.String name)
          Shortcut method for getting the first Element child with a specified name.
 Element getFirstChildElementOrNull()
          Shortcut method for getting the first Element children with any name.
 Element getFirstChildElementOrNull(java.lang.String name)
          Shortcut method for getting the first Element child with a specified name.
 int indexOf(java.lang.Object o)
           
 boolean isEmpty()
           
 java.util.Iterator<Node> iterator()
           
 int lastIndexOf(java.lang.Object o)
           
 java.util.ListIterator<Node> listIterator()
           
 java.util.ListIterator<Node> listIterator(int index)
           
 Node remove(int index)
           
 boolean remove(java.lang.Object o)
           
 boolean removeAll(java.util.Collection<?> c)
           
 boolean retainAll(java.util.Collection<?> c)
           
 Node set(int index, Node newChild)
           
 int size()
           
 java.util.List<Node> subList(int fromIndex, int toIndex)
           
 java.lang.Object[] toArray()
           
<T> T[]
toArray(T[] a)
           
 
Methods inherited from class nu.staldal.xmltree.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
 
Methods inherited from interface java.util.List
equals, hashCode
 

Constructor Detail

NodeWithChildren

public NodeWithChildren()
Construct a node which children.


NodeWithChildren

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

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

NodeWithChildren

protected NodeWithChildren(NodeWithChildren node)
Pseudo-copy constructor, do not copy the children, but allocate room for them.

Parameters:
node - node to copy.
Method Detail

getFirstChildElementOrNull

public Element getFirstChildElementOrNull(java.lang.String name)
Shortcut method for getting the first Element child with a specified name.

Parameters:
name - the qualified name of the element
Returns:
the first child Element with the specified name, or null if there is no such child.

getFirstChildElement

public Element getFirstChildElement(java.lang.String name)
                             throws org.xml.sax.SAXParseException
Shortcut method for getting the first Element child with a specified name.

Parameters:
name - the qualified name of the element
Returns:
the first child Element with the specified name, never null.
Throws:
org.xml.sax.SAXParseException - if there is no such child.

getFirstChildElementOrNull

public Element getFirstChildElementOrNull()
Shortcut method for getting the first Element children with any name.

Returns:
the first child Element or null if there are no Element children.

getFirstChildElement

public Element getFirstChildElement()
                             throws org.xml.sax.SAXParseException
Shortcut method for getting the first Element children with any name.

Returns:
the first child Element never null.
Throws:
org.xml.sax.SAXParseException - if there are no Element children.

getChildElements

public java.util.Collection<Element> getChildElements()
Returns an read-only Collection of all children which are Elements.

Returns:
an read-only Collection of all children which are Elements.

get

public Node get(int index)
Specified by:
get in interface java.util.List<Node>

add

public boolean add(Node newChild)
Specified by:
add in interface java.util.Collection<Node>
Specified by:
add in interface java.util.List<Node>

set

public Node set(int index,
                Node newChild)
Specified by:
set in interface java.util.List<Node>

addAll

public boolean addAll(java.util.Collection<? extends Node> c)
Specified by:
addAll in interface java.util.Collection<Node>
Specified by:
addAll in interface java.util.List<Node>

clear

public void clear()
Specified by:
clear in interface java.util.Collection<Node>
Specified by:
clear in interface java.util.List<Node>

contains

public boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.Collection<Node>
Specified by:
contains in interface java.util.List<Node>

containsAll

public boolean containsAll(java.util.Collection<?> c)
Specified by:
containsAll in interface java.util.Collection<Node>
Specified by:
containsAll in interface java.util.List<Node>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection<Node>
Specified by:
isEmpty in interface java.util.List<Node>

iterator

public java.util.Iterator<Node> iterator()
Specified by:
iterator in interface java.lang.Iterable<Node>
Specified by:
iterator in interface java.util.Collection<Node>
Specified by:
iterator in interface java.util.List<Node>

size

public int size()
Specified by:
size in interface java.util.Collection<Node>
Specified by:
size in interface java.util.List<Node>

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection<Node>
Specified by:
toArray in interface java.util.List<Node>

toArray

public <T> T[] toArray(T[] a)
Specified by:
toArray in interface java.util.Collection<Node>
Specified by:
toArray in interface java.util.List<Node>

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Collection<Node>
Specified by:
remove in interface java.util.List<Node>

removeAll

public boolean removeAll(java.util.Collection<?> c)
Specified by:
removeAll in interface java.util.Collection<Node>
Specified by:
removeAll in interface java.util.List<Node>

retainAll

public boolean retainAll(java.util.Collection<?> c)
Specified by:
retainAll in interface java.util.Collection<Node>
Specified by:
retainAll in interface java.util.List<Node>

add

public void add(int index,
                Node element)
Specified by:
add in interface java.util.List<Node>

addAll

public boolean addAll(int index,
                      java.util.Collection<? extends Node> c)
Specified by:
addAll in interface java.util.List<Node>

indexOf

public int indexOf(java.lang.Object o)
Specified by:
indexOf in interface java.util.List<Node>

lastIndexOf

public int lastIndexOf(java.lang.Object o)
Specified by:
lastIndexOf in interface java.util.List<Node>

listIterator

public java.util.ListIterator<Node> listIterator()
Specified by:
listIterator in interface java.util.List<Node>

listIterator

public java.util.ListIterator<Node> listIterator(int index)
Specified by:
listIterator in interface java.util.List<Node>

remove

public Node remove(int index)
Specified by:
remove in interface java.util.List<Node>

subList

public java.util.List<Node> subList(int fromIndex,
                                    int toIndex)
Specified by:
subList in interface java.util.List<Node>