|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.swing.text.ElementIterator
Safe:
ElementIterator, as the name suggests, iteratates over the Element tree. The constructor can be invoked with either Document or an Element as an argument. If the constructor is invoked with a Document as an argument then the root of the iteration is the return value of document.getDefaultRootElement(). The iteration happens in a depth-first manner. In terms of how boundary conditions are handled: a) if next() is called before first() or current(), the root will be returned. b) next() returns null to indicate the end of the list. c) previous() returns null when the current element is the root or next() has returned null. The ElementIterator does no locking of the Element tree. This means that it does not track any changes. It is the responsibility of the user of this class, to ensure that no changes happen during element iteration. Simple usage example: public void iterate() { ElementIterator it = new ElementIterator(root); Element elem; while (true) { if ((elem = next()) != null) { // process element System.out.println("elem: " + elem.getName()); } else { break; } } }
Field Summary | |
private Stack |
elementStack
|
private Element |
root
|
Constructor Summary | |
ElementIterator(Document document)
Enabled: Creates a new ElementIterator. |
|
ElementIterator(Element root)
Enabled: Creates a new ElementIterator. |
Method Summary | |
Object |
clone()
Suppressed: Clones the ElementIterator. |
Element |
current()
Enabled: Fetches the current Element. |
int |
depth()
Enabled: Fetches the current depth of element tree. |
private void |
dumpTree()
|
Element |
first()
Enabled: Fetches the first element. |
private Element |
getDeepestLeaf(Element parent)
Returns the last child of parent that is a leaf. |
Element |
next()
Enabled: Fetches the next Element. |
Element |
previous()
Enabled: Fetches the previous Element. |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private Element root
private Stack elementStack
Constructor Detail |
public ElementIterator(Document document)
public ElementIterator(Element root)
Method Detail |
public Object clone()
clone
in class Object
java.lang.Cloneable
public Element first()
public int depth()
public Element current()
null
if the root element is null
public Element next()
null
at the end of the list.public Element previous()
Element
if availableprivate Element getDeepestLeaf(Element parent)
parent
that is a leaf. If the
last child is a not a leaf, this method is called with the last child.
private void dumpTree()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |