Use primitive comparison for bit properties 85/103185/3
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 9 Nov 2022 23:40:15 +0000 (00:40 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 10 Nov 2022 00:16:10 +0000 (01:16 +0100)
Rather than boxing to go through Objects.equals(), use plain '==' on
booleans.

JIRA: MDSAL-744
Change-Id: I005ba52d8c68fb9eaf7d93e40adcf13ca159436f
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/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/JavaFileTemplate.java

index 8eee22e21131e1401c62fb642149494364ec9922..b9a2e53c4e94653bc377b164cd2756f0d9e1fe91 100644 (file)
@@ -47,6 +47,7 @@ import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject
 import org.opendaylight.mdsal.binding.model.api.Restrictions
 import org.opendaylight.mdsal.binding.model.api.Type
 import org.opendaylight.mdsal.binding.model.ri.TypeConstants
+import org.opendaylight.mdsal.binding.model.ri.Types
 import org.opendaylight.mdsal.binding.spec.naming.BindingMapping
 import org.opendaylight.yangtools.yang.common.Empty
 
@@ -574,10 +575,15 @@ class ClassTemplate extends BaseTemplate {
             @«OVERRIDE.importedName»
             public final boolean equals(«OBJECT.importedName» obj) {
                 return this == obj || obj instanceof «type.name» other
-                «FOR property : genTO.equalsIdentifiers»
-                    «val fieldName = property.fieldName»
-                        && «property.importedUtilClass».equals(«fieldName», other.«fieldName»)«
-                »«ENDFOR»;
+                    «FOR property : genTO.equalsIdentifiers»
+                        «val fieldName = property.fieldName»
+                        «val type = property.returnType»
+                        «IF type.equals(Types.primitiveBooleanType)»
+                            && «fieldName» == other.«fieldName»«
+                        »«ELSE»
+                            && «type.importedUtilClass».equals(«fieldName», other.«fieldName»)«
+                        »«ENDIF»«
+                    »«ENDFOR»;
             }
         «ENDIF»
     '''
index 45728d2cd8de719232f2fecf535dba1064d973f8..58cfafd6d5d2894e6f8229b2e232370cbb95968b 100644 (file)
@@ -272,7 +272,18 @@ class JavaFileTemplate {
      * @return Imported class name
      */
     final String importedUtilClass(final GeneratedProperty property) {
-        return importedName(property.getReturnType().getName().indexOf('[') != -1 ? JU_ARRAYS : JU_OBJECTS);
+        return importedUtilClass(property.getReturnType());
+    }
+
+    /**
+     * Return imported name of java.util class, whose hashCode/equals methods we want to invoke for a type. Returns
+     * {@link Arrays} if the type is an array, {@link Objects} otherwise.
+     *
+     * @param returnType A property return Type
+     * @return Imported class name
+     */
+    final String importedUtilClass(final Type returnType) {
+        return importedName(returnType.getName().indexOf('[') != -1 ? JU_ARRAYS : JU_OBJECTS);
     }
 
     final String generatedAnnotation() {