Hide leafSetEntryNode() 49/106449/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 12 Jun 2023 15:20:19 +0000 (17:20 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 12 Jun 2023 15:20:19 +0000 (17:20 +0200)
This is an internal utility method, annotate its return, hide it and
ditch its use of checkArgument() to streamline returns.

Change-Id: I5dff82831f67b5754806db8418afe12c3b774188
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
data/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/NormalizedNodeStreamWriterStack.java

index bf37255ed7719674e6b6fce0ff5810cca2a49a93..4f4cca462ed0c61c3363a5fe1cac7e35f985ff73 100644 (file)
@@ -216,16 +216,20 @@ public final class NormalizedNodeStreamWriterStack implements LeafrefResolver {
         return (LeafListSchemaNode) schema;
     }
 
-    public LeafListSchemaNode leafSetEntryNode(final QName qname) {
+    private @NonNull LeafListSchemaNode leafSetEntryNode(final QName qname) {
         final Object parent = getParent();
         if (parent instanceof LeafListSchemaNode leafList) {
             return leafList;
         }
-        checkArgument(parent instanceof DataNodeContainer, "Cannot lookup %s in parent %s", qname, parent);
-        final DataSchemaNode child = ((DataNodeContainer) parent).dataChildByName(qname);
-        checkArgument(child instanceof LeafListSchemaNode,
-            "Node %s is neither a leaf-list nor currently in a leaf-list", child);
-        return (LeafListSchemaNode) child;
+        if (parent instanceof DataNodeContainer parentContainer) {
+            final var child = parentContainer.dataChildByName(qname);
+            if (child instanceof LeafListSchemaNode childLeafList) {
+                return childLeafList;
+            }
+            throw new IllegalArgumentException(
+                "Node " + child + " is neither a leaf-list nor currently in a leaf-list");
+        }
+        throw new IllegalArgumentException("Cannot lookup " + qname + " in parent " + parent);
     }
 
     public void startLeafSetEntryNode(final NodeWithValue<?> name) {