Package org.jsoup.nodes
Class NodeIterator<T extends Node>
- java.lang.Object
-
- org.jsoup.nodes.NodeIterator<T>
-
- All Implemented Interfaces:
java.util.Iterator<T>
public class NodeIterator<T extends Node> extends java.lang.Object implements java.util.Iterator<T>
Iterate through a Node and its tree of descendants, in document order, and returns nodes of the specified type. This iterator supports structural changes to the tree during the traversal, such asNode.remove()
,Node.replaceWith(Node)
,Node.wrap(String)
, etc.See also the
NodeTraversor
ifhead
andtail
callbacks are desired for each node.- Since:
- 1.17.1
-
-
Constructor Summary
Constructors Constructor Description NodeIterator(Node start, java.lang.Class<T> type)
Create a NoteIterator that will iterate the supplied node, and all of its descendants.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private T
findNextNode()
static NodeIterator<Node>
from(Node start)
Create a NoteIterator that will iterate the supplied node, and all of its descendants.boolean
hasNext()
private void
maybeFindNext()
If next is not null, looks for and sets next.T
next()
void
remove()
void
restart(Node start)
Restart this Iterator from the specified start node.
-
-
-
Method Detail
-
from
public static NodeIterator<Node> from(Node start)
Create a NoteIterator that will iterate the supplied node, and all of its descendants. All node types will be returned.- Parameters:
start
- initial node
-
restart
public void restart(Node start)
Restart this Iterator from the specified start node. Will act as if it were newly constructed. Useful for e.g. to save some GC if the iterator is used in a tight loop.- Parameters:
start
- the new start node.
-
hasNext
public boolean hasNext()
-
maybeFindNext
private void maybeFindNext()
If next is not null, looks for and sets next. If next is null after this, we have reached the end.
-
findNextNode
private T findNextNode()
-
-