Hi,
thank you for your quick answer once again — it is always great to see you’re taking customer care seriously.
I do know the Visitor pattern, though, and I don’t think it specifies the precise iteration algorithm. In essence, it just says that visiting a Composite consists of visiting the composite object itself and visiting each of its Components — in which order is (and can) not be specified (because Composite doesn’t require a Composite’s Components to be ordered).
The reason I’m asking is this: I’ve got a DocumentVisitor whose visit(FieldStart) method may or may not remove the FieldStart object fieldStart it visits, plus any ancestors of fieldStart that become empty this way, and I’d like to carry on visiting the tree right after the removed nodes. What I’m doing is something like this:
public int visit(FieldStart fieldStart) {
Node previousNode = /** get a node before fieldStart that will not be deleted */
doSth(fieldStart); // This deletes fieldStart from the document tree;
previousNode.nextPreOrder(null).accept(this);
return VisitorAction.STOP;
}
However, contrary to what I expect, the Visitor will never visit previousNode.nextPreOrder(null).nextPreOrder(null).nextPreOrder(null)
which leads me to think that the iteration algorithm does something that I don’t understand right now.
I know this is very little information I’m giving you here, but I’d be very grateful if you could come up with a reason why this algorithm of mine fails. If not, I’ll hack up a minimal example and attach it to this post tomorrow.
Cheers,
Johannes