From 18ac0fd6a3af12073dd8088e6583a5c5f0c7d4e0 Mon Sep 17 00:00:00 2001 From: Ed Warnicke Date: Fri, 17 May 2013 08:26:09 -0700 Subject: [PATCH] Two more Equals/HashCode/StringBuilder replacements 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 --- .../controller/sal/core/Tier.java | 19 +++++++++--- .../internal/HostNodePair.java | 31 ++++++++++++++----- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Tier.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Tier.java index f45599f6c8..ed4d02b245 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Tier.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Tier.java @@ -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 diff --git a/opendaylight/samples/simpleforwarding/src/main/java/org/opendaylight/controller/samples/simpleforwarding/internal/HostNodePair.java b/opendaylight/samples/simpleforwarding/src/main/java/org/opendaylight/controller/samples/simpleforwarding/internal/HostNodePair.java index 2437b98d4d..afbbec998d 100644 --- a/opendaylight/samples/simpleforwarding/src/main/java/org/opendaylight/controller/samples/simpleforwarding/internal/HostNodePair.java +++ b/opendaylight/samples/simpleforwarding/src/main/java/org/opendaylight/controller/samples/simpleforwarding/internal/HostNodePair.java @@ -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 + "]"; } } -- 2.36.6