Simplify element count processing, remove Optional 39/106239/10
authorŠimon Ukuš <simon.ukus@pantheon.tech>
Thu, 8 Jun 2023 11:38:05 +0000 (13:38 +0200)
committerIvan Hrasko <ivan.hrasko@pantheon.tech>
Wed, 12 Jul 2023 11:50:53 +0000 (13:50 +0200)
Modified how ElementCountConstraint is handled during leaf-list node
processing by taking advantage of the method that depends
on the presence of the Optional value.

JIRA: NETCONF-998
Change-Id: Icde783e392beb3972397d7b4400780a1a89c8154
Signed-off-by: Šimon Ukuš <simon.ukus@pantheon.tech>
restconf/restconf-openapi/src/main/java/org/opendaylight/restconf/openapi/impl/DefinitionGenerator.java

index b5b3e6fe5bb2ba780c86ab164b5ac3809667903a..bd1f8437d0f5be2043438c40a53010ee48c95d9b 100644 (file)
@@ -516,7 +516,7 @@ public class DefinitionGenerator {
 
         final ObjectNode itemsVal = JsonNodeFactory.instance.objectNode();
         final Optional<ElementCountConstraint> optConstraint = listNode.getElementCountConstraint();
-        processElementCount(optConstraint, props);
+        optConstraint.ifPresent(elementCountConstraint -> processElementCount(elementCountConstraint, props));
 
         processTypeDef(listNode.getType(), listNode, itemsVal, stack, definitions, definitionNames);
         props.set(ITEMS_KEY, itemsVal);
@@ -526,17 +526,14 @@ public class DefinitionGenerator {
         return props;
     }
 
-    private static void processElementCount(final Optional<ElementCountConstraint> constraint, final ObjectNode props) {
-        if (constraint.isPresent()) {
-            final ElementCountConstraint constr = constraint.orElseThrow();
-            final Integer minElements = constr.getMinElements();
-            if (minElements != null) {
-                props.put(MIN_ITEMS, minElements);
-            }
-            final Integer maxElements = constr.getMaxElements();
-            if (maxElements != null) {
-                props.put(MAX_ITEMS, maxElements);
-            }
+    private static void processElementCount(final ElementCountConstraint constraint, final ObjectNode props) {
+        final Integer minElements = constraint.getMinElements();
+        if (minElements != null) {
+            props.put(MIN_ITEMS, minElements);
+        }
+        final Integer maxElements = constraint.getMaxElements();
+        if (maxElements != null) {
+            props.put(MAX_ITEMS, maxElements);
         }
     }