From b9fa6d0bbeb3797b0752f059441a6f3966043762 Mon Sep 17 00:00:00 2001 From: Ed Warnicke Date: Wed, 15 May 2013 11:36:18 -0500 Subject: [PATCH] Five 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. Sixth set. Change-Id: Iddab53b9e960a416c1416415daa6c00ebb1bfc96 Signed-off-by: Ed Warnicke --- .../controller/sal/core/ContainerFlow.java | 21 ++++++++--- .../controller/sal/core/Description.java | 23 +++++++++--- .../controller/sal/core/Edge.java | 35 ++++++++++++++++--- .../controller/sal/core/Host.java | 34 ++++++++++++++---- .../controller/sal/core/Latency.java | 19 +++++++--- 5 files changed, 107 insertions(+), 25 deletions(-) diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/ContainerFlow.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/ContainerFlow.java index acb3e19f69..2a80bd6088 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/ContainerFlow.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/ContainerFlow.java @@ -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 diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Description.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Description.java index 4233dcbb68..4138aa6c34 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Description.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Description.java @@ -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 diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Edge.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Edge.java index 162a4d4232..c119eb79f5 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Edge.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Edge.java @@ -19,13 +19,11 @@ 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 diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Host.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Host.java index f5490860d6..50036372af 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Host.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Host.java @@ -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 + "]"; } } diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Latency.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Latency.java index 3958635914..61e3872669 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Latency.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Latency.java @@ -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 -- 2.36.6