Five more Equals/HashCode/StringBuilder replacements 72/372/4
authorEd Warnicke <eaw@cisco.com>
Fri, 17 May 2013 15:12:09 +0000 (08:12 -0700)
committerGiovanni Meo <gmeo@cisco.com>
Thu, 23 May 2013 08:36:16 +0000 (10:36 +0200)
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.

Tenth set.

Change-Id: I62a1b9724ed235c6b406fbbf2a005606cfd9d87e
Signed-off-by: Ed Warnicke <eaw@cisco.com>
Signed-off-by: Giovanni Meo <gmeo@cisco.com>
opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/SpanConfig.java
opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/Subnet.java
opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/Switch.java
opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/SwitchConfig.java
opendaylight/usermanager/src/main/java/org/opendaylight/controller/usermanager/internal/UserConfig.java

index f701553811b6e15c191e9aac30aa5dcc61b4fd03..80ed20981961b56e21d397575ea09c2712190cdd 100644 (file)
@@ -14,15 +14,11 @@ import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
 import org.opendaylight.controller.sal.core.ConstructionException;
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.NodeConnector;
 import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
 import org.opendaylight.controller.sal.utils.GUIField;
-
-import org.opendaylight.controller.switchmanager.SpanConfig;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -69,12 +65,34 @@ public class SpanConfig implements Serializable {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((nodeId == null) ? 0 : nodeId.hashCode());
+        result = prime * result
+                + ((spanPort == null) ? 0 : spanPort.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;
+        SpanConfig other = (SpanConfig) obj;
+        if (nodeId == null) {
+            if (other.nodeId != null)
+                return false;
+        } else if (!nodeId.equals(other.nodeId))
+            return false;
+        if (spanPort == null) {
+            if (other.spanPort != null)
+                return false;
+        } else if (!spanPort.equals(other.spanPort))
+            return false;
+        return true;
     }
 
     public static ArrayList<String> getFieldsNames() {
index 551f0722db2e1fd30c3e9d61bc17a5577cd07616..e15303581f9ad32be958dd3971cd0cf92dc8d8bd 100644 (file)
@@ -15,13 +15,8 @@ import java.net.UnknownHostException;
 import java.util.HashSet;
 import java.util.Set;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
 import org.opendaylight.controller.sal.core.NodeConnector;
 
-import org.opendaylight.controller.switchmanager.Subnet;
-import org.opendaylight.controller.switchmanager.SubnetConfig;
-
 /**
  * The class describes subnet information including L3 address, vlan and set of
  * ports associated with the subnet.
@@ -179,33 +174,43 @@ public class Subnet implements Serializable {
         return this;
     }
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#hashCode()
-     */
     @Override
     public int hashCode() {
-        return new HashCodeBuilder().append(networkAddress).append(
-                subnetMaskLength).toHashCode();
+        final int prime = 31;
+        int result = 1;
+        result = prime * result
+                + ((networkAddress == null) ? 0 : networkAddress.hashCode());
+        result = prime * result
+                + ((nodeConnectors == null) ? 0 : nodeConnectors.hashCode());
+        result = prime * result + subnetMaskLength;
+        result = prime * result + vlan;
+        return result;
     }
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#equals(java.lang.Object)
-     */
     @Override
     public boolean equals(Object obj) {
-        if (this == obj) {
+        if (this == obj)
             return true;
-        }
-        if (obj == null) {
+        if (obj == null)
             return false;
-        }
-        if (obj.getClass() != getClass()) {
+        if (getClass() != obj.getClass())
             return false;
-        }
         Subnet other = (Subnet) obj;
-        // Check only equality for the key fields
-        return new EqualsBuilder().append(networkAddress, other.networkAddress)
-                .append(subnetMaskLength, other.subnetMaskLength).isEquals();
+        if (networkAddress == null) {
+            if (other.networkAddress != null)
+                return false;
+        } else if (!networkAddress.equals(other.networkAddress))
+            return false;
+        if (nodeConnectors == null) {
+            if (other.nodeConnectors != null)
+                return false;
+        } else if (!nodeConnectors.equals(other.nodeConnectors))
+            return false;
+        if (subnetMaskLength != other.subnetMaskLength)
+            return false;
+        if (vlan != other.vlan)
+            return false;
+        return true;
     }
 
     /* (non-Javadoc)
index afca30c3a1c89a9a1ce254e925e0cc33ae89b142..6ba78deaded8b817ee4fc382dc8560f1d3a74d10 100644 (file)
@@ -11,12 +11,11 @@ package org.opendaylight.controller.switchmanager;
 
 import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.NodeConnector;
@@ -125,12 +124,44 @@ public class Switch implements Serializable {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + Arrays.hashCode(dataLayerAddress);
+        result = prime * result + ((node == null) ? 0 : node.hashCode());
+        result = prime * result
+                + ((nodeConnectors == null) ? 0 : nodeConnectors.hashCode());
+        result = prime * result
+                + ((spanPorts == null) ? 0 : spanPorts.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;
+        Switch other = (Switch) obj;
+        if (!Arrays.equals(dataLayerAddress, other.dataLayerAddress))
+            return false;
+        if (node == null) {
+            if (other.node != null)
+                return false;
+        } else if (!node.equals(other.node))
+            return false;
+        if (nodeConnectors == null) {
+            if (other.nodeConnectors != null)
+                return false;
+        } else if (!nodeConnectors.equals(other.nodeConnectors))
+            return false;
+        if (spanPorts == null) {
+            if (other.spanPorts != null)
+                return false;
+        } else if (!spanPorts.equals(other.spanPorts))
+            return false;
+        return true;
     }
 
     @Override
index ffb8ec042c619e9f28485a76a56fb3143adcfeca..778310e07ff6a4d7879ed8e26e33cf7e9976901b 100644 (file)
@@ -11,9 +11,6 @@ package org.opendaylight.controller.switchmanager;
 
 import java.io.Serializable;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-
 /**
  * The class describes a switch configuration including node identifier, node
  * name, tier number and proactive/reactive mode.
@@ -59,11 +56,45 @@ public class SwitchConfig implements Serializable {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = 1;
+        result = prime * result
+                + ((description == null) ? 0 : description.hashCode());
+        result = prime * result + ((mode == null) ? 0 : mode.hashCode());
+        result = prime * result + ((nodeId == null) ? 0 : nodeId.hashCode());
+        result = prime * result + ((tier == null) ? 0 : tier.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;
+        SwitchConfig other = (SwitchConfig) obj;
+        if (description == null) {
+            if (other.description != null)
+                return false;
+        } else if (!description.equals(other.description))
+            return false;
+        if (mode == null) {
+            if (other.mode != null)
+                return false;
+        } else if (!mode.equals(other.mode))
+            return false;
+        if (nodeId == null) {
+            if (other.nodeId != null)
+                return false;
+        } else if (!nodeId.equals(other.nodeId))
+            return false;
+        if (tier == null) {
+            if (other.tier != null)
+                return false;
+        } else if (!tier.equals(other.tier))
+            return false;
+        return true;
     }
 }
index fd491fe880c36d928f2ca07eb52587d2355ba6c9..176af3a3e4d1d48ed9b8120f65b7bc5a6bca9ffb 100644 (file)
@@ -15,8 +15,6 @@ import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
 import org.opendaylight.controller.sal.authorization.AuthResultEnum;
 import org.opendaylight.controller.sal.utils.Status;
 import org.opendaylight.controller.sal.utils.StatusCode;
@@ -66,12 +64,40 @@ public class UserConfig implements Serializable {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = 1;
+        result = prime * result
+                + ((password == null) ? 0 : password.hashCode());
+        result = prime * result + ((roles == null) ? 0 : roles.hashCode());
+        result = prime * result + ((user == null) ? 0 : user.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;
+        UserConfig other = (UserConfig) obj;
+        if (password == null) {
+            if (other.password != null)
+                return false;
+        } else if (!password.equals(other.password))
+            return false;
+        if (roles == null) {
+            if (other.roles != null)
+                return false;
+        } else if (!roles.equals(other.roles))
+            return false;
+        if (user == null) {
+            if (other.user != null)
+                return false;
+        } else if (!user.equals(other.user))
+            return false;
+        return true;
     }
 
     @Override