Use Objects.equals() in yang-model-util 09/27509/2
authorRobert Varga <rovarga@cisco.com>
Sun, 27 Sep 2015 16:25:33 +0000 (18:25 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 28 Sep 2015 07:26:37 +0000 (07:26 +0000)
Simplifies implementations of equals() considerably.

Change-Id: I1d86308156abdca36ad9c770621a82e852ad56ab
Signed-off-by: Robert Varga <rovarga@cisco.com>
15 files changed:
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/AbstractSignedInteger.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/AbstractUnsignedInteger.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BinaryType.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BitImpl.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BitsType.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Decimal64.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/EnumerationType.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Leafref.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/LengthConstraintImpl.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/ModuleImportImpl.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/MustDefinitionImpl.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/PatternConstraintImpl.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RangeConstraintImpl.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RevisionAwareXPathImpl.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/StringType.java

index b9234e9d903e0530dd5a94ee08d8d0b0fcff9f61..d255e4f966b2ab8d583602c0206b4972fe0c4b37 100644 (file)
@@ -131,39 +131,19 @@ abstract class AbstractSignedInteger implements IntegerTypeDefinition {
             return false;
         }
         AbstractSignedInteger other = (AbstractSignedInteger) obj;
-        if (description == null) {
-            if (other.description != null) {
-                return false;
-            }
-        } else if (!description.equals(other.description)) {
+        if (!Objects.equals(description, other.description)) {
             return false;
         }
-        if (name == null) {
-            if (other.name != null) {
-                return false;
-            }
-        } else if (!name.equals(other.name)) {
+        if (!Objects.equals(name, other.name)) {
             return false;
         }
-        if (path == null) {
-            if (other.path != null) {
-                return false;
-            }
-        } else if (!path.equals(other.path)) {
+        if (!Objects.equals(path, other.path)) {
             return false;
         }
-        if (rangeStatements == null) {
-            if (other.rangeStatements != null) {
-                return false;
-            }
-        } else if (!rangeStatements.equals(other.rangeStatements)) {
+        if (!Objects.equals(rangeStatements, other.rangeStatements)) {
             return false;
         }
-        if (units == null) {
-            if (other.units != null) {
-                return false;
-            }
-        } else if (!units.equals(other.units)) {
+        if (!Objects.equals(units, other.units)) {
             return false;
         }
         return true;
index d791c8870819184e2169f90c7b5343a5cecb1b80..89225876f1403359a4437ef1db14407e488a711f 100644 (file)
@@ -131,39 +131,19 @@ abstract class AbstractUnsignedInteger implements UnsignedIntegerTypeDefinition
             return false;
         }
         AbstractUnsignedInteger other = (AbstractUnsignedInteger) obj;
-        if (description == null) {
-            if (other.description != null) {
-                return false;
-            }
-        } else if (!description.equals(other.description)) {
+        if (!Objects.equals(description, other.description)) {
             return false;
         }
-        if (name == null) {
-            if (other.name != null) {
-                return false;
-            }
-        } else if (!name.equals(other.name)) {
+        if (!Objects.equals(name, other.name)) {
             return false;
         }
-        if (path == null) {
-            if (other.path != null) {
-                return false;
-            }
-        } else if (!path.equals(other.path)) {
+        if (!Objects.equals(path, other.path)) {
             return false;
         }
-        if (rangeStatements == null) {
-            if (other.rangeStatements != null) {
-                return false;
-            }
-        } else if (!rangeStatements.equals(other.rangeStatements)) {
+        if (!Objects.equals(rangeStatements, other.rangeStatements)) {
             return false;
         }
-        if (units == null) {
-            if (other.units != null) {
-                return false;
-            }
-        } else if (!units.equals(other.units)) {
+        if (!Objects.equals(units, other.units)) {
             return false;
         }
         return true;
index 18f416d117ebdd884c58d2c29be38ef544c0efc1..061a0c646149898d48049d7357a4c713b3eaae67 100644 (file)
@@ -169,21 +169,7 @@ public final class BinaryType implements BinaryTypeDefinition {
             return false;
         }
         BinaryType other = (BinaryType) obj;
-        if (bytes == null) {
-            if (other.bytes != null) {
-                return false;
-            }
-        } else if (!bytes.equals(other.bytes)) {
-            return false;
-        }
-        if (lengthConstraints == null) {
-            if (other.lengthConstraints != null) {
-                return false;
-            }
-        } else if (!lengthConstraints.equals(other.lengthConstraints)) {
-            return false;
-        }
-        return true;
+        return Objects.equals(bytes, other.bytes) && Objects.equals(lengthConstraints, other.lengthConstraints);
     }
 
     @Override
index 00762d6156fa114197fbc47ddb52fecc7e882dd9..7ef116e4af4887625e7030f731d0a07b4964ed80 100644 (file)
@@ -104,21 +104,7 @@ public final class BitImpl implements BitsTypeDefinition.Bit, Immutable {
             return false;
         }
         Bit other = (Bit) obj;
-        if (qname == null) {
-            if (other.getQName() != null) {
-                return false;
-            }
-        } else if (!qname.equals(other.getQName())) {
-            return false;
-        }
-        if (schemaPath == null) {
-            if (other.getPath() != null) {
-                return false;
-            }
-        } else if (!schemaPath.equals(other.getPath())) {
-            return false;
-        }
-        return true;
+        return Objects.equals(qname, other.getQName()) && Objects.equals(schemaPath, other.getPath());
     }
 
     @Override
index 85b214d32d569332e4ba1dc046aff0f1edd6cb36..43b44442af21d4b5bd86791475324bc7bef30085 100644 (file)
@@ -166,21 +166,7 @@ public final class BitsType implements BitsTypeDefinition {
             return false;
         }
         BitsType other = (BitsType) obj;
-        if (bits == null) {
-            if (other.bits != null) {
-                return false;
-            }
-        } else if (!bits.equals(other.bits)) {
-            return false;
-        }
-        if (path == null) {
-            if (other.path != null) {
-                return false;
-            }
-        } else if (!path.equals(other.path)) {
-            return false;
-        }
-        return true;
+        return Objects.equals(bits, other.bits) && Objects.equals(path, other.path);
     }
 
     @Override
index 89f1e1a1960ad4b705d6cef2d7741783e91ecf7e..def34eb999b8f2c6017e10483f3bee378b3bdcb1 100644 (file)
@@ -164,14 +164,7 @@ public final class Decimal64 implements DecimalTypeDefinition {
             return false;
         }
         Decimal64 other = (Decimal64) obj;
-        if (path == null) {
-            if (other.path != null) {
-                return false;
-            }
-        } else if (!path.equals(other.path)) {
-            return false;
-        }
-        return true;
+        return Objects.equals(path, other.path);
     }
 
     @Override
index df1ff71bd14f872116758fe52b016f43df287e44..36e589ea1116e92a72bb346afc1e68624317816a 100644 (file)
@@ -179,25 +179,13 @@ public final class EnumerationType implements EnumTypeDefinition {
             return false;
         }
         EnumerationType other = (EnumerationType) obj;
-        if (defaultEnum == null) {
-            if (other.defaultEnum != null) {
-                return false;
-            }
-        } else if (!defaultEnum.equals(other.defaultEnum)) {
+        if (!Objects.equals(defaultEnum, other.defaultEnum)) {
             return false;
         }
-        if (enums == null) {
-            if (other.enums != null) {
-                return false;
-            }
-        } else if (!enums.equals(other.enums)) {
+        if (!Objects.equals(enums, other.enums)) {
             return false;
         }
-        if (path == null) {
-            if (other.path != null) {
-                return false;
-            }
-        } else if (!path.equals(other.path)) {
+        if (!Objects.equals(path, other.path)) {
             return false;
         }
         return true;
index 0024490decf4a229c84baa5788edeaab811ebcba..a51b513d9e8a708c1d12b83c681923c7392411c0 100644 (file)
@@ -117,14 +117,7 @@ public final class Leafref implements LeafrefTypeDefinition {
             return false;
         }
         Leafref other = (Leafref) obj;
-        if (xpath == null) {
-            if (other.xpath != null) {
-                return false;
-            }
-        } else if (!xpath.equals(other.xpath)) {
-            return false;
-        }
-        return true;
+        return Objects.equals(xpath, other.xpath);
     }
 
     @Override
index 6472d269f24b11cd81197ee381a9c785fc416708..ca75b0c6158a7c554aa09dc6f71d19f46934f90b 100644 (file)
@@ -103,25 +103,13 @@ final class LengthConstraintImpl implements LengthConstraint, Immutable {
             return false;
         }
         final LengthConstraintImpl other = (LengthConstraintImpl) obj;
-        if (description == null) {
-            if (other.description != null) {
-                return false;
-            }
-        } else if (!description.equals(other.description)) {
+        if (!Objects.equals(description, other.description)) {
             return false;
         }
-        if (errorAppTag == null) {
-            if (other.errorAppTag != null) {
-                return false;
-            }
-        } else if (!errorAppTag.equals(other.errorAppTag)) {
+        if (!Objects.equals(errorAppTag, other.errorAppTag)) {
             return false;
         }
-        if (errorMessage == null) {
-            if (other.errorMessage != null) {
-                return false;
-            }
-        } else if (!errorMessage.equals(other.errorMessage)) {
+        if (!Objects.equals(errorMessage, other.errorMessage)) {
             return false;
         }
         if (max != other.max) {
@@ -130,11 +118,7 @@ final class LengthConstraintImpl implements LengthConstraint, Immutable {
         if (min != other.min) {
             return false;
         }
-        if (reference == null) {
-            if (other.reference != null) {
-                return false;
-            }
-        } else if (!reference.equals(other.reference)) {
+        if (!Objects.equals(reference, other.reference)) {
             return false;
         }
         return true;
index 6ffb7286261ce84a51c6ad362b29f8b8942824be..376511663e411b8a66114dacc1bae68661ba191f 100644 (file)
@@ -59,25 +59,13 @@ public final class ModuleImportImpl implements ModuleImport {
             return false;
         }
         ModuleImport other = (ModuleImport) obj;
-        if (getModuleName() == null) {
-            if (other.getModuleName() != null) {
-                return false;
-            }
-        } else if (!getModuleName().equals(other.getModuleName())) {
+        if (!Objects.equals(getModuleName(), other.getModuleName())) {
             return false;
         }
-        if (getRevision() == null) {
-            if (other.getRevision() != null) {
-                return false;
-            }
-        } else if (!getRevision().equals(other.getRevision())) {
+        if (!Objects.equals(getRevision(), other.getRevision())) {
             return false;
         }
-        if (getPrefix() == null) {
-            if (other.getPrefix() != null) {
-                return false;
-            }
-        } else if (!getPrefix().equals(other.getPrefix())) {
+        if (!Objects.equals(getPrefix(), other.getPrefix())) {
             return false;
         }
         return true;
index 5e2949efbd9178f603e568f15398c1a5850ddf72..d361fa98c643bdcb73643c52349b35d23a9bd423 100644 (file)
@@ -102,25 +102,13 @@ public final class MustDefinitionImpl implements MustDefinition {
             return false;
         }
         final MustDefinitionImpl other = (MustDefinitionImpl) obj;
-        if (mustStr == null) {
-            if (other.mustStr != null) {
-                return false;
-            }
-        } else if (!mustStr.equals(other.mustStr)) {
+        if (!Objects.equals(mustStr, other.mustStr)) {
             return false;
         }
-        if (description == null) {
-            if (other.description != null) {
-                return false;
-            }
-        } else if (!description.equals(other.description)) {
+        if (!Objects.equals(description, other.description)) {
             return false;
         }
-        if (reference == null) {
-            if (other.reference != null) {
-                return false;
-            }
-        } else if (!reference.equals(other.reference)) {
+        if (!Objects.equals(reference, other.reference)) {
             return false;
         }
         return true;
index d6701648a5f9a909de9d38272f53e2ba954b9939..eecc2a01f5295f45bc14ed966c9b61740a94a50a 100644 (file)
@@ -96,39 +96,19 @@ final class PatternConstraintImpl implements PatternConstraint, Immutable {
             return false;
         }
         final PatternConstraintImpl other = (PatternConstraintImpl) obj;
-        if (description == null) {
-            if (other.description != null) {
-                return false;
-            }
-        } else if (!description.equals(other.description)) {
+        if (!Objects.equals(description, other.description)) {
             return false;
         }
-        if (errorAppTag == null) {
-            if (other.errorAppTag != null) {
-                return false;
-            }
-        } else if (!errorAppTag.equals(other.errorAppTag)) {
+        if (!Objects.equals(errorAppTag, other.errorAppTag)) {
             return false;
         }
-        if (errorMessage == null) {
-            if (other.errorMessage != null) {
-                return false;
-            }
-        } else if (!errorMessage.equals(other.errorMessage)) {
+        if (!Objects.equals(errorMessage, other.errorMessage)) {
             return false;
         }
-        if (reference == null) {
-            if (other.reference != null) {
-                return false;
-            }
-        } else if (!reference.equals(other.reference)) {
+        if (!Objects.equals(reference, other.reference)) {
             return false;
         }
-        if (regex == null) {
-            if (other.regex != null) {
-                return false;
-            }
-        } else if (!regex.equals(other.regex)) {
+        if (!Objects.equals(regex, other.regex)) {
             return false;
         }
         return true;
index 6f9a3f18a941ccb3eaa98bea83fea92acf530057..f8db0870528abaa1cd85efdf79da137b9f359d3d 100644 (file)
@@ -103,32 +103,16 @@ final class RangeConstraintImpl implements RangeConstraint, Immutable {
             return false;
         }
         final RangeConstraintImpl other = (RangeConstraintImpl) obj;
-        if (description == null) {
-            if (other.description != null) {
-                return false;
-            }
-        } else if (!description.equals(other.description)) {
+        if (!Objects.equals(description, other.description)) {
             return false;
         }
-        if (max == null) {
-            if (other.max != null) {
-                return false;
-            }
-        } else if (!max.equals(other.max)) {
+        if (!Objects.equals(max, other.max)) {
             return false;
         }
-        if (min == null) {
-            if (other.min != null) {
-                return false;
-            }
-        } else if (!min.equals(other.min)) {
+        if (!Objects.equals(min, other.min)) {
             return false;
         }
-        if (reference == null) {
-            if (other.reference != null) {
-                return false;
-            }
-        } else if (!reference.equals(other.reference)) {
+        if (!Objects.equals(reference, other.reference)) {
             return false;
         }
         return true;
index 18ba81332ceb2fdbfeac8a2f9d332e44178fb5b8..6d407f7bb08845111f88aaf11471825bf8685cae 100644 (file)
@@ -55,17 +55,7 @@ public class RevisionAwareXPathImpl implements RevisionAwareXPath {
             return false;
         }
         RevisionAwareXPathImpl other = (RevisionAwareXPathImpl) obj;
-        if (xpath == null) {
-            if (other.xpath != null) {
-                return false;
-            }
-        } else if (!xpath.equals(other.xpath)) {
-            return false;
-        }
-        if (absolute != other.absolute) {
-            return false;
-        }
-        return true;
+        return absolute == other.absolute && Objects.equals(xpath, other.xpath);
     }
 
     @Override
index 434676dd0a20ae43e1dbb00268193eee4ab28dd0..79f27fcc0f1dfeaae88e46f13d7fccfc6bd26c6c 100644 (file)
@@ -184,21 +184,7 @@ public final class StringType implements StringTypeDefinition, Immutable {
             return false;
         }
         StringType other = (StringType) obj;
-        if (lengthStatements == null) {
-            if (other.lengthStatements != null) {
-                return false;
-            }
-        } else if (!lengthStatements.equals(other.lengthStatements)) {
-            return false;
-        }
-        if (patterns == null) {
-            if (other.patterns != null) {
-                return false;
-            }
-        } else if (!patterns.equals(other.patterns)) {
-            return false;
-        }
-        return true;
+        return Objects.equals(lengthStatements, other.lengthStatements) && Objects.equals(patterns, other.patterns);
     }
 
     @Override