Merge "Fix equals and add hashcode to generated abstract module."
authorEd Warnicke <eaw@cisco.com>
Sat, 30 Nov 2013 16:32:32 +0000 (16:32 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Sat, 30 Nov 2013 16:32:32 +0000 (16:32 +0000)
14 files changed:
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/Field.java
opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/module_abs_template_new.ftl
opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/module_stub_template.ftl
opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGeneratorTest.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModule.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModuleFactory.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModuleStub.txt [new file with mode: 0644]
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModule.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleFactory.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleStub.txt [new file with mode: 0644]
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleUtil.java [new file with mode: 0644]
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModule.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModuleFactory.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModuleStub.txt [new file with mode: 0644]

index 7351822db9d8096f46dbce588872c34a6c744448..d0646f467a50416a71bb7d5f5c0c42cdfd343abf 100644 (file)
@@ -55,6 +55,11 @@ package ${packageName};
         dependencyResolver.validateDependency(${field.dependency.sie.fullyQualifiedName}.class, ${field.name}, ${field.name}JmxAttribute);
         </#if>
     </#list>
+        customValidation();
+    }
+
+    protected void customValidation(){
+
     }
 
     // caches of resolved dependencies
@@ -110,7 +115,7 @@ package ${packageName};
 
     public boolean canReuseInstance(${typeDeclaration.name} oldModule){
         // allow reusing of old instance if no parameters was changed
-        return equals(oldModule);
+        return isSame(oldModule);
     }
 
     public ${instanceType} reuseInstance(${instanceType} oldInstance){
@@ -120,34 +125,50 @@ package ${packageName};
 
     public abstract ${instanceType} createInstance();
 
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-        if (obj == null)
-            return false;
-        if (getClass() != obj.getClass())
-            return false;
-        ${typeDeclaration.name} other = (${typeDeclaration.name}) obj;
-
-
+    public boolean isSame(${typeDeclaration.name} other) {
+        if (other == null) {
+            throw new IllegalArgumentException("Parameter 'other' is null");
+        }
         <#list moduleFields as field>
         <#if field.dependent==true>
         if (${field.name}Dependency == null) {
             if (other.${field.name}Dependency != null)
                 return false;
-        } else if (!${field.name}Dependency.equals(other.${field.name}Dependency))
+        } else if (!${field.name}Dependency.equals(other.${field.name}Dependency)) {
             return false;
+        }
         <#else>
         if (${field.name} == null) {
-            if (other.${field.name} != null)
+            if (other.${field.name} != null) {
                 return false;
-        } else if (!${field.name}.equals(other.${field.name}))
+            }
+        } else if
+            <#if field.array == false>
+                (${field.name}.equals(other.${field.name}) == false)
+            <#else>
+                (java.util.Arrays.equals(${field.name},other.${field.name}) == false)
+            </#if>
+                 {
             return false;
+        }
         </#if>
         </#list>
 
         return true;
     }
 
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        ${typeDeclaration.name} that = (${typeDeclaration.name}) o;
+
+        return identifier.equals(that.identifier);
+    }
+
+    @Override
+    public int hashCode() {
+        return identifier.hashCode();
+    }
 }
index 23dce9321e3e10ca8d3ba4015e0c3fc2244233b2..2db505e54effb00cc9df5381e2ad95bf5e155312 100644 (file)
@@ -2,20 +2,20 @@
 package ${packageName};
 
 <@javadocD object=javadoc/>
-<@typeDeclarationD object=typeDeclaration/>
-{
+<@typeDeclarationD object=typeDeclaration/> {
 
     public ${typeDeclaration.name}(${moduleNameType} identifier, ${dependencyResolverType} dependencyResolver) {
         super(identifier, dependencyResolver);
     }
 
-    public ${typeDeclaration.name}(${moduleNameType} identifier, ${dependencyResolverType} dependencyResolver, ${typeDeclaration.name} oldModule, ${instanceType} oldInstance) {
+    public ${typeDeclaration.name}(${moduleNameType} identifier, ${dependencyResolverType} dependencyResolver,
+            ${typeDeclaration.name} oldModule, ${instanceType} oldInstance) {
+
         super(identifier, dependencyResolver, oldModule, oldInstance);
     }
 
     @Override
-    public void validate(){
-        super.validate();
+    protected void customValidation(){
         // Add custom validation for module attributes here.
     }
 
index 556abad7af2b9b80f4623cca42c4411f7191e974..0d6ec3cccbeedf872bbd61c8649f6c66cf743a63 100644 (file)
@@ -584,7 +584,7 @@ public class JMXGeneratorTest extends AbstractGeneratorTest {
         assertContains(reqIfc, PackageTranslatorTest.EXPECTED_PACKAGE_PREFIX
                 + ".threads.ThreadFactoryServiceInterface");
 
-        assertEquals("Incorrenct number of generated methods", 24,
+        assertEquals("Incorrenct number of generated methods", 27,
                 visitor.methods.size());
         assertEquals("Incorrenct number of generated method descriptions", 3,
                 visitor.methodDescriptions.size());
index 76df839665558ebc7a937d8d59f456f7c509d138..1122c1ffa46a16078623850314bb4cee3fd4aef0 100644 (file)
@@ -1,38 +1,23 @@
-/**
- * Generated file
-
- * Generated from: yang module name: config-test-impl  yang module local name: impl-dep
- * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
- * Generated at: Fri Sep 27 13:02:28 CEST 2013
- *
- * Do not modify this file unless it is present under src/main directory
- */
 package org.opendaylight.controller.config.yang.test.impl;
 
-
 /**
 *
 */
-public final class DepTestImplModule
-        extends
-        org.opendaylight.controller.config.yang.test.impl.AbstractDepTestImplModule {
+public final class DepTestImplModule extends org.opendaylight.controller.config.yang.test.impl.AbstractDepTestImplModule
+ {
 
-    public DepTestImplModule(
-            org.opendaylight.controller.config.api.ModuleIdentifier name,
-            org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
-        super(name, dependencyResolver);
+    public DepTestImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+        super(identifier, dependencyResolver);
     }
 
-    public DepTestImplModule(
-            org.opendaylight.controller.config.api.ModuleIdentifier name,
-            org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+    public DepTestImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
             DepTestImplModule oldModule, java.lang.AutoCloseable oldInstance) {
-        super(name, dependencyResolver, oldModule, oldInstance);
+
+        super(identifier, dependencyResolver, oldModule, oldInstance);
     }
 
     @Override
-    public void validate() {
-        super.validate();
+    protected void customValidation(){
         // Add custom validation for module attributes here.
     }
 
@@ -44,5 +29,4 @@ public final class DepTestImplModule
             }
         };
     }
-
 }
index b07cf40f821a5131a6f2a70bcdbddce6f93c2451..4152736768ca9ce12d089cb1fb039a536b712c47 100644 (file)
@@ -1,19 +1,10 @@
-/**
- * Generated file
-
- * Generated from: yang module name: config-test-impl  yang module local name: impl-dep
- * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
- * Generated at: Fri Sep 27 13:02:28 CEST 2013
- *
- * Do not modify this file unless it is present under src/main directory
- */
 package org.opendaylight.controller.config.yang.test.impl;
 
 /**
 *
 */
-public class DepTestImplModuleFactory
-        extends
-        org.opendaylight.controller.config.yang.test.impl.AbstractDepTestImplModuleFactory {
+public class DepTestImplModuleFactory extends org.opendaylight.controller.config.yang.test.impl.AbstractDepTestImplModuleFactory
+{
+
 
 }
diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModuleStub.txt b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModuleStub.txt
new file mode 100644 (file)
index 0000000..80c1e54
--- /dev/null
@@ -0,0 +1,5 @@
+        return new AutoCloseable() {
+            @Override
+            public void close() throws Exception {
+            }
+        };
index ae86d42d8ebd18458aa69f80d47024bbbdd4c131..7e1848dd6a7f20f6692d5dc5f5cfefd49b587190 100644 (file)
-/**
- * Generated file
-
- * Generated from: yang module name: config-test-impl  yang module local name: impl-netconf
- * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
- * Generated at: Fri Sep 27 13:02:28 CEST 2013
- *
- * Do not modify this file unless it is present under src/main directory
- */
 package org.opendaylight.controller.config.yang.test.impl;
 
-
-import com.google.common.collect.Lists;
-
-import java.util.List;
-
 /**
 *
 */
-public final class NetconfTestImplModule
-        extends
-        org.opendaylight.controller.config.yang.test.impl.AbstractNetconfTestImplModule {
+public final class NetconfTestImplModule extends org.opendaylight.controller.config.yang.test.impl.AbstractNetconfTestImplModule
+ {
 
-    public NetconfTestImplModule(
-            org.opendaylight.controller.config.api.ModuleIdentifier name,
-            org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
-        super(name, dependencyResolver);
+    public NetconfTestImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+        super(identifier, dependencyResolver);
     }
 
-    public NetconfTestImplModule(
-            org.opendaylight.controller.config.api.ModuleIdentifier name,
-            org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+    public NetconfTestImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
             NetconfTestImplModule oldModule, java.lang.AutoCloseable oldInstance) {
-        super(name, dependencyResolver, oldModule, oldInstance);
+
+        super(identifier, dependencyResolver, oldModule, oldInstance);
     }
 
     @Override
-    public void validate() {
-        super.validate();
+    protected void customValidation(){
         // Add custom validation for module attributes here.
     }
 
     @Override
     public java.lang.AutoCloseable createInstance() {
-        return registerRuntimeBeans();
+        return NetconfTestImplModuleUtil.registerRuntimeBeans(this);
     }
-
-    private NetconfTestImplRuntimeRegistration registerRuntimeBeans() {
-        NetconfTestImplRuntimeRegistration reg = getRootRuntimeBeanRegistratorWrapper().register(new NetconfTestImplRuntimeMXBean() {
-
-            @Override
-            public Long getCreatedSessions() {
-                return getSimpleLong();
-            }
-
-            @Override
-            public Asdf getAsdf() {
-                final Asdf asdf = new Asdf();
-                asdf.setSimpleString("asdf");
-                return asdf;
-            }
-
-            @Override
-            public String noArg(final String arg1) {
-                return arg1.toUpperCase();
-            }
-
-        });
-
-        for (int i = 0; i < getSimpleShort(); i++) {
-            final int finalI = i;
-
-            reg.register(new InnerRunningDataAdditionalRuntimeMXBean() {
-                @Override
-                public Integer getSimpleInt3() {
-                    return getSimpleTest();
-                }
-
-                @Override
-                public Deep4 getDeep4() {
-                    final Deep4 d = new Deep4();
-                    d.setBoool(false);
-                    return d;
-                }
-
-                @Override
-                public String getSimpleString() {
-                    return Integer.toString(finalI);
-                }
-
-                @Override
-                public void noArgInner() {
-                }
-            });
-
-            InnerRunningDataRuntimeRegistration innerReg = reg.register(new InnerRunningDataRuntimeMXBean() {
-                @Override
-                public Integer getSimpleInt3() {
-                    return finalI;
-                }
-
-                @Override
-                public Deep2 getDeep2() {
-                    return new Deep2();
-                }
-            });
-
-            for (int j = 0; j < getSimpleShort(); j++) {
-                final int finalJ = j;
-                innerReg.register(new InnerInnerRunningDataRuntimeMXBean() {
-                    @Override
-                    public List<NotStateBean> getNotStateBean() {
-                        NotStateBean b1 = new NotStateBean();
-                        b1.setElement("not state");
-                        return Lists.newArrayList(b1);
-                    }
-
-                    @Override
-                    public Integer getSimpleInt3() {
-                        return finalJ;
-                    }
-
-                    @Override
-                    public Deep3 getDeep3() {
-                        return new Deep3();
-                    }
-
-                    @Override
-                    public List<String> getListOfStrings() {
-                        return Lists.newArrayList("l1", "l2");
-                    }
-
-                    @Override
-                    public List<RetValList> listOutput() {
-                        return Lists.newArrayList(new RetValList());
-                    }
-
-                    @Override
-                    public Boolean noArgInnerInner(Integer integer, Boolean aBoolean) {
-                        return aBoolean;
-                    }
-
-                    @Override
-                    public RetValContainer containerOutput() {
-                        return new RetValContainer();
-                    }
-
-                    @Override
-                    public List<String> leafListOutput() {
-                        return Lists.newArrayList("1", "2");
-                    }
-                });
-            }
-        }
-
-        return reg;
-    }
-
 }
index e99c64dd3b473674b62e619eaba59d704cf80ffa..7cab5288680b9f2cfe454d3630c1e92f3b29d3bc 100644 (file)
@@ -1,19 +1,10 @@
-/**
- * Generated file
-
- * Generated from: yang module name: config-test-impl  yang module local name: impl-netconf
- * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
- * Generated at: Fri Sep 27 13:02:28 CEST 2013
- *
- * Do not modify this file unless it is present under src/main directory
- */
 package org.opendaylight.controller.config.yang.test.impl;
 
 /**
 *
 */
-public class NetconfTestImplModuleFactory
-        extends
-        org.opendaylight.controller.config.yang.test.impl.AbstractNetconfTestImplModuleFactory {
+public class NetconfTestImplModuleFactory extends org.opendaylight.controller.config.yang.test.impl.AbstractNetconfTestImplModuleFactory
+{
+
 
 }
diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleStub.txt b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleStub.txt
new file mode 100644 (file)
index 0000000..6515412
--- /dev/null
@@ -0,0 +1 @@
+return NetconfTestImplModuleUtil.registerRuntimeBeans(this);
diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleUtil.java b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleUtil.java
new file mode 100644 (file)
index 0000000..58943c9
--- /dev/null
@@ -0,0 +1,126 @@
+/**
+ * @author Tomas Olvecky
+ *
+ * 11 2013
+ *
+ * Copyright (c) 2013 by Cisco Systems, Inc.
+ * All rights reserved.
+ */
+package org.opendaylight.controller.config.yang.test.impl;
+
+import com.google.common.collect.Lists;
+
+import java.util.List;
+
+public class NetconfTestImplModuleUtil {
+    static NetconfTestImplRuntimeRegistration registerRuntimeBeans(final NetconfTestImplModule module) {
+        NetconfTestImplRuntimeRegistration reg = module.getRootRuntimeBeanRegistratorWrapper().register(new NetconfTestImplRuntimeMXBean() {
+
+            @Override
+            public Long getCreatedSessions() {
+                return module.getSimpleLong();
+            }
+
+            @Override
+            public Asdf getAsdf() {
+                final Asdf asdf = new Asdf();
+                asdf.setSimpleString("asdf");
+                return asdf;
+            }
+
+            @Override
+            public String noArg(final String arg1) {
+                return arg1.toUpperCase();
+            }
+
+        });
+
+        for (int i = 0; i < module.getSimpleShort(); i++) {
+            final int finalI = i;
+
+            reg.register(new InnerRunningDataAdditionalRuntimeMXBean() {
+                @Override
+                public Integer getSimpleInt3() {
+                    return module.getSimpleTest();
+                }
+
+                @Override
+                public Deep4 getDeep4() {
+                    final Deep4 d = new Deep4();
+                    d.setBoool(false);
+                    return d;
+                }
+
+                @Override
+                public String getSimpleString() {
+                    return Integer.toString(finalI);
+                }
+
+                @Override
+                public void noArgInner() {
+                }
+            });
+
+            InnerRunningDataRuntimeRegistration innerReg = reg.register(new InnerRunningDataRuntimeMXBean() {
+                @Override
+                public Integer getSimpleInt3() {
+                    return finalI;
+                }
+
+                @Override
+                public Deep2 getDeep2() {
+                    return new Deep2();
+                }
+            });
+
+            for (int j = 0; j < module.getSimpleShort(); j++) {
+                final int finalJ = j;
+                innerReg.register(new InnerInnerRunningDataRuntimeMXBean() {
+                    @Override
+                    public List<NotStateBean> getNotStateBean() {
+                        NotStateBean b1 = new NotStateBean();
+                        b1.setElement("not state");
+                        return Lists.newArrayList(b1);
+                    }
+
+                    @Override
+                    public Integer getSimpleInt3() {
+                        return finalJ;
+                    }
+
+                    @Override
+                    public Deep3 getDeep3() {
+                        return new Deep3();
+                    }
+
+                    @Override
+                    public List<String> getListOfStrings() {
+                        return Lists.newArrayList("l1", "l2");
+                    }
+
+                    @Override
+                    public List<RetValList> listOutput() {
+                        return Lists.newArrayList(new RetValList());
+                    }
+
+                    @Override
+                    public Boolean noArgInnerInner(Integer integer, Boolean aBoolean) {
+                        return aBoolean;
+                    }
+
+                    @Override
+                    public RetValContainer containerOutput() {
+                        return new RetValContainer();
+                    }
+
+                    @Override
+                    public List<String> leafListOutput() {
+                        return Lists.newArrayList("1", "2");
+                    }
+                });
+            }
+        }
+
+        return reg;
+    }
+}
index dfd9ebc021bfa62fef45dc4fb28e5dfc5678b2b3..52a71620bf0062f929e2496dac32d094f66d7157 100644 (file)
@@ -1,38 +1,23 @@
-/**
- * Generated file
-
- * Generated from: yang module name: config-test-impl  yang module local name: impl
- * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
- * Generated at: Fri Sep 27 13:02:28 CEST 2013
- *
- * Do not modify this file unless it is present under src/main directory
- */
 package org.opendaylight.controller.config.yang.test.impl;
 
-
 /**
 *
 */
-public final class TestImplModule
-        extends
-        org.opendaylight.controller.config.yang.test.impl.AbstractTestImplModule {
+public final class TestImplModule extends org.opendaylight.controller.config.yang.test.impl.AbstractTestImplModule
+ {
 
-    public TestImplModule(
-            org.opendaylight.controller.config.api.ModuleIdentifier name,
-            org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
-        super(name, dependencyResolver);
+    public TestImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+        super(identifier, dependencyResolver);
     }
 
-    public TestImplModule(
-            org.opendaylight.controller.config.api.ModuleIdentifier name,
-            org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+    public TestImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
             TestImplModule oldModule, java.lang.AutoCloseable oldInstance) {
-        super(name, dependencyResolver, oldModule, oldInstance);
+
+        super(identifier, dependencyResolver, oldModule, oldInstance);
     }
 
     @Override
-    public void validate() {
-        super.validate();
+    protected void customValidation(){
         // Add custom validation for module attributes here.
     }
 
@@ -44,5 +29,4 @@ public final class TestImplModule
             }
         };
     }
-
 }
index 1e86c83655eda9ab864b8892f512fdf66030bb69..ce9aa92b64ea0f4c61911b0f969c71ed048bac21 100644 (file)
@@ -1,19 +1,10 @@
-/**
- * Generated file
-
- * Generated from: yang module name: config-test-impl  yang module local name: impl
- * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
- * Generated at: Fri Sep 27 13:02:28 CEST 2013
- *
- * Do not modify this file unless it is present under src/main directory
- */
 package org.opendaylight.controller.config.yang.test.impl;
 
 /**
 *
 */
-public class TestImplModuleFactory
-        extends
-        org.opendaylight.controller.config.yang.test.impl.AbstractTestImplModuleFactory {
+public class TestImplModuleFactory extends org.opendaylight.controller.config.yang.test.impl.AbstractTestImplModuleFactory
+{
+
 
 }
diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModuleStub.txt b/opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModuleStub.txt
new file mode 100644 (file)
index 0000000..80c1e54
--- /dev/null
@@ -0,0 +1,5 @@
+        return new AutoCloseable() {
+            @Override
+            public void close() throws Exception {
+            }
+        };