Optimize ClassTemplate.allProperties 91/84391/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 4 Sep 2019 11:46:14 +0000 (13:46 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 13 Sep 2019 14:24:04 +0000 (16:24 +0200)
This variable is guaranteed to be a List, declare it as such,
adding following benefits:
- eliminates ClassTemplate's reliance on IterableExtensions
- a few isEmpty() checks get be eliminated, as size() is now
  handled through List.size()

Change-Id: I14354dfef3a6b663c9a027353704127437d4344d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 425d13761fd76b0ca9691a4735977519e96adf45)

binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/ClassTemplate.xtend

index 337c7a7c8801e25f4dd90103d9fdda3daa10c87d..7ce8074a90b441c01fedccb5493a621aaf854893 100644 (file)
@@ -42,7 +42,7 @@ class ClassTemplate extends BaseTemplate {
     protected val List<GeneratedProperty> properties
     protected val List<GeneratedProperty> finalProperties
     protected val List<GeneratedProperty> parentProperties
-    protected val Iterable<GeneratedProperty> allProperties
+    protected val List<GeneratedProperty> allProperties
     protected val Restrictions restrictions
 
     /**
@@ -206,7 +206,7 @@ class ClassTemplate extends BaseTemplate {
     '''
 
     def protected allValuesConstructor() '''
-    «IF genTO.typedef && !allProperties.empty && allProperties.size == 1 && allProperties.get(0).name.equals("value")»
+    «IF genTO.typedef && allProperties.size == 1 && allProperties.get(0).name.equals("value")»
         @«ConstructorProperties.importedName»("value")
     «ENDIF»
     public «type.name»(«allProperties.asArgumentsDeclaration») {
@@ -221,14 +221,14 @@ class ClassTemplate extends BaseTemplate {
          * If we have patterns, we need to apply them to the value field. This is a sad
          * consequence of how this code is structured.
          */
-        IF genTO.typedef && !allProperties.empty && allProperties.size == 1 && allProperties.get(0).name.equals("value")»
+        IF genTO.typedef && allProperties.size == 1 && allProperties.get(0).name.equals("value")»
             «Objects.importedName».requireNonNull(_value, "Supplied value may not be null");
             «genPatternEnforcer("_value")»
         «ENDIF»
 
         «FOR p : properties»
             «IF p.returnType.importedName.contains("[]")»
-                «IF genTO.typedef && !allProperties.empty && allProperties.size == 1 && allProperties.get(0).name
+                «IF genTO.typedef && allProperties.size == 1 && allProperties.get(0).name
                 .equals("value")»
                 this.«p.fieldName» = «p.fieldName».clone();
                 «ELSE»