Two more Equals/HashCode/StringBuilder replacements 73/373/3
authorEd Warnicke <eaw@cisco.com>
Fri, 17 May 2013 15:26:09 +0000 (08:26 -0700)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 23 May 2013 10:24:24 +0000 (10:24 +0000)
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.

Eleventh set.

Change-Id: I45b20ae7c5d285598a1e1a0bfa9fbbfa7c1b617a
Signed-off-by: Ed Warnicke <eaw@cisco.com>
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Tier.java
opendaylight/samples/simpleforwarding/src/main/java/org/opendaylight/controller/samples/simpleforwarding/internal/HostNodePair.java

index f45599f6c80bd5b980aa0c488f1472a564f978f4..ed4d02b2457da40b210ce05d77cebd76e55d6fac 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;
-
 /**
  * The class represents the Tier property of a node
  *
@@ -50,12 +47,24 @@ public class Tier extends Property {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + tierValue;
+        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;
+        Tier other = (Tier) obj;
+        if (tierValue != other.tierValue)
+            return false;
+        return true;
     }
 
     @Override
index 2437b98d4dfa24f5e63fe6aa0a7f1e2c36e69f51..afbbec998d3f2066df89f94caabb242a866cc904 100644 (file)
@@ -11,10 +11,6 @@ package org.opendaylight.controller.samples.simpleforwarding.internal;
 
 import java.io.Serializable;
 
-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.hosttracker.hostAware.HostNodeConnector;
 import org.opendaylight.controller.sal.core.Node;
 
@@ -53,16 +49,37 @@ public class HostNodePair implements Serializable {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((host == null) ? 0 : host.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;
+        HostNodePair other = (HostNodePair) obj;
+        if (host == null) {
+            if (other.host != null)
+                return false;
+        } else if (!host.equals(other.host))
+            return false;
+        if (node == null) {
+            if (other.node != null)
+                return false;
+        } else if (!node.equals(other.node))
+            return false;
+        return true;
     }
 
     @Override
     public String toString() {
-        return "HostNodePair[" + ReflectionToStringBuilder.toString(this) + "]";
+        return "HostNodePair [host=" + host + ", node=" + node + "]";
     }
 }