import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.NotThreadSafe;
import org.opendaylight.yangtools.concepts.Identifiable;
import org.opendaylight.yangtools.yang.data.api.schema.tree.StoreTreeNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
/**
* Node Modification Node and Tree
*
private Optional<TreeNode> snapshotCache;
private NormalizedNode<?, ?> value;
- private ModifiedNode(final PathArgument identifier, final Optional<TreeNode> original, boolean isOrdered) {
+ private ModifiedNode(final PathArgument identifier, final Optional<TreeNode> original, final boolean isOrdered) {
this.identifier = identifier;
this.original = original;
* @return {@link org.opendaylight.controller.md.sal.dom.store.impl.tree.data.ModifiedNode} for specified child, with {@link #getOriginal()}
* containing child metadata if child was present in original data.
*/
- public ModifiedNode modifyChild(final PathArgument child, boolean isOrdered) {
+ public ModifiedNode modifyChild(final PathArgument child, final boolean isOrdered) {
clearSnapshot();
if (modificationType == ModificationType.UNMODIFIED) {
updateModificationType(ModificationType.SUBTREE_MODIFIED);
this.value = data;
}
+ /**
+ * Seal the modification node and prune any children which has not been
+ * modified.
+ */
void seal() {
clearSnapshot();
- for (ModifiedNode child : children.values()) {
+
+ // Walk all child nodes and remove any children which have not
+ // been modified.
+ final Iterator<ModifiedNode> it = children.values().iterator();
+ while (it.hasNext()) {
+ final ModifiedNode child = it.next();
child.seal();
+
+ if (child.modificationType == ModificationType.UNMODIFIED) {
+ it.remove();
+ }
+ }
+
+ // A SUBTREE_MODIFIED node without any children is a no-op
+ if (modificationType == ModificationType.SUBTREE_MODIFIED && children.isEmpty()) {
+ updateModificationType(ModificationType.UNMODIFIED);
}
}
+ modificationType + ", childModification=" + children + "]";
}
- public static ModifiedNode createUnmodified(final TreeNode metadataTree, boolean isOrdered) {
+ public static ModifiedNode createUnmodified(final TreeNode metadataTree, final boolean isOrdered) {
return new ModifiedNode(metadataTree.getIdentifier(), Optional.of(metadataTree), isOrdered);
}
}