Merge "bug 1957 StackOverFlowError in YangParserImpl"
[yangtools.git] / code-generator / binding-generator-util / src / main / java / org / opendaylight / yangtools / binding / generator / util / AbstractBaseType.java
index 5707c78053b3635b8252554cc8e32f59a2b701cb..2c15ad8a36fc57737a761bc84580a9d0923da38d 100644 (file)
@@ -11,7 +11,7 @@ import org.opendaylight.yangtools.sal.binding.model.api.Type;
 
 /**
  * It is used only as ancestor for other <code>Type</code>s
- * 
+ *
  */
 public class AbstractBaseType implements Type {
 
@@ -47,7 +47,7 @@ public class AbstractBaseType implements Type {
     /**
      * Constructs the instance of this class with the concrete package name type
      * name.
-     * 
+     *
      * @param pkName
      *            string with the package name to which this <code>Type</code>
      *            belongs
@@ -55,6 +55,12 @@ public class AbstractBaseType implements Type {
      *            string with the name for this <code>Type</code>
      */
     protected AbstractBaseType(String pkName, String name) {
+        if (pkName == null) {
+            throw new IllegalArgumentException("Package Name for Generated Type cannot be null!");
+        }
+        if (name == null) {
+            throw new IllegalArgumentException("Name of Generated Type cannot be null!");
+        }
         this.packageName = pkName;
         this.name = name;
     }
@@ -70,23 +76,30 @@ public class AbstractBaseType implements Type {
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj)
+        if (this == obj) {
             return true;
-        if (obj == null)
+        }
+        if (obj == null) {
             return false;
-        if (getClass() != obj.getClass())
+        }
+        if (!(obj instanceof Type)) {
             return false;
+        }
         Type other = (Type) obj;
         if (name == null) {
-            if (other.getName() != null)
+            if (other.getName() != null) {
                 return false;
-        } else if (!name.equals(other.getName()))
+            }
+        } else if (!name.equals(other.getName())) {
             return false;
+        }
         if (packageName == null) {
-            if (other.getPackageName() != null)
+            if (other.getPackageName() != null) {
                 return false;
-        } else if (!packageName.equals(other.getPackageName()))
+            }
+        } else if (!packageName.equals(other.getPackageName())) {
             return false;
+        }
         return true;
     }