Reduce bindingEquals() verbosity 90/104490/3
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 22 Feb 2023 19:03:31 +0000 (20:03 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 22 Feb 2023 19:14:38 +0000 (20:14 +0100)
We are generating a cascade of checks, all of which must pass for us to
return 'true'. Rather that generating a number of 'if/return' blocks,
use a single expression to achieve the same result.

Change-Id: I13c7abe4ef81d2a2822b6b4d0456f277dd5ce288
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/InterfaceTemplate.xtend

index 51ac7be063c7f6dece585b7e1681223c15fc3bdc..e2b4215b4b9553efa34ea6748071fc1612e1a890 100644 (file)
@@ -331,16 +331,12 @@ class InterfaceTemplate extends BaseTemplate {
                 if (thisObj == obj) {
                     return true;
                 }
-                final «type.fullyQualifiedName» other = «CODEHELPERS.importedName».checkCast(«type.fullyQualifiedName».class, obj);
-                if (other == null) {
-                    return false;
-                }
-                «FOR property : ByTypeMemberComparator.sort(typeAnalysis.value)»
-                    if (!«property.importedUtilClass».equals(thisObj.«property.getterName»(), other.«property.getterName»())) {
-                        return false;
-                    }
-                «ENDFOR»
-                return «IF augmentable»thisObj.augmentations().equals(other.augmentations())«ELSE»true«ENDIF»;
+                final var other = «CODEHELPERS.importedName».checkCast(«type.fullyQualifiedName».class, obj);
+                return other != null
+                    «FOR property : ByTypeMemberComparator.sort(typeAnalysis.value)»
+                        && «property.importedUtilClass».equals(thisObj.«property.getterName»(), other.«property.getterName»())
+                    «ENDFOR»
+                    «IF augmentable»&& thisObj.augmentations().equals(other.augmentations())«ENDIF»;
             }
         «ENDIF»
     '''