Optimize ImmutableNodes.leafNode()
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / InMemoryDataTreeModificationCursor.java
index 17216ee92f491156c02826f0e4801d7939bd5a5b..ff926179bcb3d3493be2d0ae3258a349bec8ff75 100644 (file)
@@ -7,22 +7,26 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+
 import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Deque;
 import java.util.Iterator;
+import java.util.Optional;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModificationCursor;
 
-final class InMemoryDataTreeModificationCursor extends AbstractCursor<InMemoryDataTreeModification> implements DataTreeModificationCursor {
+final class InMemoryDataTreeModificationCursor extends AbstractCursor<InMemoryDataTreeModification>
+        implements DataTreeModificationCursor {
     private final Deque<OperationWithModification> stack = new ArrayDeque<>();
 
-    InMemoryDataTreeModificationCursor(final InMemoryDataTreeModification parent, final YangInstanceIdentifier rootPath, final OperationWithModification rootOp) {
+    InMemoryDataTreeModificationCursor(final InMemoryDataTreeModification parent, final YangInstanceIdentifier rootPath,
+            final OperationWithModification rootOp) {
         super(parent, rootPath);
         stack.push(rootOp);
     }
@@ -34,7 +38,8 @@ final class InMemoryDataTreeModificationCursor extends AbstractCursor<InMemoryDa
         final Optional<ModificationApplyOperation> potential = op.getApplyOperation().getChild(child);
         if (potential.isPresent()) {
             final ModificationApplyOperation operation = potential.get();
-            final ModifiedNode modification = op.getModification().modifyChild(child, operation.getChildPolicy());
+            final ModifiedNode modification = op.getModification().modifyChild(child, operation,
+                getParent().getVersion());
 
             return OperationWithModification.from(operation, modification);
         }
@@ -60,6 +65,7 @@ final class InMemoryDataTreeModificationCursor extends AbstractCursor<InMemoryDa
     }
 
     @Override
+    @SuppressWarnings("checkstyle:illegalCatch")
     public void enter(final Iterable<PathArgument> path) {
         int depth = 0;
         for (PathArgument child : path) {
@@ -78,8 +84,8 @@ final class InMemoryDataTreeModificationCursor extends AbstractCursor<InMemoryDa
 
     @Override
     public void exit(final int depth) {
-        Preconditions.checkArgument(depth >= 0);
-        Preconditions.checkState(depth < stack.size());
+        checkArgument(depth >= 0);
+        checkState(depth < stack.size());
 
         for (int i = 0; i < depth; i++) {
             stack.pop();
@@ -101,7 +107,7 @@ final class InMemoryDataTreeModificationCursor extends AbstractCursor<InMemoryDa
     public void merge(final PathArgument child, final NormalizedNode<?, ?> data) {
         ensureNotClosed();
         InMemoryDataTreeModification.checkIdentifierReferencesData(child, data);
-        resolveChildModification(child).merge(data);
+        resolveChildModification(child).merge(data, getParent().getVersion());
     }
 
     @Override