Some of the comments have been lost. This class implements a depth-first
tree iterator, which does not use stack for keeping state, hence its
code flow should be better commented.
Change-Id: I604b0cef6f402c0e10403a7c29d272939ba2e8bd
Signed-off-by: Robert Varga <robert.varga@pantheon.sk>
final AbstractReadyIterator process(final Version version) {
// Walk all child nodes and remove any children which have not
final AbstractReadyIterator process(final Version version) {
// Walk all child nodes and remove any children which have not
- // been modified. If a child
+ // been modified. If a child has children, we need to iterate
+ // through it via re-entering this method on the child iterator.
while (children.hasNext()) {
final ModifiedNode child = children.next();
final Optional<ModificationApplyOperation> childOperation = op.getChild(child.getIdentifier());
while (children.hasNext()) {
final ModifiedNode child = children.next();
final Optional<ModificationApplyOperation> childOperation = op.getChild(child.getIdentifier());
final ModificationApplyOperation childOp = childOperation.get();
if (grandChildren.isEmpty()) {
final ModificationApplyOperation childOp = childOperation.get();
if (grandChildren.isEmpty()) {
+ // The child is empty, seal it
child.seal(childOp, version);
if (child.getOperation() == LogicalOperation.NONE) {
children.remove();
child.seal(childOp, version);
if (child.getOperation() == LogicalOperation.NONE) {
children.remove();
+ // We are done with this node, seal it.
node.seal(op, version);
// Remove from parent if we have one and this is a no-op
if (node.getOperation() == LogicalOperation.NONE) {
removeFromParent();
}
node.seal(op, version);
// Remove from parent if we have one and this is a no-op
if (node.getOperation() == LogicalOperation.NONE) {
removeFromParent();
}
+
+ // Sub-iteration complete, return back to parent