Seven more Equals/HashCode/StringBuilder replacements 54/354/1
authorEd Warnicke <eaw@cisco.com>
Wed, 15 May 2013 16:31:48 +0000 (11:31 -0500)
committerEd Warnicke <eaw@cisco.com>
Wed, 15 May 2013 16:31:48 +0000 (11:31 -0500)
I'm intentionally breaking these up into small groups so they can
be reasonably reviewed, rather than one giant group that can't.
Contributes to fixing bug 20.

Fifth set.

Change-Id: I905753ad4b1c2f6947fae8c447de27e091aa7519
Signed-off-by: Ed Warnicke <eaw@cisco.com>
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/authorization/Resource.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/authorization/ResourceGroup.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Actions.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Bandwidth.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Buffers.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Capabilities.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Config.java

index ef8744b551bb2aea811f0b92ce4b77e2248942b0..9cf7420d1b01c7622d7d0576ccb0493456891001 100644 (file)
@@ -11,9 +11,6 @@ package org.opendaylight.controller.sal.authorization;
 
 import java.io.Serializable;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-
 /**
  * It represents the elementary resource along with
  * the access privilege associated to it
@@ -38,12 +35,32 @@ public class Resource implements Serializable {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = 1;
+        result = prime * result
+                + ((privilege == null) ? 0 : privilege.hashCode());
+        result = prime * result
+                + ((resource == null) ? 0 : resource.hashCode());
+        return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        return EqualsBuilder.reflectionEquals(this, obj);
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        Resource other = (Resource) obj;
+        if (privilege != other.privilege)
+            return false;
+        if (resource == null) {
+            if (other.resource != null)
+                return false;
+        } else if (!resource.equals(other.resource))
+            return false;
+        return true;
     }
 
     @Override
index 61e44dda4b424e7dd8c63a12af07da81962ce3ca..5a2a17f6cf45b18604ce305d2e11fba276b18e33 100644 (file)
@@ -11,9 +11,6 @@ package org.opendaylight.controller.sal.authorization;
 
 import java.io.Serializable;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-
 /**
  * Represents a group of resources along with the privilege associated to it
  *
@@ -48,12 +45,32 @@ public class ResourceGroup implements Serializable {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = 1;
+        result = prime * result
+                + ((groupName == null) ? 0 : groupName.hashCode());
+        result = prime * result
+                + ((privilege == null) ? 0 : privilege.hashCode());
+        return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        return EqualsBuilder.reflectionEquals(this, obj);
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        ResourceGroup other = (ResourceGroup) obj;
+        if (groupName == null) {
+            if (other.groupName != null)
+                return false;
+        } else if (!groupName.equals(other.groupName))
+            return false;
+        if (privilege != other.privilege)
+            return false;
+        return true;
     }
 
     @Override
index 6fb38a3a90279a898786e5c1ed1f088ad6cd5488..3f81d0c4c5524150bf386158e8d22921f57249f6 100644 (file)
@@ -12,9 +12,6 @@ package org.opendaylight.controller.sal.core;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-
 /**
  * @file   Actions.java
  *
@@ -83,12 +80,24 @@ public class Actions extends Property {
     
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + actionsValue;
+        return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        return EqualsBuilder.reflectionEquals(this, obj);
+        if (this == obj)
+            return true;
+        if (!super.equals(obj))
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        Actions other = (Actions) obj;
+        if (actionsValue != other.actionsValue)
+            return false;
+        return true;
     }
 
     @Override
index 32f661ca5ff29a7a14d284068692d45d83638e46..fa5cc10827d5847140dd21ec72b24138b23b901f 100644 (file)
@@ -12,9 +12,6 @@ package org.opendaylight.controller.sal.core;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-
 /**
  * @file   BandWidth.java
  *
@@ -84,12 +81,25 @@ public class Bandwidth extends Property {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result
+                + (int) (bandwidthValue ^ (bandwidthValue >>> 32));
+        return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        return EqualsBuilder.reflectionEquals(this, obj);
+        if (this == obj)
+            return true;
+        if (!super.equals(obj))
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        Bandwidth other = (Bandwidth) obj;
+        if (bandwidthValue != other.bandwidthValue)
+            return false;
+        return true;
     }
 
     @Override
index 91f647d45b2b1c7588355bd2880d7e58f4ce7330..991ed688f2eda4d630d63f15b965983ca07acc97 100644 (file)
@@ -12,9 +12,6 @@ package org.opendaylight.controller.sal.core;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-
 /**
  * @file   Buffers.java
  *
@@ -59,12 +56,24 @@ public class Buffers extends Property {
     
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + buffersValue;
+        return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        return EqualsBuilder.reflectionEquals(this, obj);
+        if (this == obj)
+            return true;
+        if (!super.equals(obj))
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        Buffers other = (Buffers) obj;
+        if (buffersValue != other.buffersValue)
+            return false;
+        return true;
     }
 
     @Override
index d4c8cd1b56e71fd92a428db7a290f99dea1d5c00..a41a0e22904482050bbcfe95c4338c2acb0dc520 100644 (file)
@@ -12,9 +12,6 @@ package org.opendaylight.controller.sal.core;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-
 /**
  * @file   Capabilities.java
  *
@@ -76,12 +73,24 @@ public class Capabilities extends Property {
     
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + capabilitiesValue;
+        return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        return EqualsBuilder.reflectionEquals(this, obj);
+        if (this == obj)
+            return true;
+        if (!super.equals(obj))
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        Capabilities other = (Capabilities) obj;
+        if (capabilitiesValue != other.capabilitiesValue)
+            return false;
+        return true;
     }
 
     @Override
index f8a48997f827e06a5e554344d8b3339e17b444c6..c547c2bb455bd89f9d26b0c1483d9d6b3d8cc8d2 100644 (file)
@@ -11,9 +11,6 @@ package org.opendaylight.controller.sal.core;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-
 /**
  * The class represents Admin Config status
  * 
@@ -53,12 +50,24 @@ public class Config extends Property {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + configValue;
+        return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        return EqualsBuilder.reflectionEquals(this, obj);
+        if (this == obj)
+            return true;
+        if (!super.equals(obj))
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        Config other = (Config) obj;
+        if (configValue != other.configValue)
+            return false;
+        return true;
     }
 
     @Override