Merge "Five more Equals/HashCode/StringBuilder replacements"
authorGiovanni Meo <gmeo@cisco.com>
Thu, 16 May 2013 13:01:00 +0000 (13:01 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 16 May 2013 13:01:00 +0000 (13:01 +0000)
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 acb3e19f69da6a88a2b8f1a0cda1d2f258b7c70a..2a80bd608823e2bf0a0ee329379a9578127af000 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 4233dcbb683b0db55ab9170aefa6561152e7820b..4138aa6c34068038c72ae97e9f8f5658a6b1211b 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 162a4d4232eef7e06b4b9162faab1cc1140b54aa..c119eb79f554fc47f34f05fba02bdd17591fede5 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 f5490860d652cec6e171bc32d99f7228f2569bcc..50036372afc041f106009834e676e7ab5f7037d5 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 395863591437d2bec527cd3144724abf5593f646..61e3872669b67f6a01f955bf2d15780635e0c84a 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