From: Ed Warnicke Date: Fri, 17 May 2013 15:10:12 +0000 (-0700) Subject: Five more Equals/HashCode/StringBuilder replacements X-Git-Tag: releasepom-0.1.0~429 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=ccfb9ee6445eba9a4539af7bf7650b144b791286 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. Ninth set. Change-Id: Icf3ea474ed0313ab92e93717658f20f6bc7c228c Signed-off-by: Ed Warnicke --- diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/Match.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/Match.java index 71e0087090..2ead8cdbc4 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/Match.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/Match.java @@ -26,8 +26,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.opendaylight.controller.sal.utils.EtherTypes; import org.opendaylight.controller.sal.utils.IPProtocols; import org.opendaylight.controller.sal.utils.NetUtils; @@ -337,12 +335,30 @@ public class Match implements Cloneable, Serializable { @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); + final int prime = 31; + int result = 1; + result = prime * result + ((fields == null) ? 0 : fields.hashCode()); + result = prime * result + matches; + 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; + Match other = (Match) obj; + if (fields == null) { + if (other.fields != null) + return false; + } else if (!fields.equals(other.fields)) + return false; + if (matches != other.matches) + return false; + return true; } @Override diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/address/DataLinkAddress.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/address/DataLinkAddress.java index 433f64c215..0c14517b19 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/address/DataLinkAddress.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/address/DataLinkAddress.java @@ -14,8 +14,6 @@ import java.io.Serializable; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlSeeAlso; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; /** @@ -71,12 +69,27 @@ abstract public class DataLinkAddress implements Serializable { @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.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; + DataLinkAddress other = (DataLinkAddress) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; } @Override diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/address/EthernetAddress.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/address/EthernetAddress.java index 63daf20763..2afaea8f42 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/address/EthernetAddress.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/address/EthernetAddress.java @@ -9,6 +9,8 @@ package org.opendaylight.controller.sal.packet.address; +import java.util.Arrays; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; @@ -16,8 +18,6 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; import org.opendaylight.controller.sal.core.ConstructionException; import org.opendaylight.controller.sal.utils.HexEncode; @@ -95,12 +95,24 @@ public class EthernetAddress extends DataLinkAddress { @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); + final int prime = 31; + int result = super.hashCode(); + result = prime * result + Arrays.hashCode(macAddress); + 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; + EthernetAddress other = (EthernetAddress) obj; + if (!Arrays.equals(macAddress, other.macAddress)) + return false; + return true; } @Override diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/topology/TopoEdgeUpdate.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/topology/TopoEdgeUpdate.java index d8da9c301b..fff46eafaf 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/topology/TopoEdgeUpdate.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/topology/TopoEdgeUpdate.java @@ -10,8 +10,6 @@ package org.opendaylight.controller.sal.topology; import java.util.Set; -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.Edge; import org.opendaylight.controller.sal.core.Property; @@ -46,7 +44,12 @@ public class TopoEdgeUpdate { @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); + final int prime = 31; + int result = 1; + result = prime * result + ((edge == null) ? 0 : edge.hashCode()); + result = prime * result + ((props == null) ? 0 : props.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + return result; } @Override @@ -57,6 +60,25 @@ public class TopoEdgeUpdate { @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; + TopoEdgeUpdate other = (TopoEdgeUpdate) obj; + if (edge == null) { + if (other.edge != null) + return false; + } else if (!edge.equals(other.edge)) + return false; + if (props == null) { + if (other.props != null) + return false; + } else if (!props.equals(other.props)) + return false; + if (type != other.type) + return false; + return true; } } diff --git a/opendaylight/usermanager/src/main/java/org/opendaylight/controller/usermanager/internal/ServerConfig.java b/opendaylight/usermanager/src/main/java/org/opendaylight/controller/usermanager/internal/ServerConfig.java index 649fee8f7f..2ad98aba68 100644 --- a/opendaylight/usermanager/src/main/java/org/opendaylight/controller/usermanager/internal/ServerConfig.java +++ b/opendaylight/usermanager/src/main/java/org/opendaylight/controller/usermanager/internal/ServerConfig.java @@ -11,9 +11,6 @@ package org.opendaylight.controller.usermanager.internal; import java.io.Serializable; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; - /** * Configuration Java Object which represents a Remote AAA server configuration * information for User Manager. @@ -49,12 +46,40 @@ public class ServerConfig implements Serializable { @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); + final int prime = 31; + int result = 1; + result = prime * result + ((ip == null) ? 0 : ip.hashCode()); + result = prime * result + + ((protocol == null) ? 0 : protocol.hashCode()); + result = prime * result + ((secret == null) ? 0 : secret.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; + ServerConfig other = (ServerConfig) obj; + if (ip == null) { + if (other.ip != null) + return false; + } else if (!ip.equals(other.ip)) + return false; + if (protocol == null) { + if (other.protocol != null) + return false; + } else if (!protocol.equals(other.protocol)) + return false; + if (secret == null) { + if (other.secret != null) + return false; + } else if (!secret.equals(other.secret)) + return false; + return true; } public boolean isValid() {