Eliminate putIfNonNull(ObjectNode, String, Number) 61/107261/8
authorIvan Hrasko <ivan.hrasko@pantheon.tech>
Fri, 4 Aug 2023 14:36:36 +0000 (16:36 +0200)
committerIvan Hrasko <ivan.hrasko@pantheon.tech>
Mon, 7 Aug 2023 09:10:42 +0000 (09:10 +0000)
Eliminate DefinitionGenerator#putIfNonNull(ObjectNode, String, Number)
method because:
- range type is always Integer
- com.google.common.collect.Range is designed to reject null values
- key is never null - we have passed it into the method

JIRA: NETCONF-1120
Change-Id: If5eed0da8b5cb461c024315bde0d286d7d1ab3ea
Signed-off-by: Ivan Hrasko <ivan.hrasko@pantheon.tech>
Signed-off-by: lubos-cicut <lubos.cicut@pantheon.tech>
restconf/restconf-openapi/src/main/java/org/opendaylight/restconf/openapi/impl/DefinitionGenerator.java

index 79c65940c61e0929f14ab5e1f6fdbfb06552ae81..67effacd098cd5605a148d05f12fd68fefd6af68 100644 (file)
@@ -762,8 +762,8 @@ public class DefinitionGenerator {
 
         type.getLengthConstraint().ifPresent(constraint -> {
             final Range<Integer> range = constraint.getAllowedRanges().span();
-            putIfNonNull(property, MIN_LENGTH_KEY, range.lowerEndpoint());
-            putIfNonNull(property, MAX_LENGTH_KEY, range.upperEndpoint());
+            property.put(MIN_LENGTH_KEY, range.lowerEndpoint());
+            property.put(MAX_LENGTH_KEY, range.upperEndpoint());
         });
 
         if (type.getPatternConstraints().iterator().hasNext()) {
@@ -899,22 +899,6 @@ public class DefinitionGenerator {
         return xml;
     }
 
-    private static void putIfNonNull(final ObjectNode property, final String key, final Number number) {
-        if (key != null && number != null) {
-            if (number instanceof Double doubleNum) {
-                property.put(key, doubleNum);
-            } else if (number instanceof Float floatNum) {
-                property.put(key, floatNum);
-            } else if (number instanceof Integer intNum) {
-                property.put(key, intNum);
-            } else if (number instanceof Short shortNum) {
-                property.put(key, shortNum);
-            } else if (number instanceof Long longNum) {
-                property.put(key, longNum);
-            }
-        }
-    }
-
     private static void setExampleValue(final ObjectNode property, final String value) {
         property.put(EXAMPLE_KEY, value);
     }