org.jaxen.util

Class PrecedingAxisIterator

Implemented Interfaces:
Iterator

public class PrecedingAxisIterator
extends java.lang.Object
implements Iterator

Represents the XPath preceding axis. The "preceding axis contains all nodes in the same document as the context node that are before the context node in document order, excluding any ancestors and excluding attribute nodes and namespace nodes."

This implementation of 'preceding' works like so: the preceding axis includes preceding siblings of this node and their descendants. Also, for each ancestor node of this node, it includes all preceding siblings of that ancestor, and their descendants. Finally, it includes the ancestor nodes themselves.

The reversed descendant-or-self axes that are required are calculated using a stack of reversed 'child-or-self' axes. When asked for a node, it is always taken from a child-or-self axis. If it was the last node on that axis, the node is returned. Otherwise, this axis is pushed on the stack, and the process is repeated with the child-or-self of the node. Eventually this recurses down to the last descendant of any node, then works back up to the root.

Most object models could provide a faster implementation of the reversed 'children-or-self' used here.

Version:
1.2b12

Field Summary

private Iterator
ancestorOrSelf
private ListIterator
childrenOrSelf
private Navigator
navigator
private Iterator
precedingSibling
private ArrayList
stack

Constructor Summary

PrecedingAxisIterator(Object contextNode, Navigator navigator)
Create a new preceding axis iterator.

Method Summary

private ListIterator
childrenOrSelf(Object node)
boolean
hasNext()
Returns true if there are any preceding nodes remaining; false otherwise.
Object
next()
Returns the next preceding node.
void
remove()
This operation is not supported.

Field Details

ancestorOrSelf

private Iterator ancestorOrSelf

childrenOrSelf

private ListIterator childrenOrSelf

navigator

private Navigator navigator

precedingSibling

private Iterator precedingSibling

stack

private ArrayList stack

Constructor Details

PrecedingAxisIterator

public PrecedingAxisIterator(Object contextNode,
                             Navigator navigator)
            throws UnsupportedAxisException
Create a new preceding axis iterator.
Parameters:
contextNode - the node to start from
navigator - the object model specific navigator

Method Details

childrenOrSelf

private ListIterator childrenOrSelf(Object node)

hasNext

public boolean hasNext()
Returns true if there are any preceding nodes remaining; false otherwise.
Returns:
true if any preceding nodes remain; false otherwise
See Also:
java.util.Iterator.hasNext()

next

public Object next()
            throws NoSuchElementException
Returns the next preceding node.
Returns:
the next preceding node
See Also:
java.util.Iterator.next()

remove

public void remove()
            throws UnsupportedOperationException
This operation is not supported.