FileDocCategorySizeDatePackage
DupFilterIterator.javaAPI DocJava SE 6 API4334Tue Jun 10 00:22:32 BST 2008com.sun.org.apache.xalan.internal.xsltc.dom

DupFilterIterator

public final class DupFilterIterator extends DTMAxisIteratorBase
Removes duplicates and sorts a source iterator. The nodes from the source are collected in an array upon calling setStartNode(). This array is later sorted and duplicates are ignored in next().
author
G. Todd Miller

Fields Summary
private DTMAxisIterator
_source
Reference to source iterator.
private IntegerArray
_nodes
Array to cache all nodes from source.
private int
_current
Index in _nodes array to current node.
private int
_nodesSize
Cardinality of _nodes array.
private int
_lastNext
Last value returned by next().
private int
_markedLastNext
Temporary variable to store _lastNext.
Constructors Summary
public DupFilterIterator(DTMAxisIterator source)


       
	_source = source;
// System.out.println("DFI source = " + source + " this = " + this);

	// Cache contents of id() or key() index right away. Necessary for
	// union expressions containing multiple calls to the same index, and
	// correct as well since start-node is irrelevant for id()/key() exrp.
	if (source instanceof KeyIndex) {
	    setStartNode(DTMDefaultBase.ROOTNODE);
	}
    
Methods Summary
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorcloneIterator()

	try {
	    final DupFilterIterator clone =
		(DupFilterIterator) super.clone();
	    clone._nodes = (IntegerArray) _nodes.clone();
	    clone._source = _source.cloneIterator();
	    clone._isRestartable = false;
	    return clone.reset();
	}
	catch (CloneNotSupportedException e) {
	    BasisLibrary.runTimeError(BasisLibrary.ITERATOR_CLONE_ERR,
				      e.toString());
	    return null;
	}
    
public voidgotoMark()

	_current = _markedNode;
        _lastNext = _markedLastNext;    // Bugzilla 25924
    
public intnext()

	while (_current < _nodesSize) {
	    final int next = _nodes.at(_current++);
	    if (next != _lastNext) {
		return returnNode(_lastNext = next);
	    }
	}
	return END;
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorreset()

	_current = 0;
	_lastNext = END;
	return resetPosition();
    
public voidsetMark()

	_markedNode = _current;
        _markedLastNext = _lastNext;    // Bugzilla 25924
    
public voidsetRestartable(boolean isRestartable)

	_isRestartable = isRestartable;
	_source.setRestartable(isRestartable);
    
public com.sun.org.apache.xml.internal.dtm.DTMAxisIteratorsetStartNode(int node)
Set the start node for this iterator

param
node The start node
return
A reference to this node iterator

	if (_isRestartable) {
	    // KeyIndex iterators are always relative to the root node, so there
	    // is never any point in re-reading the iterator (and we SHOULD NOT).
	    if (_source instanceof KeyIndex
                    && _startNode == DTMDefaultBase.ROOTNODE) {
		return this;
	    }

	    if (node != _startNode) {
		_source.setStartNode(_startNode = node);

		_nodes.clear();
		while ((node = _source.next()) != END) {
		    _nodes.add(node);
		}
		_nodes.sort();
		_nodesSize = _nodes.cardinality();
		_current = 0;
		_lastNext = END;
		resetPosition();
	    }
	}
	return this;