JAPI 0.9.0
Yet another Java API
API Documentation

net.sf.japi.xml
Class NodeListIterator<T extends Node>

java.lang.Object
  extended by net.sf.japi.xml.NodeListIterator<T>
All Implemented Interfaces:
Iterable<T>, Iterator<T>

public class NodeListIterator<T extends Node>
extends Object
implements Iterable<T>, Iterator<T>

A combined iterable / iterator implementation for iterating over NodeLists.

Author:
Christian Hujer

Constructor Summary
NodeListIterator(Element item, short nodeType)
          Create a NodeListIterator.
NodeListIterator(Element item, String childName)
          Create a NodeListIterator.
NodeListIterator(NodeList nodeList)
          Create a NodeListIterator.
NodeListIterator(XPath xpath, Element item, String expression)
          Create a NodeListIterator.
 
Method Summary
static Element getFirstChild(Element el, String childName)
          Convenience helper method for getting the first child of an element that is an element with a specific name.
 boolean hasNext()
          Returns true if the iteration has more elements.
 Iterator<T> iterator()
          Returns an iterator over a set of elements of type T.
 T next()
          Returns the next element in the iteration.
 void remove()
          Removes from the underlying collection the last element returned by the iterator (optional operation).
 int size()
          Get the number of elements this iterator would iterate over all.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NodeListIterator

public NodeListIterator(@NotNull
                        NodeList nodeList)
Create a NodeListIterator.

Parameters:
nodeList - NodeList to iterate over

NodeListIterator

public NodeListIterator(@NotNull
                        Element item,
                        short nodeType)
Create a NodeListIterator.

Parameters:
item - Element to evaluate against
nodeType - node type of children

NodeListIterator

public NodeListIterator(@NotNull
                        Element item,
                        @NotNull
                        String childName)
Create a NodeListIterator.

Parameters:
item - Element to evaluate against
childName - name of child element

NodeListIterator

public NodeListIterator(@NotNull
                        XPath xpath,
                        @NotNull
                        Element item,
                        @NotNull
                        String expression)
                 throws XPathExpressionException
Create a NodeListIterator.

Parameters:
xpath - XPath to evaulate against
item - Object to evaluate against
expression - XPath expression to evaluate
Throws:
XPathExpressionException - in case of xpath errors
Method Detail

getFirstChild

@Nullable
public static Element getFirstChild(Element el,
                                             String childName)
Convenience helper method for getting the first child of an element that is an element with a specific name.

Parameters:
el - element to get child of
childName - name of child element to get
Returns:
child element or null if no such child element

iterator

@NotNull
public Iterator<T> iterator()
Returns an iterator over a set of elements of type T.

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

hasNext

public boolean hasNext()
Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Specified by:
hasNext in interface Iterator<T extends Node>
Returns:
true if the iterator has more elements.

next

@NotNull
public T next()
                    throws NoSuchElementException
Returns the next element in the iteration. Calling this method repeatedly until the Iterator.hasNext() method returns false will return each element in the underlying collection exactly once.

Specified by:
next in interface Iterator<T extends Node>
Returns:
the next element in the iteration.
Throws:
NoSuchElementException - iteration has no more elements.

remove

public void remove()
Removes from the underlying collection the last element returned by the iterator (optional operation). This method can be called only once per call to next. The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method.

Specified by:
remove in interface Iterator<T extends Node>

size

public int size()
Get the number of elements this iterator would iterate over all.

Returns:
number of elements

JAPI
Yet another Java API
API Documentation

© 2005-2006 Christian Hujer. All rights reserved. See copyright