Five more Equals/HashCode/StringBuilder replacements 55/355/1
authorEd Warnicke <eaw@cisco.com>
Wed, 15 May 2013 16:36:18 +0000 (11:36 -0500)
committerEd Warnicke <eaw@cisco.com>
Wed, 15 May 2013 16:36:18 +0000 (11:36 -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.

Sixth set.

Change-Id: Iddab53b9e960a416c1416415daa6c00ebb1bfc96
Signed-off-by: Ed Warnicke <eaw@cisco.com>
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/ContainerFlow.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Description.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Edge.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Host.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Latency.java

index acb3e19..2a80bd6 100644 (file)
@@ -11,8 +11,6 @@ package org.opendaylight.controller.sal.core;
 
 import java.io.Serializable;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
 import org.opendaylight.controller.sal.action.Action;
 import org.opendaylight.controller.sal.action.SetDlType;
 import org.opendaylight.controller.sal.action.SetNwDst;
@@ -48,12 +46,27 @@ public class ContainerFlow implements Serializable {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((match == null) ? 0 : match.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;
+        ContainerFlow other = (ContainerFlow) obj;
+        if (match == null) {
+            if (other.match != null)
+                return false;
+        } else if (!match.equals(other.match))
+            return false;
+        return true;
     }
 
     @Override
index 4233dcb..4138aa6 100644 (file)
@@ -3,9 +3,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 the Name property of an element.
  */
@@ -39,12 +36,28 @@ public class Description extends Property {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result
+                + ((description == null) ? 0 : description.hashCode());
+        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;
+        Description other = (Description) obj;
+        if (description == null) {
+            if (other.description != null)
+                return false;
+        } else if (!description.equals(other.description))
+            return false;
+        return true;
     }
 
     @Override
index 162a4d4..c119eb7 100644 (file)
 package org.opendaylight.controller.sal.core;
 
 import java.io.Serializable;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.apache.commons.lang3.builder.EqualsBuilder;
 
-import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
 
 /**
  *
@@ -126,12 +124,39 @@ public class Edge implements Serializable {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = 1;
+        result = prime
+                * result
+                + ((headNodeConnector == null) ? 0 : headNodeConnector
+                        .hashCode());
+        result = prime
+                * result
+                + ((tailNodeConnector == null) ? 0 : tailNodeConnector
+                        .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;
+        Edge other = (Edge) obj;
+        if (headNodeConnector == null) {
+            if (other.headNodeConnector != null)
+                return false;
+        } else if (!headNodeConnector.equals(other.headNodeConnector))
+            return false;
+        if (tailNodeConnector == null) {
+            if (other.tailNodeConnector != null)
+                return false;
+        } else if (!tailNodeConnector.equals(other.tailNodeConnector))
+            return false;
+        return true;
     }
 
     @Override
index f549086..5003637 100644 (file)
@@ -17,9 +17,6 @@ import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
 import org.opendaylight.controller.sal.packet.address.DataLinkAddress;
 
 @XmlRootElement(name="host")
@@ -93,16 +90,41 @@ public class Host implements Serializable {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = 1;
+        result = prime
+                * result
+                + ((dataLayerAddress == null) ? 0 : dataLayerAddress.hashCode());
+        result = prime * result
+                + ((networkAddress == null) ? 0 : networkAddress.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;
+        Host other = (Host) obj;
+        if (dataLayerAddress == null) {
+            if (other.dataLayerAddress != null)
+                return false;
+        } else if (!dataLayerAddress.equals(other.dataLayerAddress))
+            return false;
+        if (networkAddress == null) {
+            if (other.networkAddress != null)
+                return false;
+        } else if (!networkAddress.equals(other.networkAddress))
+            return false;
+        return true;
     }
 
     @Override
     public String toString() {
-        return "Host[" + ReflectionToStringBuilder.toString(this) + "]";
+        return "Host [dataLayerAddress=" + dataLayerAddress
+                + ", networkAddress=" + networkAddress + "]";
     }
 }
index 3958635..61e3872 100644 (file)
@@ -11,9 +11,6 @@ package org.opendaylight.controller.sal.core;
 
 import javax.xml.bind.annotation.XmlRootElement;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-
 /**
  * @file   Latency.java
  *
@@ -71,12 +68,24 @@ public class Latency extends Property {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + (int) (latency ^ (latency >>> 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;
+        Latency other = (Latency) obj;
+        if (latency != other.latency)
+            return false;
+        return true;
     }
 
     @Override