Reduce list/map/entry strategy confusion 98/93898/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 18 Nov 2020 14:24:24 +0000 (15:24 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 20 Nov 2020 16:56:35 +0000 (17:56 +0100)
Lists with a key are called 'Map' and contain 'MapEntry'
Lists without a key are called a 'List' and do not have an entry
strategy (yet).

Change-Id: I0321eaebf1541a86778c63a2eaa68bdffcd8672a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 37380a5c65e213bc5f34b521d8f8e7d315df7465)

yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTree.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ListModificationStrategy.java [moved from yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/UnkeyedListModificationStrategy.java with 97% similarity]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/MapEntryModificationStrategy.java [moved from yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ListEntryModificationStrategy.java with 87% similarity]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/MapModificationStrategy.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/SchemaAwareApplyOperation.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/MapEntryRootTest.java

index 29cd2d4de893bb52c0fb1ab7701b0948793ee7cf..1078f74b17187f5b71e2ab6737091f1d2ffa84fc 100644 (file)
@@ -82,8 +82,8 @@ final class InMemoryDataTree extends AbstractDataTreeTip implements DataTree {
         if (rootSchemaNode instanceof ListSchemaNode) {
             final PathArgument arg = treeConfig.getRootPath().getLastPathArgument();
             if (arg instanceof NodeIdentifierWithPredicates) {
-                return maskMandatory ? new ListEntryModificationStrategy((ListSchemaNode) rootSchemaNode, treeConfig)
-                        : ListEntryModificationStrategy.of((ListSchemaNode) rootSchemaNode, treeConfig);
+                return maskMandatory ? new MapEntryModificationStrategy((ListSchemaNode) rootSchemaNode, treeConfig)
+                        : MapEntryModificationStrategy.of((ListSchemaNode) rootSchemaNode, treeConfig);
             }
         }
 
@@ -24,7 +24,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNo
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListEntryNodeBuilder;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 
-final class UnkeyedListModificationStrategy extends SchemaAwareApplyOperation<ListSchemaNode> {
+final class ListModificationStrategy extends SchemaAwareApplyOperation<ListSchemaNode> {
     private static final NormalizedNodeContainerSupport<NodeIdentifier, UnkeyedListEntryNode> ITEM_SUPPORT =
             new NormalizedNodeContainerSupport<>(UnkeyedListEntryNode.class,
                     ImmutableUnkeyedListEntryNodeBuilder::create, ImmutableUnkeyedListEntryNodeBuilder::create);
@@ -32,7 +32,7 @@ final class UnkeyedListModificationStrategy extends SchemaAwareApplyOperation<Li
     private final DataNodeContainerModificationStrategy<ListSchemaNode> entryStrategy;
     private final UnkeyedListNode emptyNode;
 
-    UnkeyedListModificationStrategy(final ListSchemaNode schema, final DataTreeConfiguration treeConfig) {
+    ListModificationStrategy(final ListSchemaNode schema, final DataTreeConfiguration treeConfig) {
         entryStrategy = new DataNodeContainerModificationStrategy<>(ITEM_SUPPORT, schema, treeConfig);
         emptyNode = ImmutableNodes.listNode(schema.getQName());
     }
@@ -20,8 +20,8 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 
-class ListEntryModificationStrategy extends DataNodeContainerModificationStrategy<ListSchemaNode> {
-    private static final class EnforcingMandatory extends ListEntryModificationStrategy {
+class MapEntryModificationStrategy extends DataNodeContainerModificationStrategy<ListSchemaNode> {
+    private static final class EnforcingMandatory extends MapEntryModificationStrategy {
         private final MandatoryLeafEnforcer enforcer;
 
         EnforcingMandatory(final ListSchemaNode schemaNode, final DataTreeConfiguration treeConfig,
@@ -64,14 +64,14 @@ class ListEntryModificationStrategy extends DataNodeContainerModificationStrateg
             new NormalizedNodeContainerSupport<>(MapEntryNode.class, ImmutableMapEntryNodeBuilder::create,
                     ImmutableMapEntryNodeBuilder::create);
 
-    ListEntryModificationStrategy(final ListSchemaNode schema, final DataTreeConfiguration treeConfig) {
+    MapEntryModificationStrategy(final ListSchemaNode schema, final DataTreeConfiguration treeConfig) {
         super(SUPPORT, schema, treeConfig);
     }
 
-    static @NonNull ListEntryModificationStrategy of(final ListSchemaNode schema,
+    static @NonNull MapEntryModificationStrategy of(final ListSchemaNode schema,
             final DataTreeConfiguration treeConfig) {
         final Optional<MandatoryLeafEnforcer> enforcer = MandatoryLeafEnforcer.forContainer(schema, treeConfig);
         return enforcer.isPresent() ? new EnforcingMandatory(schema, treeConfig, enforcer.get())
-                : new ListEntryModificationStrategy(schema, treeConfig);
+                : new MapEntryModificationStrategy(schema, treeConfig);
     }
 }
index a956d653a90c400595c2b25c0587e2b66dc297bb..25f508c4be70f30e9cc677d7559c30170eb7e995 100644 (file)
@@ -37,7 +37,7 @@ final class MapModificationStrategy extends Invisible<ListSchemaNode> {
 
     private MapModificationStrategy(final NormalizedNodeContainerSupport<?, ?> support, final ListSchemaNode schema,
         final DataTreeConfiguration treeConfig, final MapNode emptyNode) {
-        super(support, treeConfig, ListEntryModificationStrategy.of(schema, treeConfig));
+        super(support, treeConfig, MapEntryModificationStrategy.of(schema, treeConfig));
         this.emptyNode = requireNonNull(emptyNode);
     }
 
index 066d1b89b7af54e3fdbe97f419c84d5daabbfd9a..ae8440ce84db1ec3d3dfed30a43f38fbe16f9080 100644 (file)
@@ -99,7 +99,7 @@ abstract class SchemaAwareApplyOperation<T extends WithStatus> extends Modificat
         final List<QName> keyDefinition = schemaNode.getKeyDefinition();
         final SchemaAwareApplyOperation<ListSchemaNode> op;
         if (keyDefinition == null || keyDefinition.isEmpty()) {
-            op = new UnkeyedListModificationStrategy(schemaNode, treeConfig);
+            op = new ListModificationStrategy(schemaNode, treeConfig);
         } else {
             op = MapModificationStrategy.of(schemaNode, treeConfig);
         }
index c38ea90f0e19c6ed8cd1aa3ecf17100d9d17c20d..ea3854b445bb6570fe499bbfaa0077bea2d90972 100644 (file)
@@ -30,6 +30,6 @@ public class MapEntryRootTest extends AbstractTestModelTest {
         final InMemoryDataTree imdt = (InMemoryDataTree) dataTree;
         final InMemoryDataTreeModification mod = imdt.takeSnapshot().newModification();
         final ModificationApplyOperation strategy = mod.getStrategy();
-        assertThat(strategy, instanceOf(ListEntryModificationStrategy.class));
+        assertThat(strategy, instanceOf(MapEntryModificationStrategy.class));
     }
 }