org.jdesktop.dom
Class SimpleNodeList

java.lang.Object
  extended by org.jdesktop.dom.SimpleNodeList
All Implemented Interfaces:
Iterable<Node>, NodeList

public class SimpleNodeList
extends Object
implements NodeList, Iterable<Node>

An implementation of NodeList which also implements Iterable. This allows you to use a SimpleNodeList in an enhanced for loop, such as:


  SimpleNodeList nodes = ...;
  for (Node n : nodes) {
      System.out.println(n.getTextContent());
  }
 

SimpleNodeList wraps a source NodeList. Thus, any NodeList can be adapted for use with enhanced for loops by wrapping it in a SimpleNodeList.


Constructor Summary
SimpleNodeList(List<Node> nodes)
          Create a new SimpleNodeList that wraps the given nodes
SimpleNodeList(Node... nodes)
          Create a new SimpleNodeList that wraps the given nodes
SimpleNodeList(NodeList list)
          Creates a new instance of SimpleNodeList.
 
Method Summary
 int getLength()
          The number of nodes in the list.
 Node item(int index)
          Returns the indexth item in the collection.
 Iterator<Node> iterator()
          Returns an iterator over a set of elements of type T.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleNodeList

public SimpleNodeList(NodeList list)
Creates a new instance of SimpleNodeList.

Parameters:
list - the NodeList to wrap.

SimpleNodeList

public SimpleNodeList(List<Node> nodes)
Create a new SimpleNodeList that wraps the given nodes

Parameters:
nodes - the nodes to wrap

SimpleNodeList

public SimpleNodeList(Node... nodes)
Create a new SimpleNodeList that wraps the given nodes

Parameters:
nodes - the nodes to wrap
Method Detail

item

public Node item(int index)
Description copied from interface: org.w3c.dom.NodeList
Returns the indexth item in the collection. If index is greater than or equal to the number of nodes in the list, this returns null.

Specified by:
item in interface NodeList
Parameters:
index - Index into the collection.
Returns:
The node at the indexth position in the NodeList, or null if that is not a valid index.

getLength

public int getLength()
Description copied from interface: org.w3c.dom.NodeList
The number of nodes in the list. The range of valid child node indices is 0 to length-1 inclusive.

Specified by:
getLength in interface NodeList

iterator

public Iterator<Node> iterator()
Description copied from interface: java.lang.Iterable
Returns an iterator over a set of elements of type T.

Specified by:
iterator in interface Iterable<Node>
Returns:
an Iterator.