Improve ImmutableMapEntryNodeBuilder identifier handling 43/95843/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 19 Apr 2021 19:12:42 +0000 (21:12 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 19 Apr 2021 19:14:01 +0000 (21:14 +0200)
We have duplicate decisions going on here, simplify them bye combining
the check-and-put operation.

Change-Id: Ib5dd56e49e3ac8248ddbded22ba0b71d227dc067
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableMapEntryNodeBuilder.java

index af8368f902280c940031ac2c2ae04655446bc442..44d6930e2cfdda30088fdf820d9cada6b9f08096 100644 (file)
@@ -43,7 +43,7 @@ public class ImmutableMapEntryNodeBuilder
     protected ImmutableMapEntryNodeBuilder(final ImmutableMapEntryNode node) {
         super(node);
         this.childrenQNamesToPaths = new LinkedHashMap<>();
-        fillQnames(node.body(), childrenQNamesToPaths);
+        fillQNames(node.body(), childrenQNamesToPaths);
     }
 
     public static @NonNull DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> create() {
@@ -64,38 +64,31 @@ public class ImmutableMapEntryNodeBuilder
         return new ImmutableMapEntryNodeBuilder((ImmutableMapEntryNode)node);
     }
 
-    private static void fillQnames(final Iterable<DataContainerChild> iterable, final Map<QName, PathArgument> out) {
-        for (final DataContainerChild childId : iterable) {
-            final PathArgument identifier = childId.getIdentifier();
-
-            // Augmentation nodes cannot be keys, and do not have to be present in childrenQNamesToPaths map
-            if (isAugment(identifier)) {
-                continue;
-            }
+    private static void fillQNames(final Iterable<DataContainerChild> iterable, final Map<QName, PathArgument> out) {
+        for (final DataContainerChild child : iterable) {
+            putQName(out, child);
+        }
+    }
 
-            out.put(childId.getNodeType(), identifier);
+    private static void putQName(final Map<QName, PathArgument> map, final DataContainerChild child) {
+        // Augmentation nodes cannot be keys, and do not have to be present in childrenQNamesToPaths map
+        final PathArgument identifier = child.getIdentifier();
+        if (!(identifier instanceof AugmentationIdentifier)) {
+            map.put(identifier.getNodeType(), identifier);
         }
     }
 
     @Override
     public DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> withValue(
             final Collection<DataContainerChild> withValue) {
-        fillQnames(withValue, childrenQNamesToPaths);
+        fillQNames(withValue, childrenQNamesToPaths);
         return super.withValue(withValue);
     }
 
-    private static boolean isAugment(final PathArgument identifier) {
-        return identifier instanceof AugmentationIdentifier;
-    }
-
     @Override
     public DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> withChild(
             final DataContainerChild child) {
-        // Augmentation nodes cannot be keys, and do not have to be present in childrenQNamesToPaths map
-        if (!isAugment(child.getIdentifier())) {
-            childrenQNamesToPaths.put(child.getNodeType(), child.getIdentifier());
-        }
-
+        putQName(childrenQNamesToPaths, child);
         return super.withChild(child);
     }