BUG-4295: fix merge callsite
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / UnkeyedListModificationStrategy.java
index ace568fd21924a3fc16d3f604d5dbc8d4f9373be..561f5fcc7876ee17cc98138a8cfab40895561c5a 100644 (file)
@@ -8,13 +8,13 @@
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
 import com.google.common.base.Optional;
-import com.google.common.collect.Iterables;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 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.UnkeyedListEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.IncorrectDataStructureException;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.MutableTreeNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory;
@@ -27,23 +27,23 @@ final class UnkeyedListModificationStrategy extends SchemaAwareApplyOperation {
 
     private final Optional<ModificationApplyOperation> entryStrategy;
 
-    protected UnkeyedListModificationStrategy(final ListSchemaNode schema) {
-        entryStrategy = Optional.<ModificationApplyOperation> of(new DataNodeContainerModificationStrategy.UnkeyedListItemModificationStrategy(schema));
+    UnkeyedListModificationStrategy(final ListSchemaNode schema, final TreeType treeType) {
+        entryStrategy = Optional.<ModificationApplyOperation> of(new UnkeyedListItemModificationStrategy(schema, treeType));
     }
 
     @Override
-    boolean isOrdered() {
-        return true;
+    protected ChildTrackingPolicy getChildPolicy() {
+        return ChildTrackingPolicy.ORDERED;
     }
 
     @Override
-    protected TreeNode applyMerge(final ModifiedNode modification, final TreeNode currentMeta,
-            final Version version) {
-        return applyWrite(modification, Optional.of(currentMeta), version);
+    protected TreeNode applyMerge(final ModifiedNode modification, final TreeNode currentMeta, final Version version) {
+        throw new IllegalStateException(String.format("Merge of modification %s on unkeyed list should never be called",
+            modification));
     }
 
     @Override
-    protected TreeNode applySubtreeChange(final ModifiedNode modification,
+    protected TreeNode applyTouch(final ModifiedNode modification,
             final TreeNode currentMeta, final Version version) {
         throw new UnsupportedOperationException("UnkeyedList does not support subtree change.");
     }
@@ -54,7 +54,7 @@ final class UnkeyedListModificationStrategy extends SchemaAwareApplyOperation {
         final NormalizedNode<?, ?> newValue = modification.getWrittenValue();
         final TreeNode newValueMeta = TreeNodeFactory.createTreeNode(newValue, version);
 
-        if (Iterables.isEmpty(modification.getChildren())) {
+        if (modification.getChildren().isEmpty()) {
             return newValueMeta;
         }
 
@@ -93,11 +93,11 @@ final class UnkeyedListModificationStrategy extends SchemaAwareApplyOperation {
     private TreeNode mutateChildren(final MutableTreeNode meta, final NormalizedNodeContainerBuilder data,
         final Version nodeVersion, final Iterable<ModifiedNode> modifications) {
 
-        for (ModifiedNode mod : modifications) {
+        for (final ModifiedNode mod : modifications) {
             final PathArgument id = mod.getIdentifier();
             final Optional<TreeNode> cm = meta.getChild(id);
 
-            Optional<TreeNode> result = resolveChildOperation(id).apply(mod, cm, nodeVersion);
+            final Optional<TreeNode> result = resolveChildOperation(id).apply(mod, cm, nodeVersion);
             if (result.isPresent()) {
                 final TreeNode tn = result.get();
                 meta.addChild(tn);
@@ -121,13 +121,24 @@ final class UnkeyedListModificationStrategy extends SchemaAwareApplyOperation {
     }
 
     @Override
-    protected void verifyWrittenStructure(final NormalizedNode<?, ?> writtenValue) {
+    protected void verifyStructure(final NormalizedNode<?, ?> writtenValue, final boolean verifyChildren) {
 
     }
 
     @Override
-    protected void checkSubtreeModificationApplicable(final YangInstanceIdentifier path, final NodeModification modification,
-            final Optional<TreeNode> current) throws IncorrectDataStructureException {
+    void recursivelyVerifyStructure(NormalizedNode<?, ?> value) {
+        // NOOP
+    }
+
+    @Override
+    protected void checkTouchApplicable(final YangInstanceIdentifier path, final NodeModification modification,
+            final Optional<TreeNode> current, final Version version) throws IncorrectDataStructureException {
         throw new IncorrectDataStructureException(path, "Subtree modification is not allowed.");
     }
-}
\ No newline at end of file
+
+    @Override
+    void mergeIntoModifiedNode(final ModifiedNode node, final NormalizedNode<?, ?> value, final Version version) {
+        // Unkeyed lists are always replaced
+        node.write(value);
+    }
+}