Offload null value checking to CodeHelpers 04/81204/3
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 26 Mar 2019 19:34:36 +0000 (20:34 +0100)
committerRobert Varga <nite@hq.sk>
Wed, 27 Mar 2019 12:35:27 +0000 (12:35 +0000)
Since we are using a fixed string, we can easily offload the call
to a centralized place in CodeHelpers, thus providing some minor
class size improvements.

Change-Id: I25991e7020bafc535dab6731063e39e92de03d95
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/ClassTemplate.xtend
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/CodeHelpers.java

index 24f2972c625635ec1a53b900295f63cbd4821eeb..d7acf20b7d5bb96e57fd40ee38e58a97554ce3af 100644 (file)
@@ -22,7 +22,6 @@ import java.util.Base64;
 import java.util.Collections
 import java.util.List
 import java.util.Map
-import java.util.Objects
 import java.util.regex.Pattern
 import org.opendaylight.mdsal.binding.model.api.ConcreteType
 import org.opendaylight.mdsal.binding.model.api.Constant
@@ -224,7 +223,7 @@ class ClassTemplate extends BaseTemplate {
          * consequence of how this code is structured.
          */
         IF genTO.typedef && !allProperties.empty && allProperties.size == 1 && allProperties.get(0).name.equals("value")»
-            «Objects.importedName».requireNonNull(_value, "Supplied value may not be null");
+            «CodeHelpers.importedName».requireValue(_value);
             «genPatternEnforcer("_value")»
         «ENDIF»
 
index 774ee6cdebc81740ffdec6e4e3c1b9882b8498ad..a3fde03a2fe6632458e64ebc3e51ac96b71e69d3 100644 (file)
@@ -67,6 +67,16 @@ public final class CodeHelpers {
         return value;
     }
 
+    /**
+     * A shortcut for {@code Objects.requireNonNull(value, "Supplied value may not be null")}.
+     *
+     * @param value Value itself
+     * @throws NullPointerException if value is null
+     */
+    public static void requireValue(@Nullable final Object value) {
+        requireNonNull(value, "Supplied value may not be null");
+    }
+
     /**
      * Append a named value to a ToStringHelper. If the value is null, this method does nothing.
      *