Use Objects.equals() 11/27511/1
authorRobert Varga <rovarga@cisco.com>
Sun, 27 Sep 2015 16:55:01 +0000 (18:55 +0200)
committerRobert Varga <rovarga@cisco.com>
Sun, 27 Sep 2015 17:32:54 +0000 (19:32 +0200)
This simplifies implementations of equals() method.

Change-Id: Ib58c7417607f85224ab6d452dab2a8aac604c055
Signed-off-by: Robert Varga <rovarga@cisco.com>
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/LazyDataObject.java
binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/AbstractBaseType.java
binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AbstractGeneratedTypeBuilder.java
binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AbstractTypeMember.java
binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AbstractTypeMemberBuilder.java
binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AnnotationTypeBuilderImpl.java
binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/ConstantImpl.java
binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/EnumerationBuilderImpl.java
binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/MethodParameterImpl.java
binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/MethodSignatureBuilderImpl.java
binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/MethodSignatureImpl.java

index 40f4ccf0edd962222c45ee310c284665de68cb76..1e891c70deb25f194f7dc0dd98f9f0804f4badce 100644 (file)
@@ -205,20 +205,6 @@ class LazyDataObject<D extends DataObject> implements InvocationHandler, Augment
             return false;
         }
         final LazyDataObject<?> other = (LazyDataObject<?>) obj;
-        if (context == null) {
-            if (other.context != null) {
-                return false;
-            }
-        } else if (!context.equals(other.context)) {
-            return false;
-        }
-        if (data == null) {
-            if (other.data != null) {
-                return false;
-            }
-        } else if (!data.equals(other.data)) {
-            return false;
-        }
-        return true;
+        return Objects.equals(context, other.context) && Objects.equals(data, other.data);
     }
 }
index 76e4dd80cf96b3cff34254242052e27699cca855..0f33815408b4ed312e2922ceb3818699a430b49f 100644 (file)
@@ -55,7 +55,7 @@ public class AbstractBaseType implements Type {
      * @param name
      *            string with the name for this <code>Type</code>
      */
-    protected AbstractBaseType(String pkName, String name) {
+    protected AbstractBaseType(final String pkName, final String name) {
         if (pkName == null) {
             throw new IllegalArgumentException("Package Name for Generated Type cannot be null!");
         }
@@ -76,7 +76,7 @@ public class AbstractBaseType implements Type {
     }
 
     @Override
-    public boolean equals(Object obj) {
+    public boolean equals(final Object obj) {
         if (this == obj) {
             return true;
         }
@@ -87,21 +87,7 @@ public class AbstractBaseType implements Type {
             return false;
         }
         Type other = (Type) obj;
-        if (name == null) {
-            if (other.getName() != null) {
-                return false;
-            }
-        } else if (!name.equals(other.getName())) {
-            return false;
-        }
-        if (packageName == null) {
-            if (other.getPackageName() != null) {
-                return false;
-            }
-        } else if (!packageName.equals(other.getPackageName())) {
-            return false;
-        }
-        return true;
+        return Objects.equals(name, other.getName()) && Objects.equals(packageName, other.getPackageName());
     }
 
     @Override
index 4ace539cc401b87c0cc651dc67086d7a6e3b544c..e4fc107a98d9446212776d6f1c4ba77c6ccbdc49 100644 (file)
@@ -227,21 +227,7 @@ abstract class AbstractGeneratedTypeBuilder<T extends GeneratedTypeBuilderBase<T
             return false;
         }
         AbstractGeneratedTypeBuilder<?> other = (AbstractGeneratedTypeBuilder<?>) obj;
-        if (getName() == null) {
-            if (other.getName() != null) {
-                return false;
-            }
-        } else if (!getName().equals(other.getName())) {
-            return false;
-        }
-        if (getPackageName() == null) {
-            if (other.getPackageName() != null) {
-                return false;
-            }
-        } else if (!getPackageName().equals(other.getPackageName())) {
-            return false;
-        }
-        return true;
+        return Objects.equals(getName(), other.getName()) && Objects.equals(getPackageName(), other.getPackageName());
     }
 
     public Type getParent() {
index 86b53400de407e6ce4637f630239315feb516d70..0cb81701ef50b6b47c8aa079090809cd0ddde797 100644 (file)
@@ -100,21 +100,7 @@ abstract class AbstractTypeMember implements TypeMember {
             return false;
         }
         AbstractTypeMember other = (AbstractTypeMember) obj;
-        if (getName() == null) {
-            if (other.getName() != null) {
-                return false;
-            }
-        } else if (!getName().equals(other.getName())) {
-            return false;
-        }
-        if (getReturnType() == null) {
-            if (other.getReturnType() != null) {
-                return false;
-            }
-        } else if (!getReturnType().equals(other.getReturnType())) {
-            return false;
-        }
-        return true;
+        return Objects.equals(getName(), other.getName()) && Objects.equals(getReturnType(), other.getReturnType());
     }
 
     @Override
index e53a11e3a1196216cdf15cc053481581d29befce..58451825d885a180750029eb9295823f13bb8cc7 100644 (file)
@@ -142,21 +142,7 @@ abstract class AbstractTypeMemberBuilder<T extends TypeMemberBuilder<T>> impleme
             return false;
         }
         AbstractTypeMemberBuilder<?> other = (AbstractTypeMemberBuilder<?>) obj;
-        if (getName() == null) {
-            if (other.getName() != null) {
-                return false;
-            }
-        } else if (!getName().equals(other.getName())) {
-            return false;
-        }
-        if (getReturnType() == null) {
-            if (other.getReturnType() != null) {
-                return false;
-            }
-        } else if (!getReturnType().equals(other.getReturnType())) {
-            return false;
-        }
-        return true;
+        return Objects.equals(getName(), other.getName()) && Objects.equals(getReturnType(), other.getReturnType());
     }
 
     @Override
index cd2a3e469532267831ff1b1e63320a03b0f17563..04c2b8840134ab1b01ba864e4bc4021d6a01e926 100644 (file)
@@ -95,21 +95,7 @@ final class AnnotationTypeBuilderImpl extends AbstractBaseType implements Annota
             return false;
         }
         AnnotationTypeBuilderImpl other = (AnnotationTypeBuilderImpl) obj;
-        if (name == null) {
-            if (other.name != null) {
-                return false;
-            }
-        } else if (!name.equals(other.name)) {
-            return false;
-        }
-        if (packageName == null) {
-            if (other.packageName != null) {
-                return false;
-            }
-        } else if (!packageName.equals(other.packageName)) {
-            return false;
-        }
-        return true;
+        return Objects.equals(name, other.name) && Objects.equals(packageName, other.packageName);
     }
 
     @Override
@@ -226,21 +212,7 @@ final class AnnotationTypeBuilderImpl extends AbstractBaseType implements Annota
                 return false;
             }
             AnnotationTypeImpl other = (AnnotationTypeImpl) obj;
-            if (name == null) {
-                if (other.name != null) {
-                    return false;
-                }
-            } else if (!name.equals(other.name)) {
-                return false;
-            }
-            if (packageName == null) {
-                if (other.packageName != null) {
-                    return false;
-                }
-            } else if (!packageName.equals(other.packageName)) {
-                return false;
-            }
-            return true;
+            return Objects.equals(name, other.name) && Objects.equals(packageName, other.packageName);
         }
 
         @Override
@@ -314,14 +286,7 @@ final class AnnotationTypeBuilderImpl extends AbstractBaseType implements Annota
                 return false;
             }
             ParameterImpl other = (ParameterImpl) obj;
-            if (name == null) {
-                if (other.name != null) {
-                    return false;
-                }
-            } else if (!name.equals(other.name)) {
-                return false;
-            }
-            return true;
+            return Objects.equals(name, other.name);
         }
 
         @Override
index 081ea21b5a3c9c9284efd405695c96ab5879850c..920d4eb9ac6182f24f33700d1a6abef01f4f6b4f 100644 (file)
@@ -59,7 +59,7 @@ final class ConstantImpl implements Constant {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see java.lang.Object#hashCode()
      */
     @Override
@@ -73,11 +73,11 @@ final class ConstantImpl implements Constant {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see java.lang.Object#equals(java.lang.Object)
      */
     @Override
-    public boolean equals(Object obj) {
+    public boolean equals(final Object obj) {
         if (this == obj) {
             return true;
         }
@@ -88,28 +88,7 @@ final class ConstantImpl implements Constant {
             return false;
         }
         ConstantImpl other = (ConstantImpl) obj;
-        if (name == null) {
-            if (other.name != null) {
-                return false;
-            }
-        } else if (!name.equals(other.name)) {
-            return false;
-        }
-        if (type == null) {
-            if (other.type != null) {
-                return false;
-            }
-        } else if (!type.equals(other.type)) {
-            return false;
-        }
-        if (value == null) {
-            if (other.value != null) {
-                return false;
-            }
-        } else if (!value.equals(other.value)) {
-            return false;
-        }
-        return true;
+        return Objects.equals(name, other.name) && Objects.equals(type, other.type) && Objects.equals(value, other.value);
     }
 
     @Override
index 968253868cc7c6e9c1a61adc31f2624fa46e125d..284e7e11f63b606b23d6f4770f003bfb1bed7118 100644 (file)
@@ -60,7 +60,7 @@ public final class EnumerationBuilderImpl extends AbstractBaseType implements En
     }
 
     @Override
-    public void setDescription(String description) {
+    public void setDescription(final String description) {
         this.description = description;
 
     }
@@ -187,21 +187,7 @@ public final class EnumerationBuilderImpl extends AbstractBaseType implements En
                 return false;
             }
             EnumPairImpl other = (EnumPairImpl) obj;
-            if (name == null) {
-                if (other.name != null) {
-                    return false;
-                }
-            } else if (!name.equals(other.name)) {
-                return false;
-            }
-            if (value == null) {
-                if (other.value != null) {
-                    return false;
-                }
-            } else if (!value.equals(other.value)) {
-                return false;
-            }
-            return true;
+            return Objects.equals(name, other.name) && Objects.equals(value, other.value);
         }
 
         /*
index 923d1934d9e40c2deb2027abbb363df654f027a2..4ca84acadb29e83003e69312ffe89483778608d4 100644 (file)
@@ -8,8 +8,8 @@
 package org.opendaylight.yangtools.binding.generator.util.generated.type.builder;
 
 import java.util.Objects;
-import org.opendaylight.yangtools.sal.binding.model.api.Type;
 import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature.Parameter;
+import org.opendaylight.yangtools.sal.binding.model.api.Type;
 
 final class MethodParameterImpl implements Parameter {
 
@@ -34,7 +34,7 @@ final class MethodParameterImpl implements Parameter {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see java.lang.Object#hashCode()
      */
     @Override
@@ -48,11 +48,11 @@ final class MethodParameterImpl implements Parameter {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see java.lang.Object#equals(java.lang.Object)
      */
     @Override
-    public boolean equals(Object obj) {
+    public boolean equals(final Object obj) {
         if (this == obj) {
             return true;
         }
@@ -63,26 +63,12 @@ final class MethodParameterImpl implements Parameter {
             return false;
         }
         MethodParameterImpl other = (MethodParameterImpl) obj;
-        if (name == null) {
-            if (other.name != null) {
-                return false;
-            }
-        } else if (!name.equals(other.name)) {
-            return false;
-        }
-        if (type == null) {
-            if (other.type != null) {
-                return false;
-            }
-        } else if (!type.equals(other.type)) {
-            return false;
-        }
-        return true;
+        return Objects.equals(name, other.name) && Objects.equals(type, other.type);
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see java.lang.Object#toString()
      */
     @Override
index 6aa6208d71aceb5db0e6578039694e49809e3c2e..ca711fd9d679ce18b98b79eb61e85addd34c24d9 100644 (file)
@@ -73,25 +73,13 @@ final class MethodSignatureBuilderImpl extends AbstractTypeMemberBuilder<MethodS
             return false;
         }
         MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
-        if (getName() == null) {
-            if (other.getName() != null) {
-                return false;
-            }
-        } else if (!getName().equals(other.getName())) {
+        if (!Objects.equals(getName(), other.getName())) {
             return false;
         }
-        if (parameters == null) {
-            if (other.parameters != null) {
-                return false;
-            }
-        } else if (!parameters.equals(other.parameters)) {
+        if (!Objects.equals(parameters, other.parameters)) {
             return false;
         }
-        if (getReturnType() == null) {
-            if (other.getReturnType() != null) {
-                return false;
-            }
-        } else if (!getReturnType().equals(other.getReturnType())) {
+        if (!Objects.equals(getReturnType(), other.getReturnType())) {
             return false;
         }
         return true;
index 06dda6e12811b697fd0f144646a9ea33650002ad..2b3c5fc339bd17239f8bc5ce47ec20aaabe9e46b 100644 (file)
@@ -61,25 +61,13 @@ class MethodSignatureImpl extends AbstractTypeMember implements MethodSignature
             return false;
         }
         MethodSignatureImpl other = (MethodSignatureImpl) obj;
-        if (getName() == null) {
-            if (other.getName() != null) {
-                return false;
-            }
-        } else if (!getName().equals(other.getName())) {
+        if (!Objects.equals(getName(), other.getName())) {
             return false;
         }
-        if (params == null) {
-            if (other.params != null) {
-                return false;
-            }
-        } else if (!params.equals(other.params)) {
+        if (!Objects.equals(params, other.params)) {
             return false;
         }
-        if (getReturnType() == null) {
-            if (other.getReturnType() != null) {
-                return false;
-            }
-        } else if (!getReturnType().equals(other.getReturnType())) {
+        if (!Objects.equals(getReturnType(), other.getReturnType())) {
             return false;
         }
         return true;