Challenge to be taken care of (Bernd Eilers)

What´s returned as java.util.List at that textBody.getContent() call is
in fact an instance of class BlockContent which extends
java.util.AbstractList. What the listIterator() and iterator() methods
of that AbstractList returns which are curently not overriden in
BlockContent would likely call the get(int index) method with an
advancing index for every next() call on the Iterator. The get(int
index) method which we have in BlockContent now basically starts every
time at the first childElement advancing until it gets to the index
element at each call. Adding that together means that the current
iterator is highly inefficent especially when considering large
documents. So this means it would be a good idea to implement some inner
class which implements ListIterator for BlockContent and to override the
iterator and listIterator methods to return an instance of that class.
This inner class should keep an pointer into the DOM tree for
remembering where it is and just call factory.getElement() similar as it
is done in the get(int index) Method.

Leave a Reply