Use ImmutableSet in YangModuleInfo 98/85298/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 21 Oct 2019 15:23:01 +0000 (17:23 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 21 Oct 2019 17:48:09 +0000 (19:48 +0200)
This allows us to bind to a concrete implementation, improving
performance very slightly.

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

binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/mdsal/binding/yang/unified/doc/generator/maven/YangModuleInfoCompilationTest.java
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/YangModuleInfoTemplate.xtend

index 82eac6d041d35ed4822394921f4acab9f533c673..d7ca340d0d7a5ba67ec0249c674a5f7cbb93ff00 100644 (file)
@@ -14,6 +14,7 @@ import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.lang.reflect.Method;
@@ -103,7 +104,7 @@ public class YangModuleInfoCompilationTest {
         Object yangModuleInfo = getInstance.invoke(null);
 
         // Test getImportedModules method
-        Method getImportedModules = assertContainsMethod(yangModuleInfoClass, Set.class, "getImportedModules");
+        Method getImportedModules = assertContainsMethod(yangModuleInfoClass, ImmutableSet.class, "getImportedModules");
         Object importedModules = getImportedModules.invoke(yangModuleInfo);
         assertTrue(importedModules instanceof Set);
 
index 643e4cdc0ad3070f5105a218e5645659838e1bca..7c1b4eafbfd6db5fd76cc789efbebc7f99be431a 100644 (file)
@@ -15,7 +15,6 @@ import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.MODULE_I
 
 import com.google.common.base.Preconditions
 import com.google.common.collect.ImmutableSet
-import java.util.Collections
 import java.util.Comparator
 import java.util.HashSet
 import java.util.LinkedHashMap
@@ -76,7 +75,7 @@ class YangModuleInfoTemplate {
                 private static final «QName.importedName» NAME = «QName.importedName».create("«module.namespace.toString»", «IF rev.present»"«rev.get.toString»", «ENDIF»"«module.name»").intern();
                 private static final «YangModuleInfo.importedName» INSTANCE = new «MODULE_INFO_CLASS_NAME»();
 
-                private final «Set.importedName»<«YangModuleInfo.importedName»> importedModules;
+                private final «ImmutableSet.importedName»<«YangModuleInfo.importedName»> importedModules;
 
                 public static «YangModuleInfo.importedName» getInstance() {
                     return INSTANCE;
@@ -147,7 +146,7 @@ class YangModuleInfoTemplate {
                 set.add(«submodule.name.className»Info.getInstance());
             «ENDFOR»
             «IF m.imports.empty && submodules.empty»
-                importedModules = «Collections.importedName».emptySet();
+                importedModules = «ImmutableSet.importedName».of();
             «ELSE»
                 importedModules = «ImmutableSet.importedName».copyOf(set);
             «ENDIF»
@@ -164,7 +163,7 @@ class YangModuleInfoTemplate {
         }
 
         @«Override.importedName»
-        public «Set.importedName»<«YangModuleInfo.importedName»> getImportedModules() {
+        public «ImmutableSet.importedName»<«YangModuleInfo.importedName»> getImportedModules() {
             return importedModules;
         }
         «generateSubInfo(submodules)»
@@ -286,13 +285,13 @@ class YangModuleInfoTemplate {
                     submodule.namespace.toString»", «IF rev.present»"«rev.get.toString»", «ENDIF»"«submodule.name»").intern();
                 private static final «YangModuleInfo.importedName» INSTANCE = new «className»Info();
 
-                private final «Set.importedName»<YangModuleInfo> importedModules;
+                private final «ImmutableSet.importedName»<YangModuleInfo> importedModules;
 
                 public static «YangModuleInfo.importedName» getInstance() {
                     return INSTANCE;
                 }
 
-                «classBody(submodule, className + "Info", Collections.emptySet
+                «classBody(submodule, className + "Info", ImmutableSet.of
             }
         «ENDFOR»
     '''