Fix list modification with DataTree rooted at MapEntryNode 09/43309/2
authorTomas Cere <tcere@cisco.com>
Mon, 8 Aug 2016 12:26:57 +0000 (14:26 +0200)
committerTomas Cere <tcere@cisco.com>
Mon, 8 Aug 2016 12:59:33 +0000 (14:59 +0200)
Follow up to d8f0f2b146500275441ab8ba0cd2e1907f4b4ce4

We also need to handle the building of the list when rooted
at a MapEntry and return the correct node.

Change-Id: I60390e3fee4e34a44ee9f8836c8b9c147047691b
Signed-off-by: Tomas Cere <tcere@cisco.com>
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/UnorderedMapModificationStrategy.java

index 4a8e7731fcd616246c550c19cd07ad668dd834bf..a9aee20a53b44c04f2421113a4cd4746d7b718a2 100644 (file)
@@ -8,14 +8,14 @@
 
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
-import static com.google.common.base.Preconditions.checkArgument;
-
 import com.google.common.base.Optional;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 
@@ -30,14 +30,24 @@ final class UnorderedMapModificationStrategy extends AbstractNodeContainerModifi
     @SuppressWarnings("rawtypes")
     @Override
     protected NormalizedNodeContainerBuilder createBuilder(final NormalizedNode<?, ?> original) {
-        checkArgument(original instanceof MapNode);
-        return ImmutableMapNodeBuilder.create((MapNode) original);
+        // If the DataTree is rooted at a MapEntryNode the original value will be MapEntryNode
+        // so make sure we can handle this aswell
+        if (original instanceof MapNode) {
+            return ImmutableMapNodeBuilder.create((MapNode) original);
+        } else if (original instanceof MapEntryNode) {
+            return ImmutableMapEntryNodeBuilder.create((MapEntryNode) original);
+        }
+        throw new IllegalArgumentException("MapModification strategy can only handle MapNode or MapEntryNode's, offending node: " + original);
     }
 
     @Override
     protected NormalizedNode<?, ?> createEmptyValue(final NormalizedNode<?, ?> original) {
-        checkArgument(original instanceof MapNode);
-        return ImmutableMapNodeBuilder.create().withNodeIdentifier(((MapNode) original).getIdentifier()).build();
+        if (original instanceof MapNode) {
+            return ImmutableMapNodeBuilder.create().withNodeIdentifier(((MapNode) original).getIdentifier()).build();
+        } else if (original instanceof MapEntryNode) {
+            return ImmutableMapEntryNodeBuilder.create().withNodeIdentifier(((MapEntryNode) original).getIdentifier()).build();
+        }
+        throw new IllegalArgumentException("MapModification strategy can only handle MapNode or MapEntryNode's, offending node: " + original);
     }
 
     @Override