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

Change-Id: I8fb7e4ce544a15fd0b819dcffe978e2af990fe52
Signed-off-by: Ed Warnicke <eaw@cisco.com>
opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowEntry.java
opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowEntryInstall.java
opendaylight/hosttracker/api/src/main/java/org/opendaylight/controller/hosttracker/hostAware/HostNodeConnector.java
opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6Error.java
opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6StatsReply.java

index 2e174d2..6aa5b07 100644 (file)
@@ -11,8 +11,6 @@ package org.opendaylight.controller.forwardingrulesmanager;
 import java.io.Serializable;
 import java.util.Date;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
 import org.opendaylight.controller.sal.core.ContainerFlow;
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.flowprogrammer.Flow;
@@ -90,12 +88,47 @@ public class FlowEntry implements Cloneable, Serializable {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((flow == null) ? 0 : flow.hashCode());
+        result = prime * result
+                + ((flowName == null) ? 0 : flowName.hashCode());
+        result = prime * result
+                + ((groupName == null) ? 0 : groupName.hashCode());
+        result = prime * result + ((node == null) ? 0 : node.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;
+        FlowEntry other = (FlowEntry) obj;
+        if (flow == null) {
+            if (other.flow != null)
+                return false;
+        } else if (!flow.equals(other.flow))
+            return false;
+        if (flowName == null) {
+            if (other.flowName != null)
+                return false;
+        } else if (!flowName.equals(other.flowName))
+            return false;
+        if (groupName == null) {
+            if (other.groupName != null)
+                return false;
+        } else if (!groupName.equals(other.groupName))
+            return false;
+        if (node == null) {
+            if (other.node != null)
+                return false;
+        } else if (!node.equals(other.node))
+            return false;
+        return true;
     }
 
     @Override
index 96b6819..18255bc 100644 (file)
@@ -8,8 +8,6 @@
 
 package org.opendaylight.controller.forwardingrulesmanager;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
 import org.opendaylight.controller.sal.core.ContainerFlow;
 import org.opendaylight.controller.sal.core.Node;
 
@@ -42,12 +40,40 @@ public class FlowEntryInstall {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((cFlow == null) ? 0 : cFlow.hashCode());
+        result = prime * result + ((install == null) ? 0 : install.hashCode());
+        result = prime * result
+                + ((original == null) ? 0 : original.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;
+        FlowEntryInstall other = (FlowEntryInstall) obj;
+        if (cFlow == null) {
+            if (other.cFlow != null)
+                return false;
+        } else if (!cFlow.equals(other.cFlow))
+            return false;
+        if (install == null) {
+            if (other.install != null)
+                return false;
+        } else if (!install.equals(other.install))
+            return false;
+        if (original == null) {
+            if (other.original != null)
+                return false;
+        } else if (!original.equals(other.original))
+            return false;
+        return true;
     }
 
     public String getFlowName() {
index c83dc3d..e7b5745 100644 (file)
@@ -19,8 +19,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.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
 import org.opendaylight.controller.sal.core.ConstructionException;
 import org.opendaylight.controller.sal.core.Host;
@@ -140,20 +138,36 @@ public class HostNodeConnector extends Host {
         return this;
     }
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#hashCode()
-     */
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result
+                + ((nodeConnector == null) ? 0 : nodeConnector.hashCode());
+        result = prime * result + (staticHost ? 1231 : 1237);
+        result = prime * result + vlan;
+        return result;
     }
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#equals(java.lang.Object)
-     */
     @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;
+        HostNodeConnector other = (HostNodeConnector) obj;
+        if (nodeConnector == null) {
+            if (other.nodeConnector != null)
+                return false;
+        } else if (!nodeConnector.equals(other.nodeConnector))
+            return false;
+        if (staticHost != other.staticHost)
+            return false;
+        if (vlan != other.vlan)
+            return false;
+        return true;
     }
 
     public boolean equalsByIP(InetAddress networkAddress) {
index 4f0dbd5..c52c3f5 100644 (file)
@@ -1,10 +1,8 @@
 package org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension;
 
 import java.nio.ByteBuffer;
+import java.util.Arrays;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
 import org.openflow.protocol.OFError;
 
 public class V6Error extends OFError {
@@ -65,16 +63,44 @@ public class V6Error extends OFError {
     
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + Arrays.hashCode(V6ErrorData);
+        result = prime * result + V6VendorErrorCode;
+        result = prime * result + V6VendorErrorType;
+        result = prime * result + V6VendorId;
+        return result;
     }
 
     @Override
     public String toString() {
-        return "V6Error[" + ReflectionToStringBuilder.toString(this) + "]";
+        return "V6Error [V6VendorId=" + V6VendorId + ", V6VendorErrorType="
+                + V6VendorErrorType + ", V6VendorErrorCode="
+                + V6VendorErrorCode + ", V6ErrorData="
+                + Arrays.toString(V6ErrorData) + ", errorType=" + errorType
+                + ", errorCode=" + errorCode + ", factory=" + factory
+                + ", error=" + Arrays.toString(error) + ", errorIsAscii="
+                + errorIsAscii + ", version=" + version + ", type=" + type
+                + ", length=" + length + ", xid=" + xid + "]";
     }
 
     @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;
+        V6Error other = (V6Error) obj;
+        if (!Arrays.equals(V6ErrorData, other.V6ErrorData))
+            return false;
+        if (V6VendorErrorCode != other.V6VendorErrorCode)
+            return false;
+        if (V6VendorErrorType != other.V6VendorErrorType)
+            return false;
+        if (V6VendorId != other.V6VendorId)
+            return false;
+        return true;
     }
 }
index 8b5662c..f88efa3 100644 (file)
@@ -314,17 +314,84 @@ public class V6StatsReply extends OFVendorStatistics {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + ((actions == null) ? 0 : actions.hashCode());
+        result = prime * result + (int) (byteCount ^ (byteCount >>> 32));
+        result = prime * result + (int) (cookie ^ (cookie >>> 32));
+        result = prime * result + durationNanoseconds;
+        result = prime * result + durationSeconds;
+        result = prime * result + hardAge;
+        result = prime * result + hardTimeout;
+        result = prime * result + idleAge;
+        result = prime * result + idleTimeout;
+        result = prime * result + length;
+        result = prime * result + ((match == null) ? 0 : match.hashCode());
+        result = prime * result + match_len;
+        result = prime * result + (int) (packetCount ^ (packetCount >>> 32));
+        result = prime * result + priority;
+        result = prime * result + tableId;
+        return result;
     }
 
     @Override
     public String toString() {
-        return "V6StatsReply[" + ReflectionToStringBuilder.toString(this) + "]";
+        return "V6StatsReply [length=" + length + ", tableId=" + tableId
+                + ", durationSeconds=" + durationSeconds
+                + ", durationNanoseconds=" + durationNanoseconds
+                + ", priority=" + priority + ", idleTimeout=" + idleTimeout
+                + ", hardTimeout=" + hardTimeout + ", match_len=" + match_len
+                + ", idleAge=" + idleAge + ", hardAge=" + hardAge + ", cookie="
+                + cookie + ", packetCount=" + packetCount + ", byteCount="
+                + byteCount + ", match=" + match + ", actions=" + actions + "]";
     }
 
     @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;
+        V6StatsReply other = (V6StatsReply) obj;
+        if (actions == null) {
+            if (other.actions != null)
+                return false;
+        } else if (!actions.equals(other.actions))
+            return false;
+        if (byteCount != other.byteCount)
+            return false;
+        if (cookie != other.cookie)
+            return false;
+        if (durationNanoseconds != other.durationNanoseconds)
+            return false;
+        if (durationSeconds != other.durationSeconds)
+            return false;
+        if (hardAge != other.hardAge)
+            return false;
+        if (hardTimeout != other.hardTimeout)
+            return false;
+        if (idleAge != other.idleAge)
+            return false;
+        if (idleTimeout != other.idleTimeout)
+            return false;
+        if (length != other.length)
+            return false;
+        if (match == null) {
+            if (other.match != null)
+                return false;
+        } else if (!match.equals(other.match))
+            return false;
+        if (match_len != other.match_len)
+            return false;
+        if (packetCount != other.packetCount)
+            return false;
+        if (priority != other.priority)
+            return false;
+        if (tableId != other.tableId)
+            return false;
+        return true;
     }
 
 }