org.inria.ns.reflex.xml.dom
Class ListOfNodes

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList
          extended by org.inria.ns.reflex.xml.dom.ListOfNodes
All Implemented Interfaces:
Iterable, Collection, List, NodeList

public class ListOfNodes
extends AbstractList
implements List, NodeList

A list of nodes.

Just for adding a flat list view to the underlying node list.

Flat lists

This view masks the physical representation of the underlying list of nodes, that appears as "flat" :

Text nodes in flat lists

To get the string value of a set of adjacent text nodes, use XMaster.stringValueOf(Object) on the first one, that will delegate to DOMOperator.stringValueOf(Object).

Implementation limitations

List.add(int, java.lang.Object) and List.set(int, java.lang.Object) are not supported : to update a node list, act on the parent directly.

Author:
Philippe Poulard

Field Summary
static NodeList EMPTY_NODE_LIST
          The empty list of nodes.
 
Constructor Summary
ListOfNodes(NodeList nodeList, boolean isListOfElements, Node parent)
          Create a list of nodes from a NodeList.
ListOfNodes(NodeList nodeList, Node parent)
          Create a list of nodes from a NodeList.
 
Method Summary
 Object get(int index)
          Return the node at the index specified.
 int getLength()
          Return the length of the underlying flatenned node list.
 Node item(int index)
          Return the node at the index specified in the underlying flatenned node list.
 Iterator iterator()
          Return an iterator on this list.
 Object remove(int index)
          Remove the node at the index specified.
 int size()
          Return the size of the list.
 
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, set, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
add, add, addAll, addAll, clear, contains, containsAll, equals, hashCode, indexOf, isEmpty, lastIndexOf, listIterator, listIterator, remove, removeAll, retainAll, set, subList, toArray, toArray
 

Field Detail

EMPTY_NODE_LIST

public static NodeList EMPTY_NODE_LIST
The empty list of nodes.

Constructor Detail

ListOfNodes

public ListOfNodes(NodeList nodeList,
                   boolean isListOfElements,
                   Node parent)
Create a list of nodes from a NodeList.

Parameters:
nodeList - The underlying node list.
isListOfElements - true if all items of the list are elements, false otherwise ; a list of elements is reputed flat, and won't be checked.
parent - The parent node, or null
See Also:
Document.getElementsByTagName(java.lang.String), Document.getElementsByTagNameNS(java.lang.String, java.lang.String), Element.getElementsByTagName(java.lang.String), Element.getElementsByTagNameNS(java.lang.String, java.lang.String)

ListOfNodes

public ListOfNodes(NodeList nodeList,
                   Node parent)
Create a list of nodes from a NodeList. Suitable when the node list is a children list. List of elements should be created with the other constructor to avoid checking if the list is flat.

Parameters:
nodeList - The underlying node list.
parent - The parent node, or null
See Also:
Node.getChildNodes(), #ListOfNodes(NodeList, boolean)
Method Detail

get

public Object get(int index)
Return the node at the index specified.

Specified by:
get in interface List
Specified by:
get in class AbstractList
Parameters:
index - The index.
Returns:
The node at the index specified.
See Also:
AbstractList.get(int), item(int)

size

public int size()
Return the size of the list.

Specified by:
size in interface Collection
Specified by:
size in interface List
Specified by:
size in class AbstractCollection
Returns:
The size of the list.
See Also:
AbstractCollection.size(), getLength()

remove

public Object remove(int index)
Remove the node at the index specified.

Specified by:
remove in interface List
Overrides:
remove in class AbstractList
Parameters:
index - The index.
Returns:
The old node, or null if the index was out of range.
See Also:
List.remove(int)

getLength

public int getLength()
Return the length of the underlying flatenned node list.

Specified by:
getLength in interface NodeList
Returns:
The length after flatenning the list.
See Also:
NodeList.getLength()

item

public Node item(int index)
Return the node at the index specified in the underlying flatenned node list.

Specified by:
item in interface NodeList
Parameters:
index - The index of the node to retrieve.
Returns:
The node after flatenning the list.
See Also:
NodeList.item(int)

iterator

public Iterator iterator()
Return an iterator on this list.

Specified by:
iterator in interface Iterable
Specified by:
iterator in interface Collection
Specified by:
iterator in interface List
Overrides:
iterator in class AbstractList
Returns:
An iterator on this list.
See Also:
List.iterator()