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 / ValueNodeModificationStrategy.java
index 28929539359fb94807c54000fe24c6151ff8eddd..a9f69ac953afdfda5d853e47474d09efe0a26021 100644 (file)
@@ -4,82 +4,85 @@
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
- */package org.opendaylight.controller.md.sal.dom.store.impl.tree.data;
+ */
+package org.opendaylight.controller.md.sal.dom.store.impl.tree.data;
 
- import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkArgument;
 
 import org.opendaylight.controller.md.sal.dom.store.impl.tree.DataPreconditionFailedException;
- import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
- import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
- import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
- import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
- import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
- import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
- import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
- import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+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.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 
 import com.google.common.base.Optional;
- import com.google.common.primitives.UnsignedLong;
 
- abstract class ValueNodeModificationStrategy<T extends DataSchemaNode> extends SchemaAwareApplyOperation {
+abstract class ValueNodeModificationStrategy<T extends DataSchemaNode> extends SchemaAwareApplyOperation {
 
-     private final T schema;
-     private final Class<? extends NormalizedNode<?, ?>> nodeClass;
+    private final T schema;
+    private final Class<? extends NormalizedNode<?, ?>> nodeClass;
 
-     protected ValueNodeModificationStrategy(final T schema, final Class<? extends NormalizedNode<?, ?>> nodeClass) {
-         super();
-         this.schema = schema;
-         this.nodeClass = nodeClass;
-     }
+    protected ValueNodeModificationStrategy(final T schema, final Class<? extends NormalizedNode<?, ?>> nodeClass) {
+        super();
+        this.schema = schema;
+        this.nodeClass = nodeClass;
+    }
 
-     @Override
-     protected void verifyWrittenStructure(final NormalizedNode<?, ?> writtenValue) {
-         checkArgument(nodeClass.isInstance(writtenValue), "Node should must be of type %s", nodeClass);
-     }
+    @Override
+    protected void verifyWrittenStructure(final NormalizedNode<?, ?> writtenValue) {
+        checkArgument(nodeClass.isInstance(writtenValue), "Node should must be of type %s", nodeClass);
+    }
 
-     @Override
-     public Optional<ModificationApplyOperation> getChild(final PathArgument child) {
-         throw new UnsupportedOperationException("Node " + schema.getPath()
-                 + "is leaf type node. Child nodes not allowed");
-     }
+    @Override
+    public Optional<ModificationApplyOperation> getChild(final PathArgument child) {
+        throw new UnsupportedOperationException("Node " + schema.getPath()
+                + "is leaf type node. Child nodes not allowed");
+    }
 
-     @Override
-     protected StoreMetadataNode applySubtreeChange(final NodeModification modification,
-             final StoreMetadataNode currentMeta, final UnsignedLong subtreeVersion) {
-         throw new UnsupportedOperationException("Node " + schema.getPath()
-                 + "is leaf type node. Subtree change is not allowed.");
-     }
+    @Override
+    protected TreeNode applySubtreeChange(final ModifiedNode modification,
+            final TreeNode currentMeta, final Version version) {
+        throw new UnsupportedOperationException("Node " + schema.getPath()
+                + "is leaf type node. Subtree change is not allowed.");
+    }
 
-     @Override
-     protected StoreMetadataNode applyMerge(final NodeModification modification, final StoreMetadataNode currentMeta,
-             final UnsignedLong subtreeVersion) {
-         return applyWrite(modification, Optional.of(currentMeta), subtreeVersion);
-     }
+    @Override
+    protected TreeNode applyMerge(final ModifiedNode modification, final TreeNode currentMeta,
+            final Version version) {
+        // Just overwrite whatever was there
+        return applyWrite(modification, null, version);
+    }
 
-     @Override
-     protected StoreMetadataNode applyWrite(final NodeModification modification,
-             final Optional<StoreMetadataNode> currentMeta, final UnsignedLong subtreeVersion) {
-         return StoreMetadataNode.builder(subtreeVersion).setSubtreeVersion(subtreeVersion)
-                 .setData(modification.getWrittenValue()).build();
-     }
+    @Override
+    protected TreeNode applyWrite(final ModifiedNode modification,
+            final Optional<TreeNode> currentMeta, final Version version) {
+        return TreeNodeFactory.createTreeNode(modification.getWrittenValue(), version);
+    }
 
-     @Override
-     protected void checkSubtreeModificationApplicable(final InstanceIdentifier path,final NodeModification modification,
-             final Optional<StoreMetadataNode> current) throws DataPreconditionFailedException {
-         throw new DataPreconditionFailedException(path, "Subtree modification is not allowed.");
-     }
+    @Override
+    protected void checkSubtreeModificationApplicable(final InstanceIdentifier path, final NodeModification modification,
+            final Optional<TreeNode> current) throws DataPreconditionFailedException {
+        throw new DataPreconditionFailedException(path, "Subtree modification is not allowed.");
+    }
 
-     public static class LeafSetEntryModificationStrategy extends ValueNodeModificationStrategy<LeafListSchemaNode> {
-         @SuppressWarnings({ "unchecked", "rawtypes" })
-         protected LeafSetEntryModificationStrategy(final LeafListSchemaNode schema) {
-             super(schema, (Class) LeafSetEntryNode.class);
-         }
-     }
+    public static class LeafSetEntryModificationStrategy extends ValueNodeModificationStrategy<LeafListSchemaNode> {
+        @SuppressWarnings({ "unchecked", "rawtypes" })
+        protected LeafSetEntryModificationStrategy(final LeafListSchemaNode schema) {
+            super(schema, (Class) LeafSetEntryNode.class);
+        }
+    }
 
-     public static class LeafModificationStrategy extends ValueNodeModificationStrategy<LeafSchemaNode> {
-         @SuppressWarnings({ "unchecked", "rawtypes" })
-         protected LeafModificationStrategy(final LeafSchemaNode schema) {
-             super(schema, (Class) LeafNode.class);
-         }
-     }
- }
\ No newline at end of file
+    public static class LeafModificationStrategy extends ValueNodeModificationStrategy<LeafSchemaNode> {
+        @SuppressWarnings({ "unchecked", "rawtypes" })
+        protected LeafModificationStrategy(final LeafSchemaNode schema) {
+            super(schema, (Class) LeafNode.class);
+        }
+    }
+}
\ No newline at end of file