BUG-509: remove unnecessary Version objects
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / md / sal / dom / store / impl / tree / data / NormalizedNodeContainerModificationStrategy.java
index c5037bc0c64714cb10de717a6c46954f8d5cf78b..b70c5d18dc58a6c30c36864678d4c725dc6fd0b9 100644 (file)
@@ -19,6 +19,7 @@ import org.opendaylight.controller.md.sal.dom.store.impl.tree.data.ValueNodeModi
 import org.opendaylight.controller.md.sal.dom.store.impl.tree.spi.MutableTreeNode;
 import org.opendaylight.controller.md.sal.dom.store.impl.tree.spi.TreeNode;
 import org.opendaylight.controller.md.sal.dom.store.impl.tree.spi.TreeNodeFactory;
+import org.opendaylight.controller.md.sal.dom.store.impl.tree.spi.Version;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifierWithPredicates;
@@ -46,7 +47,6 @@ import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Iterables;
-import com.google.common.primitives.UnsignedLong;
 
 abstract class NormalizedNodeContainerModificationStrategy extends SchemaAwareApplyOperation {
 
@@ -95,16 +95,9 @@ abstract class NormalizedNodeContainerModificationStrategy extends SchemaAwareAp
 
     @Override
     protected TreeNode applyWrite(final ModifiedNode modification,
-            final Optional<TreeNode> currentMeta, final UnsignedLong subtreeVersion) {
-        final UnsignedLong nodeVersion;
-        if (currentMeta.isPresent()) {
-            nodeVersion = StoreUtils.increase(currentMeta.get().getVersion());
-        } else {
-            nodeVersion = subtreeVersion;
-        }
-
+            final Optional<TreeNode> currentMeta, final Version version) {
         final NormalizedNode<?, ?> newValue = modification.getWrittenValue();
-        final TreeNode newValueMeta = TreeNodeFactory.createTreeNode(newValue, nodeVersion);
+        final TreeNode newValueMeta = TreeNodeFactory.createTreeNode(newValue, version);
 
         if (Iterables.isEmpty(modification.getChildren())) {
             return newValueMeta;
@@ -122,17 +115,17 @@ abstract class NormalizedNodeContainerModificationStrategy extends SchemaAwareAp
          * and run the common parts on it -- which end with the node being sealed.
          */
         final MutableTreeNode mutable = newValueMeta.mutable();
-        mutable.setSubtreeVersion(subtreeVersion);
+        mutable.setSubtreeVersion(version);
 
         @SuppressWarnings("rawtypes")
         final NormalizedNodeContainerBuilder dataBuilder = createBuilder(newValue);
 
-        return mutateChildren(mutable, dataBuilder, nodeVersion, modification.getChildren());
+        return mutateChildren(mutable, dataBuilder, version, modification.getChildren());
     }
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
     private TreeNode mutateChildren(final MutableTreeNode meta, final NormalizedNodeContainerBuilder data,
-            final UnsignedLong nodeVersion, final Iterable<ModifiedNode> modifications) {
+            final Version nodeVersion, final Iterable<ModifiedNode> modifications) {
 
         for (ModifiedNode mod : modifications) {
             final PathArgument id = mod.getIdentifier();
@@ -155,24 +148,21 @@ abstract class NormalizedNodeContainerModificationStrategy extends SchemaAwareAp
 
     @Override
     protected TreeNode applyMerge(final ModifiedNode modification, final TreeNode currentMeta,
-            final UnsignedLong subtreeVersion) {
+            final Version version) {
         // For Node Containers - merge is same as subtree change - we only replace children.
-        return applySubtreeChange(modification, currentMeta, subtreeVersion);
+        return applySubtreeChange(modification, currentMeta, version);
     }
 
     @Override
     public TreeNode applySubtreeChange(final ModifiedNode modification,
-            final TreeNode currentMeta, final UnsignedLong subtreeVersion) {
-        // Bump subtree version to its new target
-        final UnsignedLong updatedSubtreeVersion = StoreUtils.increase(currentMeta.getSubtreeVersion());
-
+            final TreeNode currentMeta, final Version version) {
         final MutableTreeNode newMeta = currentMeta.mutable();
-        newMeta.setSubtreeVersion(updatedSubtreeVersion);
+        newMeta.setSubtreeVersion(version);
 
         @SuppressWarnings("rawtypes")
         NormalizedNodeContainerBuilder dataBuilder = createBuilder(currentMeta.getData());
 
-        return mutateChildren(newMeta, dataBuilder, updatedSubtreeVersion, modification.getChildren());
+        return mutateChildren(newMeta, dataBuilder, version, modification.getChildren());
     }
 
     @Override